Automattic\WooCommerce\Blocks
BlockPatterns::register_ptk_patterns
Register patterns from the Patterns Toolkit.
Метод класса: BlockPatterns{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$BlockPatterns = new BlockPatterns(); $BlockPatterns->register_ptk_patterns();
Код BlockPatterns::register_ptk_patterns() BlockPatterns::register ptk patterns WC 10.5.0
public function register_ptk_patterns() {
// Only if the user has allowed tracking, we register the patterns from the PTK.
$allow_tracking = 'yes' === get_option( 'woocommerce_allow_tracking' );
if ( ! $allow_tracking ) {
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();
if ( empty( $patterns ) || ! is_array( $patterns ) ) {
// Only log once per day by using a transient.
$transient_key = 'wc_ptk_pattern_store_warning';
// By only logging when patterns are empty and no fetch is scheduled,
// we ensure that warnings are only generated in genuinely problematic situations,
// such as when the pattern fetching mechanism has failed entirely.
if ( ! get_transient( $transient_key ) && ! call_user_func( $has_scheduled_action, 'fetch_patterns' ) ) {
wc_get_logger()->warning(
__( 'Empty patterns received from the PTK Pattern Store', 'woocommerce' ),
);
// Set the transient to true to indicate that the warning has been logged in the current day.
set_transient( $transient_key, true, DAY_IN_SECONDS );
}
return;
}
$patterns = $this->parse_categories( $patterns );
foreach ( $patterns as $pattern ) {
$pattern['slug'] = $pattern['name'];
$pattern['content'] = $pattern['html'];
$this->pattern_registry->register_block_pattern( $pattern['ID'], $pattern );
}
}