Skip to content

Commit a2f083e

Browse files
committed
remove filters
1 parent 8265524 commit a2f083e

File tree

1 file changed

+15
-153
lines changed

1 file changed

+15
-153
lines changed

src/design-library/init.php

Lines changed: 15 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ class Stackable_Design_Library {
2929
public function __construct() {
3030
add_action( 'rest_api_init', array( $this, 'register_route' ) );
3131

32-
add_filter( 'stackable_design_library_get_premium_designs', array( $this, 'get_designs_with_disabled_blocks' ) );
33-
add_filter( 'stackable_design_library_get_premium_designs', array( $this, 'get_premium_designs' ) );
3432
add_action( 'stackable_delete_design_library_cache', array( $this, 'delete_cache_v3' ) );
3533
}
3634

@@ -109,7 +107,6 @@ public function delete_cache_v3() {
109107

110108
public function delete_cache() {
111109
// Delete design library.
112-
delete_transient( 'stackable_get_design_library_v4' );
113110
delete_transient( 'stackable_get_design_library_json_v4' );
114111

115112
do_action( 'stackable_delete_design_library_cache' );
@@ -225,10 +222,6 @@ public function get_design_library_image( $request ) {
225222
), 200 );
226223
}
227224

228-
public function filter_patterns( $pattern ) {
229-
return strpos( $pattern[ 'name' ], 'stackable_' ) !== false;
230-
}
231-
232225
public function get_design_library_from_cloud() {
233226
$designs = get_transient( 'stackable_get_design_library_json_v4' );
234227

@@ -247,8 +240,20 @@ public function get_design_library_from_cloud() {
247240
);
248241
} else {
249242
$content_body = wp_remote_retrieve_body( $response );
250-
$content = apply_filters( 'stackable_design_library_retreive_body', $content_body );
251-
$content = json_decode( $content, true );
243+
$designs = apply_filters( 'stackable_design_library_retreive_body', $content_body );
244+
$designs = json_decode( $designs, true );
245+
246+
$content = array();
247+
foreach ( $designs as $design_id => $design ) {
248+
$content[ $design_id ] = array(
249+
'title' => $design[ 'label' ],
250+
'content' => $design[ 'template' ],
251+
'category' => $design[ 'category' ],
252+
'description' => $design[ 'description' ],
253+
'plan' => $design[ 'plan' ],
254+
'designId' => $design_id
255+
);
256+
}
252257

253258
// Add our error message so we can see it in the network tab.
254259
if ( empty( $content ) ) {
@@ -272,38 +277,6 @@ public function get_design_library_from_cloud() {
272277
return apply_filters( 'stackable_design_library', $designs );
273278
}
274279

275-
public function _get_design_library( $outside_init = false ) {
276-
$designs = get_transient( 'stackable_get_design_library_v4' );
277-
// Fetch designs.
278-
if ( empty( $designs ) ) {
279-
$designs = array();
280-
$content = array();
281-
282-
$block_patterns = WP_Block_Patterns_Registry::get_instance()->get_all_registered( $outside_init );
283-
foreach ( $block_patterns as $pattern ) {
284-
if ( strpos( $pattern[ 'name' ], 'stackable_' ) !== false ) {
285-
$pattern[ 'title' ] = str_replace( sprintf( __( 'Stackable ', STACKABLE_I18N ) ), '', $pattern[ 'title' ] );
286-
$content[ $pattern[ 'designId' ] ] = $pattern;
287-
}
288-
}
289-
290-
// Get premium designs for v4
291-
$content = apply_filters( 'stackable_design_library_get_premium_designs', $content );
292-
293-
// We add the latest designs in the `v4` area.
294-
$designs[ self::API_VERSION ] = $content;
295-
296-
// Allow deprecated code to fetch other designs
297-
$designs = apply_filters( 'stackable_fetch_design_library', $designs );
298-
299-
// Cache results.
300-
set_transient( 'stackable_get_design_library_v4', $designs, DAY_IN_SECONDS );
301-
302-
}
303-
304-
return apply_filters( 'stackable_design_library', $designs );
305-
}
306-
307280
/**
308281
* Gets and caches library designs.
309282
*/
@@ -313,120 +286,9 @@ public function get_design_library( $request ) {
313286
$this->delete_cache();
314287
}
315288

316-
return rest_ensure_response( $this->_get_design_library( $reset ) );
289+
return rest_ensure_response( $this->get_design_library_from_cloud() );
317290
}
318291

319-
public function get_disabled_blocks() {
320-
$disabled_blocks = get_option( 'stackable_block_states' );
321-
322-
if ( $disabled_blocks == false ) {
323-
return false;
324-
}
325-
326-
$disabled_blocks = array_filter( $disabled_blocks, function ( $block_state ) { return $block_state == 3; } );
327-
if ( count( $disabled_blocks ) ) {
328-
$disabled_blocks = array_keys( $disabled_blocks );
329-
$disabled_blocks = array_map( function ( $block ) { return preg_quote( $block, '/' ); }, $disabled_blocks );
330-
$disabled_blocks = '/' . implode( '|', $disabled_blocks ) . '/i';
331-
return $disabled_blocks;
332-
}
333-
334-
return false;
335-
}
336-
337-
public function check_for_disabled_block( $design, $disabled_blocks ) {
338-
if ( preg_match( $disabled_blocks, $design ) ) {
339-
return true;
340-
}
341-
342-
return false;
343-
}
344-
345-
public function get_premium_designs( $content ) {
346-
$designs = $this->get_design_library_from_cloud();
347-
348-
$library = $designs[ self::API_VERSION ];
349-
350-
$premium_designs = array();
351-
foreach ( $library as $design_id => $design ) {
352-
if ( $design[ 'plan' ] === 'premium' && STACKABLE_BUILD === 'premium' && sugb_fs()->can_use_premium_code() ) {
353-
continue;
354-
}
355-
356-
$premium_designs[ $design_id ] = array(
357-
'title' => $design[ 'label' ],
358-
'content' => $design[ 'template' ],
359-
'category' => $design[ 'category' ],
360-
'description' => $design[ 'description' ],
361-
'plan' => $design[ 'plan' ],
362-
'designId' => $design_id
363-
);
364-
}
365-
366-
$merged = array_merge( $content, $premium_designs );
367-
368-
uasort($merged, function( $design_1, $design_2 ) {
369-
return strnatcmp( $design_1[ 'title' ], $design_2[ 'title' ] );
370-
});
371-
372-
return $merged;
373-
}
374-
375-
public function get_designs_with_disabled_blocks( $content ) {
376-
$designs = $this->get_design_library_from_cloud();
377-
378-
$library = $designs[ self::API_VERSION ];
379-
380-
$designs_with_disabled = array();
381-
foreach ( $library as $design_id => $design ) {
382-
if ( isset( $content[ $design_id ] ) ) {
383-
continue;
384-
}
385-
386-
$designs_with_disabled[ $design_id ] = array(
387-
'title' => $design[ 'label' ],
388-
'content' => $design[ 'template' ],
389-
'category' => $design[ 'category' ],
390-
'description' => $design[ 'description' ],
391-
'plan' => $design[ 'plan' ],
392-
'designId' => $design_id,
393-
);
394-
}
395-
396-
$merged = array_merge( $content, $designs_with_disabled );
397-
398-
uasort($merged, function( $design_1, $design_2 ) {
399-
return strnatcmp( $design_1[ 'title' ], $design_2[ 'title' ] );
400-
});
401-
402-
return $merged;
403-
}
404-
405-
public function get_category_kebab_case( $category ) {
406-
$category = trim( strtolower( $category ) );
407-
return preg_replace( '/[^a-z0-9-]+/', '-', $category );
408-
}
409-
410-
public function get_template_with_placeholders( $template, $category ) {
411-
if ( ! class_exists( 'Stackable_Design_Library_Placeholders' ) ) {
412-
return $template;
413-
}
414-
415-
$default_placeholders = Stackable_Design_Library_Placeholders::get_default();
416-
417-
if ( ! isset( $default_placeholders[ $category ] ) ) {
418-
return $template;
419-
}
420-
421-
foreach( $default_placeholders[ $category ] as $placeholder => $value ) {
422-
if ( ! is_string( $value ) ) {
423-
continue;
424-
}
425-
$template = str_replace( $placeholder, $value, $template );
426-
}
427-
428-
return $template;
429-
}
430292

431293
/**
432294
* Gets the URL of the CDN where to load our design library data. When

0 commit comments

Comments
 (0)