PTK: Check to confirm `as_has_scheduled_action` exists before using to conditionally fire logger (#52725)
* Check to confirm as_has_scheduled_action exists Add a check to confirm that `as_has_scheduled_action` exists in the condition that uses it to conditionally run the warning log. * improve fallback logic * Update plugins/woocommerce/src/Blocks/BlockPatterns.php Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com> --------- Co-authored-by: Luigi Teschio <gigitux@gmail.com> Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
This commit is contained in:
parent
b0284be31e
commit
9495d7ce98
|
@ -150,12 +150,16 @@ class BlockPatterns {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The most efficient way to check for an existing action is to use `as_has_scheduled_action`, but in unusual
|
||||||
|
// cases where another plugin has loaded a very old version of Action Scheduler, it may not be available to us.
|
||||||
|
$has_scheduled_action = function_exists( 'as_has_scheduled_action' ) ? 'as_has_scheduled_action' : 'as_next_scheduled_action';
|
||||||
|
|
||||||
$patterns = $this->ptk_patterns_store->get_patterns();
|
$patterns = $this->ptk_patterns_store->get_patterns();
|
||||||
if ( empty( $patterns ) ) {
|
if ( empty( $patterns ) ) {
|
||||||
// By only logging when patterns are empty and no fetch is scheduled,
|
// By only logging when patterns are empty and no fetch is scheduled,
|
||||||
// we ensure that warnings are only generated in genuinely problematic situations,
|
// we ensure that warnings are only generated in genuinely problematic situations,
|
||||||
// such as when the pattern fetching mechanism has failed entirely.
|
// such as when the pattern fetching mechanism has failed entirely.
|
||||||
if ( ! as_has_scheduled_action( 'fetch_patterns' ) ) {
|
if ( ! call_user_func( $has_scheduled_action, 'fetch_patterns' ) ) {
|
||||||
wc_get_logger()->warning(
|
wc_get_logger()->warning(
|
||||||
__( 'Empty patterns received from the PTK Pattern Store', 'woocommerce' ),
|
__( 'Empty patterns received from the PTK Pattern Store', 'woocommerce' ),
|
||||||
);
|
);
|
||||||
|
|
|
@ -94,7 +94,11 @@ class PTKPatternsStore {
|
||||||
*/
|
*/
|
||||||
private function schedule_action_if_not_pending( $action ) {
|
private function schedule_action_if_not_pending( $action ) {
|
||||||
$last_request = get_transient( 'last_fetch_patterns_request' );
|
$last_request = get_transient( 'last_fetch_patterns_request' );
|
||||||
if ( as_has_scheduled_action( $action ) || false !== $last_request ) {
|
// The most efficient way to check for an existing action is to use `as_has_scheduled_action`, but in unusual
|
||||||
|
// cases where another plugin has loaded a very old version of Action Scheduler, it may not be available to us.
|
||||||
|
|
||||||
|
$has_scheduled_action = function_exists( 'as_has_scheduled_action' ) ? 'as_has_scheduled_action' : 'as_next_scheduled_action';
|
||||||
|
if ( call_user_func( $has_scheduled_action, $action ) || false !== $last_request ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue