8889841cwp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Utils/BlockTemplateMigrationUtils.php000064400000010046150444473270035350 0ustar00home/clixcotz/gj.clix.co.tzwp_id ) { return self::set_has_migrated_page( $template_slug, 'custom-template-exists' ); } $template_content = self::get_default_template( $template_slug ); if ( self::create_custom_template( $block_template, $template_content ) ) { return self::set_has_migrated_page( $template_slug ); } } /** * Prepare default page template. * * @param string $template_slug Template slug. * @return string */ protected static function get_default_template( $template_slug ) { $default_template_content = '
'; return self::get_block_template_part( 'header' ) . $default_template_content . self::get_block_template_part( 'footer' ); } /** * Create a custom template with given content. * * @param \WP_Block_Template|null $template Template object. * @param string $content Template content. * @return boolean Success. */ protected static function create_custom_template( $template, $content ) { $term = get_term_by( 'slug', $template->theme, 'wp_theme', ARRAY_A ); if ( ! $term ) { $term = wp_insert_term( $template->theme, 'wp_theme' ); } $template_id = wp_insert_post( [ 'post_name' => $template->slug, 'post_type' => 'wp_template', 'post_status' => 'publish', 'tax_input' => array( 'wp_theme' => $template->theme, ), 'meta_input' => array( 'origin' => $template->source, ), 'post_content' => $content, ], true ); wp_set_post_terms( $template_id, array( $term['term_id'] ), 'wp_theme' ); return $template_id && ! is_wp_error( $template_id ); } /** * Returns the requested template part. * * @param string $part The part to return. * @return string */ protected static function get_block_template_part( $part ) { $template_part = BlockTemplateUtils::get_block_template( get_stylesheet() . '//' . $part, 'wp_template_part' ); if ( ! $template_part || empty( $template_part->content ) ) { return ''; } return $template_part->content; } }