Skip to content

Instantly share code, notes, and snippets.

@pawelkmpt
Last active September 28, 2022 13:50
Show Gist options
  • Save pawelkmpt/05bc9f0fca5783553fe4a7b0d7e2f240 to your computer and use it in GitHub Desktop.
Save pawelkmpt/05bc9f0fca5783553fe4a7b0d7e2f240 to your computer and use it in GitHub Desktop.
<?php
/**
* Selectively avoid triggering some `_doing_it_wrong()` errors.
*
* @see https://developer.wordpress.org/reference/functions/_doing_it_wrong/
*/
/**
* AutomateWoo workflows sometimes need internal meta keys.
*
* @since 2022.09.06
*/
add_filter( 'doing_it_wrong_trigger_error', static function( bool $trigger, string $function, string $message ): bool {
if ( $trigger
&& 'is_internal_meta_key' === $function
&& cxl_strposa( $message, [ '_customer_ip_address', '_transaction_id' ] )
) {
$trigger = false;
}
return $trigger;
}, 10, 3 );
if ( ! function_exists( 'cxl_strposa' ) ) {
/**
* Performs `strpos()` check for array or strings.
*
* Simple version just to fulfill needs in this plugin.
*
* @since 2022.09.28
* @see https://stackoverflow.com/questions/6284553/using-an-array-as-needles-in-strpos
*/
function cxl_strposa( string $haystack, array $needles ): bool {
foreach ( $needles as $needle ) {
if ( strpos( $haystack, $needle ) !== false ) {
return true; // stop on first true result
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment