Skip to content

Commit

Permalink
Block Patterns: Load patterns from wordpress.org API
Browse files Browse the repository at this point in the history
  • Loading branch information
ryelle committed Apr 21, 2021
1 parent d504910 commit c41f48d
Show file tree
Hide file tree
Showing 16 changed files with 10 additions and 529 deletions.
35 changes: 10 additions & 25 deletions lib/block-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@
add_action(
'init',
function() {

$core_block_patterns = array(
'text-two-columns',
'two-buttons',
Expand All @@ -202,24 +201,6 @@ function() {
'quote',
);

$new_core_block_patterns = array(
'media-text-nature',
'two-images-gallery',
'three-columns-media-text',
'quote',
'large-header-left',
'large-header-text-button',
'media-text-art',
'text-two-columns-title',
'three-columns-text',
'text-two-columns-title-offset',
'heading',
'three-images-gallery',
'text-two-columns',
'media-text-arquitecture',
'two-buttons',
);

if ( ! function_exists( 'unregister_block_pattern' ) ) {
return;
}
Expand All @@ -228,12 +209,16 @@ function() {
unregister_block_pattern( 'core/' . $core_block_pattern );
}

foreach ( $new_core_block_patterns as $core_block_pattern ) {
register_block_pattern(
'core/' . $core_block_pattern,
require __DIR__ . '/block-patterns/' . $core_block_pattern . '.php'
);
$request = new WP_REST_Request( 'GET', '/__experimental/pattern-directory/patterns' );
$request->set_param( 'keyword', 11 ); // 11 is the ID for "core".
$response = rest_do_request( $request );
if ( $response->is_error() ) {
return;
}
$patterns = $response->get_data();
foreach ( $patterns as $settings ) {
$pattern_name = 'core/' . sanitize_title( $settings['title'] );
register_block_pattern( $pattern_name, (array) $settings );
}

}
);
16 changes: 0 additions & 16 deletions lib/block-patterns/heading.php

This file was deleted.

33 changes: 0 additions & 33 deletions lib/block-patterns/large-header-left.php

This file was deleted.

35 changes: 0 additions & 35 deletions lib/block-patterns/large-header-text-button.php

This file was deleted.

21 changes: 0 additions & 21 deletions lib/block-patterns/media-text-arquitecture.php

This file was deleted.

21 changes: 0 additions & 21 deletions lib/block-patterns/media-text-art.php

This file was deleted.

28 changes: 0 additions & 28 deletions lib/block-patterns/media-text-nature.php

This file was deleted.

30 changes: 0 additions & 30 deletions lib/block-patterns/quote.php

This file was deleted.

53 changes: 0 additions & 53 deletions lib/block-patterns/text-two-columns-title-offset.php

This file was deleted.

31 changes: 0 additions & 31 deletions lib/block-patterns/text-two-columns-title.php

This file was deleted.

Loading

0 comments on commit c41f48d

Please sign in to comment.