From 8265524f71561c4211d92956aaa3b5f12111a356 Mon Sep 17 00:00:00 2001 From: "bfintal@gmail.com" <> Date: Sat, 2 Aug 2025 17:09:47 +0800 Subject: [PATCH 1/4] remove pattern registration --- src/design-library/init.php | 65 ------------------------------------- 1 file changed, 65 deletions(-) diff --git a/src/design-library/init.php b/src/design-library/init.php index bd1ef3c2dc..94eafd11be 100644 --- a/src/design-library/init.php +++ b/src/design-library/init.php @@ -31,7 +31,6 @@ public function __construct() { add_filter( 'stackable_design_library_get_premium_designs', array( $this, 'get_designs_with_disabled_blocks' ) ); add_filter( 'stackable_design_library_get_premium_designs', array( $this, 'get_premium_designs' ) ); - add_action( 'init', array( $this, 'register_design_pattern' ) ); add_action( 'stackable_delete_design_library_cache', array( $this, 'delete_cache_v3' ) ); } @@ -109,24 +108,10 @@ public function delete_cache_v3() { } public function delete_cache() { - $designs = $this->get_design_library_from_cloud(); - - $library = $designs[ self::API_VERSION ]; - foreach ( $library as $design_id => $design ) { - if ( WP_Block_Patterns_Registry::get_instance()->is_registered( 'stackable_' . $design_id ) ) { - $res = unregister_block_pattern( 'stackable_' . $design_id ); - } - - if ( WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( 'stackable_' . $design[ 'category' ] ) ) { - $res = unregister_block_pattern_category( 'stackable_' . $design[ 'category' ] ); - } - } // Delete design library. delete_transient( 'stackable_get_design_library_v4' ); delete_transient( 'stackable_get_design_library_json_v4' ); - $this->register_design_pattern(); - do_action( 'stackable_delete_design_library_cache' ); } @@ -443,56 +428,6 @@ public function get_template_with_placeholders( $template, $category ) { return $template; } - public function register_design_pattern() { - $designs = $this->get_design_library_from_cloud(); - - $library = $designs[ self::API_VERSION ]; - - if ( ! $library ) { - return; - } - - - $disabled_blocks = $this->get_disabled_blocks(); - - - if ( ! WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( 'stackable' ) ) { - register_block_pattern_category( 'stackable', [ - 'label' => __( 'Stackable', STACKABLE_I18N ), - 'description' => __( 'Patterns for Stackable Design Library', STACKABLE_I18N ), - ] ); - } - - foreach ( $library as $design_id => $design ) { - if ( $design[ 'plan' ] === 'premium' && ( STACKABLE_BUILD === 'free' || ! sugb_fs()->can_use_premium_code() ) ) { - continue; - } - - if ( $disabled_blocks ) { - $has_disabled = $this->check_for_disabled_block( $design[ 'template' ], $disabled_blocks ); - if ( $has_disabled ) continue; - } - - register_block_pattern_category( 'stackable_' . $this->get_category_kebab_case( $design[ 'category' ] ), [ - 'label' => sprintf( __( 'Stackable %s', STACKABLE_I18N ), $design[ 'category' ] ), - 'description' => sprintf( __( '%s patterns for Stackable Design Library', STACKABLE_I18N ), $design[ 'category' ] ), - ] ); - - register_block_pattern( - 'stackable_' . $design_id, - array( - 'title' => sprintf( __( 'Stackable %s', STACKABLE_I18N ), $design[ 'label' ] ), - 'content' => $this->get_template_with_placeholders( $design[ 'template' ], $design[ 'category' ] ), - 'categories' => array( 'stackable_' . $this->get_category_kebab_case( $design[ 'category' ] ), 'stackable' ), // used in Patterns - 'category' => $design[ 'category' ], // used in Design Library - 'description' => $design[ 'description' ], - 'plan' => $design[ 'plan' ], - 'designId' => $design_id - ) - ); - } - } - /** * Gets the URL of the CDN where to load our design library data. When * developer mode for the design library is turned on, the URL of the From a2f083e218f8cdf99526bc199df93336ce948bf1 Mon Sep 17 00:00:00 2001 From: Mikhaela Tapia Date: Sat, 2 Aug 2025 17:28:38 +0800 Subject: [PATCH 2/4] remove filters --- src/design-library/init.php | 168 ++++-------------------------------- 1 file changed, 15 insertions(+), 153 deletions(-) diff --git a/src/design-library/init.php b/src/design-library/init.php index 94eafd11be..4c195e3834 100644 --- a/src/design-library/init.php +++ b/src/design-library/init.php @@ -29,8 +29,6 @@ class Stackable_Design_Library { public function __construct() { add_action( 'rest_api_init', array( $this, 'register_route' ) ); - add_filter( 'stackable_design_library_get_premium_designs', array( $this, 'get_designs_with_disabled_blocks' ) ); - add_filter( 'stackable_design_library_get_premium_designs', array( $this, 'get_premium_designs' ) ); add_action( 'stackable_delete_design_library_cache', array( $this, 'delete_cache_v3' ) ); } @@ -109,7 +107,6 @@ public function delete_cache_v3() { public function delete_cache() { // Delete design library. - delete_transient( 'stackable_get_design_library_v4' ); delete_transient( 'stackable_get_design_library_json_v4' ); do_action( 'stackable_delete_design_library_cache' ); @@ -225,10 +222,6 @@ public function get_design_library_image( $request ) { ), 200 ); } - public function filter_patterns( $pattern ) { - return strpos( $pattern[ 'name' ], 'stackable_' ) !== false; - } - public function get_design_library_from_cloud() { $designs = get_transient( 'stackable_get_design_library_json_v4' ); @@ -247,8 +240,20 @@ public function get_design_library_from_cloud() { ); } else { $content_body = wp_remote_retrieve_body( $response ); - $content = apply_filters( 'stackable_design_library_retreive_body', $content_body ); - $content = json_decode( $content, true ); + $designs = apply_filters( 'stackable_design_library_retreive_body', $content_body ); + $designs = json_decode( $designs, true ); + + $content = array(); + foreach ( $designs as $design_id => $design ) { + $content[ $design_id ] = array( + 'title' => $design[ 'label' ], + 'content' => $design[ 'template' ], + 'category' => $design[ 'category' ], + 'description' => $design[ 'description' ], + 'plan' => $design[ 'plan' ], + 'designId' => $design_id + ); + } // Add our error message so we can see it in the network tab. if ( empty( $content ) ) { @@ -272,38 +277,6 @@ public function get_design_library_from_cloud() { return apply_filters( 'stackable_design_library', $designs ); } - public function _get_design_library( $outside_init = false ) { - $designs = get_transient( 'stackable_get_design_library_v4' ); - // Fetch designs. - if ( empty( $designs ) ) { - $designs = array(); - $content = array(); - - $block_patterns = WP_Block_Patterns_Registry::get_instance()->get_all_registered( $outside_init ); - foreach ( $block_patterns as $pattern ) { - if ( strpos( $pattern[ 'name' ], 'stackable_' ) !== false ) { - $pattern[ 'title' ] = str_replace( sprintf( __( 'Stackable ', STACKABLE_I18N ) ), '', $pattern[ 'title' ] ); - $content[ $pattern[ 'designId' ] ] = $pattern; - } - } - - // Get premium designs for v4 - $content = apply_filters( 'stackable_design_library_get_premium_designs', $content ); - - // We add the latest designs in the `v4` area. - $designs[ self::API_VERSION ] = $content; - - // Allow deprecated code to fetch other designs - $designs = apply_filters( 'stackable_fetch_design_library', $designs ); - - // Cache results. - set_transient( 'stackable_get_design_library_v4', $designs, DAY_IN_SECONDS ); - - } - - return apply_filters( 'stackable_design_library', $designs ); - } - /** * Gets and caches library designs. */ @@ -313,120 +286,9 @@ public function get_design_library( $request ) { $this->delete_cache(); } - return rest_ensure_response( $this->_get_design_library( $reset ) ); + return rest_ensure_response( $this->get_design_library_from_cloud() ); } - public function get_disabled_blocks() { - $disabled_blocks = get_option( 'stackable_block_states' ); - - if ( $disabled_blocks == false ) { - return false; - } - - $disabled_blocks = array_filter( $disabled_blocks, function ( $block_state ) { return $block_state == 3; } ); - if ( count( $disabled_blocks ) ) { - $disabled_blocks = array_keys( $disabled_blocks ); - $disabled_blocks = array_map( function ( $block ) { return preg_quote( $block, '/' ); }, $disabled_blocks ); - $disabled_blocks = '/' . implode( '|', $disabled_blocks ) . '/i'; - return $disabled_blocks; - } - - return false; - } - - public function check_for_disabled_block( $design, $disabled_blocks ) { - if ( preg_match( $disabled_blocks, $design ) ) { - return true; - } - - return false; - } - - public function get_premium_designs( $content ) { - $designs = $this->get_design_library_from_cloud(); - - $library = $designs[ self::API_VERSION ]; - - $premium_designs = array(); - foreach ( $library as $design_id => $design ) { - if ( $design[ 'plan' ] === 'premium' && STACKABLE_BUILD === 'premium' && sugb_fs()->can_use_premium_code() ) { - continue; - } - - $premium_designs[ $design_id ] = array( - 'title' => $design[ 'label' ], - 'content' => $design[ 'template' ], - 'category' => $design[ 'category' ], - 'description' => $design[ 'description' ], - 'plan' => $design[ 'plan' ], - 'designId' => $design_id - ); - } - - $merged = array_merge( $content, $premium_designs ); - - uasort($merged, function( $design_1, $design_2 ) { - return strnatcmp( $design_1[ 'title' ], $design_2[ 'title' ] ); - }); - - return $merged; - } - - public function get_designs_with_disabled_blocks( $content ) { - $designs = $this->get_design_library_from_cloud(); - - $library = $designs[ self::API_VERSION ]; - - $designs_with_disabled = array(); - foreach ( $library as $design_id => $design ) { - if ( isset( $content[ $design_id ] ) ) { - continue; - } - - $designs_with_disabled[ $design_id ] = array( - 'title' => $design[ 'label' ], - 'content' => $design[ 'template' ], - 'category' => $design[ 'category' ], - 'description' => $design[ 'description' ], - 'plan' => $design[ 'plan' ], - 'designId' => $design_id, - ); - } - - $merged = array_merge( $content, $designs_with_disabled ); - - uasort($merged, function( $design_1, $design_2 ) { - return strnatcmp( $design_1[ 'title' ], $design_2[ 'title' ] ); - }); - - return $merged; - } - - public function get_category_kebab_case( $category ) { - $category = trim( strtolower( $category ) ); - return preg_replace( '/[^a-z0-9-]+/', '-', $category ); - } - - public function get_template_with_placeholders( $template, $category ) { - if ( ! class_exists( 'Stackable_Design_Library_Placeholders' ) ) { - return $template; - } - - $default_placeholders = Stackable_Design_Library_Placeholders::get_default(); - - if ( ! isset( $default_placeholders[ $category ] ) ) { - return $template; - } - - foreach( $default_placeholders[ $category ] as $placeholder => $value ) { - if ( ! is_string( $value ) ) { - continue; - } - $template = str_replace( $placeholder, $value, $template ); - } - - return $template; - } /** * Gets the URL of the CDN where to load our design library data. When From 8185e3fd23259cda2d8eb1b68fc47e03da02a5a0 Mon Sep 17 00:00:00 2001 From: Mikhaela Tapia Date: Sat, 2 Aug 2025 17:38:16 +0800 Subject: [PATCH 3/4] change transient name --- src/design-library/init.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/design-library/init.php b/src/design-library/init.php index 4c195e3834..3317ca74d4 100644 --- a/src/design-library/init.php +++ b/src/design-library/init.php @@ -108,6 +108,7 @@ public function delete_cache_v3() { public function delete_cache() { // Delete design library. delete_transient( 'stackable_get_design_library_json_v4' ); + delete_transient( 'stackable_get_design_library_v4' ); do_action( 'stackable_delete_design_library_cache' ); } @@ -223,7 +224,7 @@ public function get_design_library_image( $request ) { } public function get_design_library_from_cloud() { - $designs = get_transient( 'stackable_get_design_library_json_v4' ); + $designs = get_transient( 'stackable_get_design_library_v4' ); // Fetch designs. if ( empty( $designs ) ) { @@ -271,7 +272,7 @@ public function get_design_library_from_cloud() { $designs = apply_filters( 'stackable_fetch_design_library', $designs ); // Cache results. - set_transient( 'stackable_get_design_library_json_v4', $designs, DAY_IN_SECONDS ); + set_transient( 'stackable_get_design_library_v4', $designs, DAY_IN_SECONDS ); } return apply_filters( 'stackable_design_library', $designs ); From ae012c31125e266afec5d3df893eedc5acfb50f3 Mon Sep 17 00:00:00 2001 From: "bfintal@gmail.com" <> Date: Sat, 2 Aug 2025 17:44:14 +0800 Subject: [PATCH 4/4] use the property cdnUrl --- src/components/design-library-list/util.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/design-library-list/util.js b/src/components/design-library-list/util.js index 85bed0335d..82f339e760 100644 --- a/src/components/design-library-list/util.js +++ b/src/components/design-library-list/util.js @@ -1,6 +1,8 @@ /* eslint-disable no-console */ import DEFAULT from './default.json' -import { settings, isPro } from 'stackable' +import { + settings, isPro, cdnUrl, +} from 'stackable' import { parse, serialize } from '@wordpress/blocks' const DEFAULT_CONTENT = { ...DEFAULT } @@ -199,7 +201,7 @@ export const parseDisabledBlocks = parsedBlock => { return { block, blocksForSubstitution } } -const IMAGE_STORAGE = 'https://stackable-files.pages.dev/library-v4/images/' +const IMAGE_STORAGE = cdnUrl.replace( /\/$/, '' ) + '/library-v4/images/' export const addPlaceholderForPostsBlock = ( content, postsPlaceholder, defaultValues ) => { const remainingPosts = [ ...postsPlaceholder ]