From 9709a126c9c3e123cb44f48869d3ec4234ef05d7 Mon Sep 17 00:00:00 2001 From: Henrik Wirth Date: Tue, 30 Nov 2021 23:52:02 +0200 Subject: [PATCH 1/4] Adds monitoring for acf option pages and introduces Utils class for helpers. --- src/ActionMonitor/Monitors/AcfMonitor.php | 26 ++++++++++++++++++++-- src/Utils/Utils.php | 27 +++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/Utils/Utils.php diff --git a/src/ActionMonitor/Monitors/AcfMonitor.php b/src/ActionMonitor/Monitors/AcfMonitor.php index c379854..ada2c88 100644 --- a/src/ActionMonitor/Monitors/AcfMonitor.php +++ b/src/ActionMonitor/Monitors/AcfMonitor.php @@ -2,6 +2,8 @@ namespace WPGatsby\ActionMonitor\Monitors; +use WPGatsby\Utils\Utils; + class AcfMonitor extends Monitor { public function init() { @@ -28,8 +30,28 @@ function() { } ); - // @todo: Add support for tracking ACF Options Fields. - + add_action('acf/save_post', [$this, 'after_acf_save_post'], 20); } + /** + * Handles content updates of ACF option pages. + */ + public function after_acf_save_post() { + $option_pages_slugs = array_keys(acf_get_options_pages()); + + /** + * Filters the $option_pages_slugs array. + * + * @since 2.1.2 + * + * @param array $option_pages_slugs Array with slugs of all registered ACF option pages. + */ + $option_pages_slugs = apply_filters('gatsby_action_monitor_tracked_acf_options_pages', $option_pages_slugs); + + $screen = get_current_screen(); + + if(!empty($option_pages_slugs) && is_array($option_pages_slugs) && Utils::str_in_substr_array($screen->id, $option_pages_slugs)) { + $this->trigger_non_node_root_field_update(); + } + } } diff --git a/src/Utils/Utils.php b/src/Utils/Utils.php new file mode 100644 index 0000000..23ce852 --- /dev/null +++ b/src/Utils/Utils.php @@ -0,0 +1,27 @@ + Date: Tue, 30 Nov 2021 14:10:30 -0800 Subject: [PATCH 2/4] formatting --- src/ActionMonitor/Monitors/AcfMonitor.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ActionMonitor/Monitors/AcfMonitor.php b/src/ActionMonitor/Monitors/AcfMonitor.php index ada2c88..a0dd2cf 100644 --- a/src/ActionMonitor/Monitors/AcfMonitor.php +++ b/src/ActionMonitor/Monitors/AcfMonitor.php @@ -37,7 +37,7 @@ function() { * Handles content updates of ACF option pages. */ public function after_acf_save_post() { - $option_pages_slugs = array_keys(acf_get_options_pages()); + $option_pages_slugs = array_keys( acf_get_options_pages() ); /** * Filters the $option_pages_slugs array. @@ -46,11 +46,14 @@ public function after_acf_save_post() { * * @param array $option_pages_slugs Array with slugs of all registered ACF option pages. */ - $option_pages_slugs = apply_filters('gatsby_action_monitor_tracked_acf_options_pages', $option_pages_slugs); + $option_pages_slugs = apply_filters( + 'gatsby_action_monitor_tracked_acf_options_pages', + $option_pages_slugs + ); $screen = get_current_screen(); - if(!empty($option_pages_slugs) && is_array($option_pages_slugs) && Utils::str_in_substr_array($screen->id, $option_pages_slugs)) { + if( ! empty( $option_pages_slugs ) && is_array( $option_pages_slugs ) && Utils::str_in_substr_array( $screen->id, $option_pages_slugs ) ) { $this->trigger_non_node_root_field_update(); } } From 44a06d2cbc428a791a646076d5f0cf507f7c1dd4 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Tue, 30 Nov 2021 14:11:44 -0800 Subject: [PATCH 3/4] more formatting --- src/ActionMonitor/Monitors/AcfMonitor.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ActionMonitor/Monitors/AcfMonitor.php b/src/ActionMonitor/Monitors/AcfMonitor.php index a0dd2cf..fd2a5c3 100644 --- a/src/ActionMonitor/Monitors/AcfMonitor.php +++ b/src/ActionMonitor/Monitors/AcfMonitor.php @@ -53,7 +53,11 @@ public function after_acf_save_post() { $screen = get_current_screen(); - if( ! empty( $option_pages_slugs ) && is_array( $option_pages_slugs ) && Utils::str_in_substr_array( $screen->id, $option_pages_slugs ) ) { + if( + ! empty( $option_pages_slugs ) + && is_array( $option_pages_slugs ) + && Utils::str_in_substr_array( $screen->id, $option_pages_slugs ) + ) { $this->trigger_non_node_root_field_update(); } } From e53bf0257e3c47f11b7fd4e6917d0a30f72752fe Mon Sep 17 00:00:00 2001 From: Henrik Wirth Date: Wed, 1 Dec 2021 00:27:48 +0200 Subject: [PATCH 4/4] check if acf_get_options_pages is returning an array --- src/ActionMonitor/Monitors/AcfMonitor.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ActionMonitor/Monitors/AcfMonitor.php b/src/ActionMonitor/Monitors/AcfMonitor.php index fd2a5c3..e318588 100644 --- a/src/ActionMonitor/Monitors/AcfMonitor.php +++ b/src/ActionMonitor/Monitors/AcfMonitor.php @@ -37,7 +37,13 @@ function() { * Handles content updates of ACF option pages. */ public function after_acf_save_post() { - $option_pages_slugs = array_keys( acf_get_options_pages() ); + $option_pages = acf_get_options_pages(); + + if ( ! is_array( $option_pages ) ) { + return; + } + + $option_pages_slugs = array_keys( $option_pages ); /** * Filters the $option_pages_slugs array.