Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACF Options Page Monitoring #206

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions src/ActionMonitor/Monitors/AcfMonitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace WPGatsby\ActionMonitor\Monitors;

use WPGatsby\Utils\Utils;

class AcfMonitor extends Monitor {

public function init() {
Expand All @@ -28,8 +30,41 @@ 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 = acf_get_options_pages();

if ( ! is_array( $option_pages ) ) {
return;
}

$option_pages_slugs = array_keys( $option_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();
}
}
}
27 changes: 27 additions & 0 deletions src/Utils/Utils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace WPGatsby\Utils;

class Utils {

/**
* Checks if any of the strings in $substr_array is a substring in the $haystack.
*
* @since 2.1.2
*
* @param string $haystack
* @param array $substr_array
* @param int $offset
*
* @return bool
*/
public static function str_in_substr_array(string $haystack, array $substr_array, int $offset = 0): bool {
foreach ( $substr_array as $substr ) {
if ($substr && strpos($haystack, $substr, $offset) !== false ) {
return true;
}
}

return false;
}
}