diff --git a/includes/assets.php b/includes/assets.php index 5b166adb..e6b19e71 100644 --- a/includes/assets.php +++ b/includes/assets.php @@ -265,6 +265,37 @@ public function register_scripts() { ) ); + wp_add_inline_script( + 'wp-blocks', + 'const originalBlocks = window.wp.blocks; + +window.wp.blocks = new Proxy(originalBlocks, { + get(target, prop, receiver) { + if (prop === "getBlockBindingsSources") { + return function(...args) { + const result = target.getBlockBindingsSources(...args); + if (result?.["acf/field"]) { + result["acf/field"]["getFieldsList"] = function() { + return acf.getFields().reduce( (acc, { data, $el }) => { + acc[data.name] = { + label: $el.find("label").text(), + value: $el.find("input").val() || "", + type: data.type === "text" ? "string" : data.type, + }; + return acc; + }, {} ); + }; + } + return result; + }; + } + + return Reflect.get(target, prop, receiver); + } +});', + 'after' + ); + // Register styles. foreach ( $styles as $style ) { wp_register_style( @@ -753,4 +784,4 @@ function acf_enqueue_scripts( $args = array() ) { */ function acf_enqueue_uploader() { return acf_get_instance( 'ACF_Assets' )->enqueue_uploader(); -} \ No newline at end of file +}