ermalink_structure_changed'} action once the init call has * processed passing the old and new values * * @since 1.5.0 * * @param string $permalink_structure Permalink structure. */ public function set_permalink_structure( $permalink_structure ) { if ( $this->permalink_structure !== $permalink_structure ) { $old_permalink_structure = $this->permalink_structure; update_option( 'permalink_structure', $permalink_structure ); $this->init(); /** * Fires after the permalink structure is updated. * * @since 2.8.0 * * @param string $old_permalink_structure The previous permalink structure. * @param string $permalink_structure The new permalink structure. */ do_action( 'permalink_structure_changed', $old_permalink_structure, $permalink_structure ); } } /** * Sets the category base for the category permalink. * * Will update the 'category_base' option, if there is a difference between * the current category base and the parameter value. Calls WP_Rewrite::init() * after the option is updated. * * @since 1.5.0 * * @param string $category_base Category permalink structure base. */ public function set_category_base( $category_base ) { if ( get_option( 'category_base' ) !== $category_base ) { update_option( 'category_base', $category_base ); $this->init(); } } /** * Sets the tag base for the tag permalink. * * Will update the 'tag_base' option, if there is a difference between the * current tag base and the parameter value. Calls WP_Rewrite::init() after * the option is updated. * * @since 2.3.0 * * @param string $tag_base Tag permalink structure base. */ public function set_tag_base( $tag_base ) { if ( get_option( 'tag_base' ) !== $tag_base ) { update_option( 'tag_base', $tag_base ); $this->init(); } } /** * Constructor - Calls init(), which runs setup. * * @since 1.5.0 */ public function __construct() { $this->init(); } } rns[] = $data; } $this->set_pattern_cache( $patterns ); return $patterns; } /** * Gets block pattern cache. * * @return array|false Returns an array of patterns if cache is found, otherwise false. */ private function get_pattern_cache() { $pattern_data = get_site_transient( 'woocommerce_blocks_patterns' ); if ( is_array( $pattern_data ) && WOOCOMMERCE_VERSION === $pattern_data['version'] ) { return $pattern_data['patterns']; } return false; } /** * Sets block pattern cache. * * @param array $patterns Block patterns data to set in cache. */ private function set_pattern_cache( array $patterns ) { $pattern_data = array( 'version' => WOOCOMMERCE_VERSION, 'patterns' => $patterns, ); set_site_transient( 'woocommerce_blocks_patterns', $pattern_data, MONTH_IN_SECONDS ); } /** * Register patterns from the Patterns Toolkit. * * @return void */ 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 ) ) { // 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 ( ! call_user_func( $has_scheduled_action, 'fetch_patterns' ) ) { wc_get_logger()->warning( __( 'Empty patterns received from the PTK Pattern Store', 'woocommerce' ), ); } 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, $this->get_patterns_dictionary() ); } } /** * Parse prefixed categories from the PTK patterns into the actual WooCommerce categories. * * @param array $patterns The patterns to parse. * @return array The parsed patterns. */ private function parse_categories( array $patterns ) { return array_map( function ( $pattern ) { $pattern['categories'] = array_map( function ( $category ) { foreach ( self::CATEGORIES_PREFIXES as $prefix ) { if ( strpos( $category['title'], $prefix ) !== false ) { $parsed_category = str_replace( $prefix, '', $category['title'] ); $parsed_category = str_replace( '_', ' ', $parsed_category ); $category['title'] = ucfirst( $parsed_category ); } } return $category; }, $pattern['categories'] ); return $pattern; }, $patterns ); } }