Skip to content

Commit 3454a89

Browse files
authored
Revert "Block Patterns: Load patterns from wordpress.org API (#28800)"
This reverts commit 57f7791.
1 parent 57f7791 commit 3454a89

18 files changed

+543
-45
lines changed

lib/block-patterns.php

+30-38
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,10 @@ function register_gutenberg_patterns() {
185185
}
186186

187187
/**
188-
* Deactivate the legacy patterns bundled with WordPress.
188+
* Deactivate the legacy patterns bundled with WordPress, and add new block patterns for testing.
189+
* More details in the trac issue (https://core.trac.wordpress.org/ticket/52846).
189190
*/
190-
function remove_core_patterns() {
191+
function update_core_patterns() {
191192
$core_block_patterns = array(
192193
'text-two-columns',
193194
'two-buttons',
@@ -201,31 +202,36 @@ function remove_core_patterns() {
201202
'quote',
202203
);
203204

204-
foreach ( $core_block_patterns as $core_block_pattern ) {
205-
unregister_block_pattern( 'core/' . $core_block_pattern );
206-
}
207-
}
205+
$new_core_block_patterns = array(
206+
'media-text-nature',
207+
'two-images-gallery',
208+
'three-columns-media-text',
209+
'quote',
210+
'large-header-left',
211+
'large-header-text-button',
212+
'media-text-art',
213+
'text-two-columns-title',
214+
'three-columns-text',
215+
'text-two-columns-title-offset',
216+
'heading',
217+
'three-images-gallery',
218+
'text-two-columns',
219+
'media-text-arquitecture',
220+
'two-buttons',
221+
);
208222

209-
/**
210-
* Import patterns from wordpress.org/patterns.
211-
*/
212-
function load_remote_patterns() {
213-
$patterns = get_transient( 'gutenberg_remote_block_patterns' );
214-
if ( ! $patterns ) {
215-
$request = new WP_REST_Request( 'GET', '/__experimental/pattern-directory/patterns' );
216-
$core_keyword_id = 11; // 11 is the ID for "core".
217-
$request->set_param( 'keyword', $core_keyword_id );
218-
$response = rest_do_request( $request );
219-
if ( $response->is_error() ) {
220-
return;
223+
foreach ( $core_block_patterns as $core_block_pattern ) {
224+
$name = 'core/' . $core_block_pattern;
225+
if ( WP_Block_Patterns_Registry::get_instance()->is_registered( $name ) ) {
226+
unregister_block_pattern( $name );
221227
}
222-
$patterns = $response->get_data();
223-
set_transient( 'gutenberg_remote_block_patterns', $patterns, HOUR_IN_SECONDS );
224228
}
225229

226-
foreach ( $patterns as $settings ) {
227-
$pattern_name = 'core/' . sanitize_title( $settings['title'] );
228-
register_block_pattern( $pattern_name, (array) $settings );
230+
foreach ( $new_core_block_patterns as $core_block_pattern ) {
231+
register_block_pattern(
232+
'core/' . $core_block_pattern,
233+
require __DIR__ . '/block-patterns/' . $core_block_pattern . '.php'
234+
);
229235
}
230236
}
231237

@@ -236,21 +242,7 @@ function() {
236242
if ( ! get_theme_support( 'core-block-patterns' ) || ! function_exists( 'unregister_block_pattern' ) ) {
237243
return;
238244
}
239-
remove_core_patterns();
240245
register_gutenberg_patterns();
241-
}
242-
);
243-
244-
add_action(
245-
'current_screen',
246-
function( $current_screen ) {
247-
if ( ! get_theme_support( 'core-block-patterns' ) ) {
248-
return;
249-
}
250-
251-
$is_site_editor = ( function_exists( 'gutenberg_is_edit_site_page' ) && gutenberg_is_edit_site_page( $current_screen->id ) );
252-
if ( $current_screen->is_block_editor || $is_site_editor ) {
253-
load_remote_patterns();
254-
}
246+
update_core_patterns();
255247
}
256248
);

lib/block-patterns/heading.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Heading.
4+
*
5+
* @package WordPress
6+
*/
7+
8+
return array(
9+
'title' => _x( 'Heading', 'Block pattern title', 'default' ),
10+
'categories' => array( 'text' ),
11+
'blockTypes' => array( 'core/heading' ),
12+
'content' => '<!-- wp:heading {"align":"wide","style":{"typography":{"fontSize":"48px","lineHeight":"1.1"}}} -->
13+
<h2 class="alignwide" style="font-size:48px;line-height:1.1">' . esc_html__( "We're a studio in Berlin with an international practice in architecture, urban planning and interior design. We believe in sharing knowledge and promoting dialogue to increase the creative potential of collaboration.", 'default' ) . '</h2>
14+
<!-- /wp:heading -->',
15+
'description' => _x( 'Heading text', 'Block pattern description', 'default' ),
16+
);
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Large header with left-aligned text.
4+
*
5+
* @package WordPress
6+
*/
7+
8+
return array(
9+
'title' => _x( 'Large header with left-aligned text', 'Block pattern title', 'default' ),
10+
'categories' => array( 'header' ),
11+
'content' => '<!-- wp:cover {"url":"https://s.w.org/images/core/5.8/forest.jpg","id":null,"dimRatio":60,"minHeight":800,"align":"full"} -->
12+
<div class="wp-block-cover alignfull has-background-dim-60 has-background-dim" style="min-height:800px"><img class="wp-block-cover__image-background " alt="" src="https://s.w.org/images/core/5.8/forest.jpg" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:heading {"align":"wide","style":{"color":{"text":"#ffe074"},"typography":{"fontSize":"64px"}}} -->
13+
<h2 class="alignwide has-text-color" style="color:#ffe074;font-size:64px">' . esc_html__( 'Forest.', 'default' ) . '</h2>
14+
<!-- /wp:heading -->
15+
16+
<!-- wp:columns {"align":"wide"} -->
17+
<div class="wp-block-columns alignwide"><!-- wp:column {"width":"55%"} -->
18+
<div class="wp-block-column" style="flex-basis:55%"><!-- wp:spacer {"height":330} -->
19+
<div style="height:330px" aria-hidden="true" class="wp-block-spacer"></div>
20+
<!-- /wp:spacer -->
21+
22+
<!-- wp:paragraph {"style":{"color":{"text":"#ffe074"},"typography":{"lineHeight":"1.3","fontSize":"12px"}}} -->
23+
<p class="has-text-color" style="color:#ffe074;font-size:12px;line-height:1.3"><em>' . esc_html__( 'Even a child knows how valuable the forest is. The fresh, breathtaking smell of trees. Echoing birds flying above that dense magnitude. A stable climate, a sustainable diverse life and a source of culture. Yet, forests and other ecosystems hang in the balance, threatened to become croplands, pasture, and plantations.', 'default' ) . '</em></p>
24+
<!-- /wp:paragraph --></div>
25+
<!-- /wp:column -->
26+
27+
<!-- wp:column -->
28+
<div class="wp-block-column"></div>
29+
<!-- /wp:column --></div>
30+
<!-- /wp:columns --></div></div>
31+
<!-- /wp:cover -->',
32+
'description' => _x( 'Cover image with quote on top', 'Block pattern description', 'default' ),
33+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Large header with text and a button.
4+
*
5+
* @package WordPress
6+
*/
7+
8+
return array(
9+
'title' => _x( 'Large header with text and a button.', 'Block pattern title', 'default' ),
10+
'categories' => array( 'header' ),
11+
'content' => '<!-- wp:cover {"url":"https://s.w.org/images/core/5.8/art-01.jpg","id":null,"hasParallax":true,"dimRatio":40,"customOverlayColor":"#000000","minHeight":100,"minHeightUnit":"vh","contentPosition":"center center","align":"full"} -->
12+
<div class="wp-block-cover alignfull has-background-dim-40 has-background-dim has-parallax" style="background-color:#000000;background-image:url(https://s.w.org/images/core/5.8/art-01.jpg);min-height:100vh"><div class="wp-block-cover__inner-container"><!-- wp:heading {"style":{"typography":{"fontSize":"48px","lineHeight":"1.2"}},"className":"alignwide has-white-color has-text-color"} -->
13+
<h2 class="alignwide has-white-color has-text-color" style="font-size:48px;line-height:1.2"><strong><em>' . esc_html__( 'Overseas:', 'default' ) . '</em></strong><br><strong><em>' . esc_html__( '1500 — 1960', 'default' ) . '</em></strong></h2>
14+
<!-- /wp:heading -->
15+
16+
<!-- wp:columns {"align":"wide"} -->
17+
<div class="wp-block-columns alignwide"><!-- wp:column {"width":"60%"} -->
18+
<div class="wp-block-column" style="flex-basis:60%"><!-- wp:paragraph {"style":{"color":{"text":"#ffffff"}}} -->
19+
<p class="has-text-color" style="color:#ffffff">' . wp_kses_post( __( 'An exhibition about the different representations of the ocean throughout time, between the sixteenth and the twentieth century. Taking place in our Open Room in <em>Floor 2</em>.', 'default' ) ) . '</p>
20+
<!-- /wp:paragraph -->
21+
22+
<!-- wp:buttons -->
23+
<div class="wp-block-buttons"><!-- wp:button {"borderRadius":0,"style":{"color":{"text":"#ffffff","background":"#000000"}},"className":"is-style-outline"} -->
24+
<div class="wp-block-button is-style-outline"><a class="wp-block-button__link has-text-color has-background no-border-radius" style="background-color:#000000;color:#ffffff">' . esc_html__( 'Visit', 'default' ) . '</a></div>
25+
<!-- /wp:button --></div>
26+
<!-- /wp:buttons --></div>
27+
<!-- /wp:column -->
28+
29+
<!-- wp:column -->
30+
<div class="wp-block-column"></div>
31+
<!-- /wp:column --></div>
32+
<!-- /wp:columns --></div></div>
33+
<!-- /wp:cover -->',
34+
'description' => _x( 'Large header with background image and text and button on top', 'Block pattern description', 'default' ),
35+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Media and text with image on the right.
4+
*
5+
* @package WordPress
6+
*/
7+
8+
return array(
9+
'title' => _x( 'Media and text with image on the right', 'Block pattern title', 'default' ),
10+
'categories' => array( 'header' ),
11+
'content' => '<!-- wp:media-text {"align":"full","mediaId":null,"mediaType":"image","verticalAlignment":"center"} -->
12+
<div class="wp-block-media-text alignfull is-stacked-on-mobile is-vertically-aligned-center"><figure class="wp-block-media-text__media"><img src="https://s.w.org/images/core/5.8/architecture-04.jpg" alt="' . esc_attr__( 'Close-up, abstract view of architecture.', 'default' ) . '"/></figure><div class="wp-block-media-text__content"><!-- wp:heading {"textAlign":"center","level":3,"style":{"color":{"text":"#000000"}}} -->
13+
<h3 class="has-text-align-center has-text-color" style="color:#000000"><strong>' . esc_html__( 'Open Spaces', 'default' ) . '</strong></h3>
14+
<!-- /wp:heading -->
15+
16+
<!-- wp:paragraph {"align":"center","fontSize":"extra-small"} -->
17+
<p class="has-text-align-center has-extra-small-font-size"><a href="#">' . esc_html__( 'See case study ↗', 'default' ) . '</a></p>
18+
<!-- /wp:paragraph --></div></div>
19+
<!-- /wp:media-text -->',
20+
'description' => _x( 'Media and text block with image to the left and text to the right', 'Block pattern description', 'default' ),
21+
);

lib/block-patterns/media-text-art.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Media & text with image on the right.
4+
*
5+
* @package WordPress
6+
*/
7+
8+
return array(
9+
'title' => _x( 'Media & text with image on the right', 'Block pattern title', 'default' ),
10+
'categories' => array( 'header' ),
11+
'content' => '<!-- wp:media-text {"align":"full","mediaPosition":"right","mediaId":null,"mediaLink":"#","mediaType":"image","mediaWidth":56,"verticalAlignment":"center","className":"is-style-default"} -->
12+
<div class="wp-block-media-text alignfull has-media-on-the-right is-stacked-on-mobile is-vertically-aligned-center is-style-default" style="grid-template-columns:auto 56%"><figure class="wp-block-media-text__media"><img src="https://s.w.org/images/core/5.8/art-02.jpg" alt="' . esc_attr__( 'A green and brown rural landscape leading into a bright blue ocean and slightly cloudy sky, done in oil paints.', 'default' ) . '"/></figure><div class="wp-block-media-text__content"><!-- wp:heading {"style":{"color":{"text":"#000000"}}} -->
13+
<h2 class="has-text-color" style="color:#000000"><strong>' . esc_html__( 'Shore with Blue Sea', 'default' ) . '</strong></h2>
14+
<!-- /wp:heading -->
15+
16+
<!-- wp:paragraph {"style":{"typography":{"lineHeight":"1.1","fontSize":"17px"},"color":{"text":"#636363"}}} -->
17+
<p class="has-text-color" style="color:#636363;font-size:17px;line-height:1.1">' . esc_html__( 'Eleanor Harris&nbsp;(American, 1901-1942)', 'default' ) . '</p>
18+
<!-- /wp:paragraph --></div></div>
19+
<!-- /wp:media-text -->',
20+
'description' => _x( 'Media and text block with image to the right and text to the left', 'Block pattern description', 'default' ),
21+
);
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Media & text in a full height container.
4+
*
5+
* @package WordPress
6+
*/
7+
8+
return array(
9+
'title' => _x( 'Media & text in a full height container', 'Block pattern title', 'default' ),
10+
'categories' => array( 'header' ),
11+
'content' => '<!-- wp:cover {"customOverlayColor":"#ffffff","minHeight":100,"minHeightUnit":"vh","contentPosition":"center center","align":"full"} -->
12+
<div class="wp-block-cover alignfull has-background-dim" style="background-color:#ffffff;min-height:100vh"><div class="wp-block-cover__inner-container"><!-- wp:media-text {"mediaId":null,"mediaLink":"https://s.w.org/images/core/5.8/soil.jpg","mediaType":"image","mediaWidth":56,"verticalAlignment":"center","imageFill":true} -->
13+
<div class="wp-block-media-text alignwide is-stacked-on-mobile is-vertically-aligned-center is-image-fill" style="grid-template-columns:56% auto"><figure class="wp-block-media-text__media" style="background-image:url(https://s.w.org/images/core/5.8/soil.jpg);background-position:50% 50%"><img src="https://s.w.org/images/core/5.8/soil.jpg" alt="' . esc_attr__( 'Close-up of dried, cracked earth.', 'default' ) . '"/></figure><div class="wp-block-media-text__content"><!-- wp:heading {"style":{"typography":{"fontSize":"32px"},"color":{"text":"#000000"}}} -->
14+
<h2 class="has-text-color" style="color:#000000;font-size:32px"><strong>' . esc_html__( "What's the problem?", 'default' ) . '</strong></h2>
15+
<!-- /wp:heading -->
16+
17+
<!-- wp:paragraph {"style":{"typography":{"fontSize":"17px"},"color":{"text":"#000000"}}} -->
18+
<p class="has-text-color" style="color:#000000;font-size:17px">' . esc_html__( 'Trees are more important today than ever before. More than 10,000 products are reportedly made from trees. Through chemistry, the humble woodpile is yielding chemicals, plastics and fabrics that were beyond comprehension when an axe first felled a Texas tree.', 'default' ) . '</p>
19+
<!-- /wp:paragraph -->
20+
<!-- wp:buttons -->
21+
<div class="wp-block-buttons"><!-- wp:button {"className":"is-style-fill"} -->
22+
<div class="wp-block-button is-style-fill"><a class="wp-block-button__link">' . esc_html__( 'Learn more', 'default' ) . '</a></div>
23+
<!-- /wp:button --></div>
24+
<!-- /wp:buttons --></div></div>
25+
<!-- /wp:media-text --></div></div>
26+
<!-- /wp:cover -->',
27+
'description' => _x( 'Media and text block with image to the left and text and button to the right', 'Block pattern description', 'default' ),
28+
);

lib/block-patterns/quote.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Quote.
4+
*
5+
* @package WordPress
6+
*/
7+
8+
return array(
9+
'title' => _x( 'Quote', 'Block pattern title', 'default' ),
10+
'categories' => array( 'text' ),
11+
'blockTypes' => array( 'core/quote' ),
12+
'content' => '<!-- wp:group -->
13+
<div class="wp-block-group"><div class="wp-block-group__inner-container"><!-- wp:separator {"className":"is-style-default"} -->
14+
<hr class="wp-block-separator is-style-default"/>
15+
<!-- /wp:separator -->
16+
17+
<!-- wp:image {"align":"center","id":null,"width":150,"height":150,"sizeSlug":"large","linkDestination":"none","className":"is-style-rounded"} -->
18+
<div class="wp-block-image is-style-rounded"><figure class="aligncenter size-large is-resized"><img src="https://s.w.org/images/core/5.8/portrait.jpg" alt="' . esc_attr__( 'A side profile of a woman in a russet-colored turtleneck and white bag. She looks up with her eyes closed.', 'default' ) . '" width="150" height="150"/></figure></div>
19+
<!-- /wp:image -->
20+
21+
<!-- wp:quote {"align":"center","className":"is-style-large"} -->
22+
<blockquote class="wp-block-quote has-text-align-center is-style-large"><p>' . esc_html__( "\"Contributing makes me feel like I'm being useful to the planet.\"", 'default' ) . '</p><cite>' . wp_kses_post( __( '— Anna Wong, <em>Volunteer</em>', 'default' ) ) . '</cite></blockquote>
23+
<!-- /wp:quote -->
24+
25+
<!-- wp:separator {"className":"is-style-default"} -->
26+
<hr class="wp-block-separator is-style-default"/>
27+
<!-- /wp:separator --></div></div>
28+
<!-- /wp:group -->',
29+
'description' => _x( 'Testimonial quote with portrait', 'Block pattern description', 'default' ),
30+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Two columns of text with offset heading.
4+
*
5+
* @package WordPress
6+
*/
7+
8+
return array(
9+
'title' => _x( 'Two columns of text with offset heading', 'Block pattern title', 'default' ),
10+
'categories' => array( 'columns', 'text' ),
11+
'content' => '<!-- wp:group {"align":"full","style":{"color":{"background":"#f2f0e9"}}} -->
12+
<div class="wp-block-group alignfull has-background" style="background-color:#f2f0e9"><!-- wp:spacer {"height":70} -->
13+
<div style="height:70px" aria-hidden="true" class="wp-block-spacer"></div>
14+
<!-- /wp:spacer -->
15+
16+
<!-- wp:columns {"verticalAlignment":"center","align":"wide"} -->
17+
<div class="wp-block-columns alignwide are-vertically-aligned-center"><!-- wp:column {"width":"50%"} -->
18+
<div class="wp-block-column" style="flex-basis:50%"><!-- wp:paragraph {"style":{"typography":{"lineHeight":"1.1","fontSize":"30px"},"color":{"text":"#000000"}}} -->
19+
<p class="has-text-color" style="color:#000000;font-size:30px;line-height:1.1"><strong>' . esc_html__( 'Oceanic Inspiration', 'default' ) . '</strong></p>
20+
<!-- /wp:paragraph --></div>
21+
<!-- /wp:column -->
22+
23+
<!-- wp:column {"width":"50%"} -->
24+
<div class="wp-block-column" style="flex-basis:50%"><!-- wp:separator {"customColor":"#000000","className":"is-style-wide"} -->
25+
<hr class="wp-block-separator has-text-color has-background is-style-wide" style="background-color:#000000;color:#000000"/>
26+
<!-- /wp:separator --></div>
27+
<!-- /wp:column --></div>
28+
<!-- /wp:columns -->
29+
30+
<!-- wp:columns {"align":"wide"} -->
31+
<div class="wp-block-columns alignwide"><!-- wp:column -->
32+
<div class="wp-block-column"></div>
33+
<!-- /wp:column -->
34+
35+
<!-- wp:column -->
36+
<div class="wp-block-column"><!-- wp:paragraph {"style":{"color":{"text":"#000000"}},"fontSize":"extra-small"} -->
37+
<p class="has-text-color has-extra-small-font-size" style="color:#000000">' . esc_html__( 'Winding veils round their heads, the women walked on deck. They were now moving steadily down the river, passing the dark shapes of ships at anchor, and London was a swarm of lights with a pale yellow canopy drooping above it. There were the lights of the great theatres, the lights of the long streets, lights that indicated huge squares of domestic comfort, lights that hung high in air.', 'default' ) . '</p>
38+
<!-- /wp:paragraph --></div>
39+
<!-- /wp:column -->
40+
41+
<!-- wp:column -->
42+
<div class="wp-block-column"><!-- wp:paragraph {"style":{"color":{"text":"#000000"}},"fontSize":"extra-small"} -->
43+
<p class="has-text-color has-extra-small-font-size" style="color:#000000">' . esc_html__( 'No darkness would ever settle upon those lamps, as no darkness had settled upon them for hundreds of years. It seemed dreadful that the town should blaze for ever in the same spot; dreadful at least to people going away to adventure upon the sea, and beholding it as a circumscribed mound, eternally burnt, eternally scarred. From the deck of the ship the great city appeared a crouched and cowardly figure, a sedentary miser.', 'default' ) . '</p>
44+
<!-- /wp:paragraph --></div>
45+
<!-- /wp:column --></div>
46+
<!-- /wp:columns -->
47+
48+
<!-- wp:spacer {"height":40} -->
49+
<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>
50+
<!-- /wp:spacer --></div>
51+
<!-- /wp:group -->',
52+
'description' => _x( 'Two columns of text with offset heading', 'Block pattern description', 'default' ),
53+
);

0 commit comments

Comments
 (0)