From d79ac8697d7de5e5002f2eb12a39952b96ea0365 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Fri, 23 May 2025 13:32:10 +0200 Subject: [PATCH 1/3] Bindings: Integrate `acf/field` source in the Attributes panel --- includes/assets.php | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/includes/assets.php b/includes/assets.php index 5b166adb..2766c8fc 100644 --- a/includes/assets.php +++ b/includes/assets.php @@ -265,6 +265,42 @@ 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); + console.log("Intercepted getBlockBindingsSources", result); + if (result?.["acf/field"]) { + result["acf/field"]["getFieldsList"] = function() { + return { + isbn: { + label: "ISBN (SCF)", + value: "978-3-16-148410-0", + type: "string", + }, + author: { + label: "Author (SCF)", + value: "John Doe", + type: "string", + }, + }; + }; + } + return result; + }; + } + + return Reflect.get(target, prop, receiver); + } +});', + 'after' + ); + // Register styles. foreach ( $styles as $style ) { wp_register_style( @@ -753,4 +789,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 +} From d44efc62b14cb51b2f3a11ea2f63f9ce621278e9 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Fri, 23 May 2025 14:42:41 +0200 Subject: [PATCH 2/3] Improve the UI using more precise information --- includes/assets.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/includes/assets.php b/includes/assets.php index 2766c8fc..29750bb7 100644 --- a/includes/assets.php +++ b/includes/assets.php @@ -277,18 +277,14 @@ public function register_scripts() { console.log("Intercepted getBlockBindingsSources", result); if (result?.["acf/field"]) { result["acf/field"]["getFieldsList"] = function() { - return { - isbn: { - label: "ISBN (SCF)", - value: "978-3-16-148410-0", - type: "string", - }, - author: { - label: "Author (SCF)", - value: "John Doe", - type: "string", - }, - }; + 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; From 365bd8af03b6c33c02779dfc6539f1502000e5ac Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Fri, 23 May 2025 14:48:14 +0200 Subject: [PATCH 3/3] Remove obsolete debug logs --- includes/assets.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/assets.php b/includes/assets.php index 29750bb7..e6b19e71 100644 --- a/includes/assets.php +++ b/includes/assets.php @@ -274,7 +274,6 @@ public function register_scripts() { if (prop === "getBlockBindingsSources") { return function(...args) { const result = target.getBlockBindingsSources(...args); - console.log("Intercepted getBlockBindingsSources", result); if (result?.["acf/field"]) { result["acf/field"]["getFieldsList"] = function() { return acf.getFields().reduce( (acc, { data, $el }) => {