Block Editor: Add support for the pattern directory.

Add an endpoint for fetching block patterns from WordPress.org, and load the block patterns from this new API. Remove the block patterns that have already been moved to WordPress.org/patterns.

Props ryelle, iandunn, youknowriad, timothyblynjacobs.
Fixes #53246.


Built from https://develop.svn.wordpress.org/trunk@51021


git-svn-id: http://core.svn.wordpress.org/trunk@50630 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryelle 2021-05-26 01:11:59 +00:00
parent 072e83aac4
commit 56ca42b5d9
21 changed files with 344 additions and 520 deletions

View File

@ -19,21 +19,6 @@ function _register_core_block_patterns_and_categories() {
if ( $should_register_core_patterns ) { if ( $should_register_core_patterns ) {
$core_block_patterns = array( $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',
'query-standard-posts', 'query-standard-posts',
'query-medium-posts', 'query-medium-posts',
'query-small-posts', 'query-small-posts',
@ -58,3 +43,43 @@ function _register_core_block_patterns_and_categories() {
register_block_pattern_category( 'text', array( 'label' => _x( 'Text', 'Block pattern category' ) ) ); register_block_pattern_category( 'text', array( 'label' => _x( 'Text', 'Block pattern category' ) ) );
register_block_pattern_category( 'query', array( 'label' => __( 'Query', 'Block pattern category' ) ) ); register_block_pattern_category( 'query', array( 'label' => __( 'Query', 'Block pattern category' ) ) );
} }
/**
* Import patterns from wordpress.org/patterns.
*/
function _load_remote_block_patterns( $current_screen ) {
if ( ! $current_screen->is_block_editor ) {
return;
}
$supports_core_patterns = get_theme_support( 'core-block-patterns' );
/**
* Filter to disable remote block patterns.
*
* @since 5.8.0
*
* @param bool $should_load_remote
*/
$should_load_remote = apply_filters( 'should_load_remote_block_patterns', true );
if ( $supports_core_patterns && $should_load_remote ) {
$patterns = get_transient( 'wp_remote_block_patterns' );
if ( ! $patterns ) {
$request = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns' );
$core_keyword_id = 11; // 11 is the ID for "core".
$request->set_param( 'keyword', $core_keyword_id );
$response = rest_do_request( $request );
if ( $response->is_error() ) {
return;
}
$patterns = $response->get_data();
set_transient( 'wp_remote_block_patterns', $patterns, HOUR_IN_SECONDS );
}
foreach ( $patterns as $settings ) {
$pattern_name = 'core/' . sanitize_title( $settings['title'] );
register_block_pattern( $pattern_name, (array) $settings );
}
}
}

View File

@ -1,16 +0,0 @@
<?php
/**
* Heading.
*
* @package WordPress
*/
return array(
'title' => _x( 'Heading', 'Block pattern title' ),
'categories' => array( 'text' ),
'blockTypes' => array( 'core/heading' ),
'content' => '<!-- wp:heading {"align":"wide","style":{"typography":{"fontSize":"48px","lineHeight":"1.1"}}} -->
<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." ) . '</h2>
<!-- /wp:heading -->',
'description' => _x( 'Heading text', 'Block pattern description' ),
);

View File

@ -1,33 +0,0 @@
<?php
/**
* Large header with left-aligned text.
*
* @package WordPress
*/
return array(
'title' => _x( 'Large header with left-aligned text', 'Block pattern title' ),
'categories' => array( 'header' ),
'content' => '<!-- wp:cover {"url":"https://s.w.org/images/core/5.8/forest.jpg","id":null,"dimRatio":60,"minHeight":800,"align":"full"} -->
<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"}}} -->
<h2 class="alignwide has-text-color" style="color:#ffe074;font-size:64px">' . esc_html__( 'Forest.' ) . '</h2>
<!-- /wp:heading -->
<!-- wp:columns {"align":"wide"} -->
<div class="wp-block-columns alignwide"><!-- wp:column {"width":"55%"} -->
<div class="wp-block-column" style="flex-basis:55%"><!-- wp:spacer {"height":330} -->
<div style="height:330px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:paragraph {"style":{"color":{"text":"#ffe074"},"typography":{"lineHeight":"1.3","fontSize":"12px"}}} -->
<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.' ) . '</em></p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"></div>
<!-- /wp:column --></div>
<!-- /wp:columns --></div></div>
<!-- /wp:cover -->',
'description' => _x( 'Cover image with quote on top', 'Block pattern description' ),
);

View File

@ -1,35 +0,0 @@
<?php
/**
* Large header with text and a button.
*
* @package WordPress
*/
return array(
'title' => _x( 'Large header with text and a button.', 'Block pattern title' ),
'categories' => array( 'header' ),
'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"} -->
<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"} -->
<h2 class="alignwide has-white-color has-text-color" style="font-size:48px;line-height:1.2"><strong><em>' . esc_html__( 'Overseas:' ) . '</em></strong><br><strong><em>' . esc_html__( '1500 1960' ) . '</em></strong></h2>
<!-- /wp:heading -->
<!-- wp:columns {"align":"wide"} -->
<div class="wp-block-columns alignwide"><!-- wp:column {"width":"60%"} -->
<div class="wp-block-column" style="flex-basis:60%"><!-- wp:paragraph {"style":{"color":{"text":"#ffffff"}}} -->
<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>.' ) ) . '</p>
<!-- /wp:paragraph -->
<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button {"borderRadius":0,"style":{"color":{"text":"#ffffff","background":"#000000"}},"className":"is-style-outline"} -->
<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' ) . '</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons --></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"></div>
<!-- /wp:column --></div>
<!-- /wp:columns --></div></div>
<!-- /wp:cover -->',
'description' => _x( 'Large header with background image and text and button on top', 'Block pattern description' ),
);

View File

@ -1,21 +0,0 @@
<?php
/**
* Media and text with image on the right.
*
* @package WordPress
*/
return array(
'title' => _x( 'Media and text with image on the right', 'Block pattern title' ),
'categories' => array( 'header' ),
'content' => '<!-- wp:media-text {"align":"full","mediaId":null,"mediaType":"image","verticalAlignment":"center"} -->
<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.' ) . '"/></figure><div class="wp-block-media-text__content"><!-- wp:heading {"textAlign":"center","level":3,"style":{"color":{"text":"#000000"}}} -->
<h3 class="has-text-align-center has-text-color" style="color:#000000"><strong>' . esc_html__( 'Open Spaces' ) . '</strong></h3>
<!-- /wp:heading -->
<!-- wp:paragraph {"align":"center","fontSize":"extra-small"} -->
<p class="has-text-align-center has-extra-small-font-size"><a href="#">' . esc_html__( 'See case study ' ) . '</a></p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:media-text -->',
'description' => _x( 'Media and text block with image to the left and text to the right', 'Block pattern description' ),
);

View File

@ -1,21 +0,0 @@
<?php
/**
* Media & text with image on the right.
*
* @package WordPress
*/
return array(
'title' => _x( 'Media & text with image on the right', 'Block pattern title' ),
'categories' => array( 'header' ),
'content' => '<!-- wp:media-text {"align":"full","mediaPosition":"right","mediaId":null,"mediaLink":"#","mediaType":"image","mediaWidth":56,"verticalAlignment":"center","className":"is-style-default"} -->
<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.' ) . '"/></figure><div class="wp-block-media-text__content"><!-- wp:heading {"style":{"color":{"text":"#000000"}}} -->
<h2 class="has-text-color" style="color:#000000"><strong>' . esc_html__( 'Shore with Blue Sea' ) . '</strong></h2>
<!-- /wp:heading -->
<!-- wp:paragraph {"style":{"typography":{"lineHeight":"1.1","fontSize":"17px"},"color":{"text":"#636363"}}} -->
<p class="has-text-color" style="color:#636363;font-size:17px;line-height:1.1">' . esc_html__( 'Eleanor Harris&nbsp;(American, 1901-1942)' ) . '</p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:media-text -->',
'description' => _x( 'Media and text block with image to the right and text to the left', 'Block pattern description' ),
);

View File

@ -1,28 +0,0 @@
<?php
/**
* Media & text in a full height container.
*
* @package WordPress
*/
return array(
'title' => _x( 'Media & text in a full height container', 'Block pattern title' ),
'categories' => array( 'header' ),
'content' => '<!-- wp:cover {"customOverlayColor":"#ffffff","minHeight":100,"minHeightUnit":"vh","contentPosition":"center center","align":"full"} -->
<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} -->
<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.' ) . '"/></figure><div class="wp-block-media-text__content"><!-- wp:heading {"style":{"typography":{"fontSize":"32px"},"color":{"text":"#000000"}}} -->
<h2 class="has-text-color" style="color:#000000;font-size:32px"><strong>' . esc_html__( "What's the problem?" ) . '</strong></h2>
<!-- /wp:heading -->
<!-- wp:paragraph {"style":{"typography":{"fontSize":"17px"},"color":{"text":"#000000"}}} -->
<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.' ) . '</p>
<!-- /wp:paragraph -->
<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button {"className":"is-style-fill"} -->
<div class="wp-block-button is-style-fill"><a class="wp-block-button__link">' . esc_html__( 'Learn more' ) . '</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons --></div></div>
<!-- /wp:media-text --></div></div>
<!-- /wp:cover -->',
'description' => _x( 'Media and text block with image to the left and text and button to the right', 'Block pattern description' ),
);

View File

@ -1,30 +0,0 @@
<?php
/**
* Quote.
*
* @package WordPress
*/
return array(
'title' => _x( 'Quote', 'Block pattern title' ),
'categories' => array( 'text' ),
'blockTypes' => array( 'core/quote' ),
'content' => '<!-- wp:group -->
<div class="wp-block-group"><div class="wp-block-group__inner-container"><!-- wp:separator {"className":"is-style-default"} -->
<hr class="wp-block-separator is-style-default"/>
<!-- /wp:separator -->
<!-- wp:image {"align":"center","id":null,"width":150,"height":150,"sizeSlug":"large","linkDestination":"none","className":"is-style-rounded"} -->
<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.' ) . '" width="150" height="150"/></figure></div>
<!-- /wp:image -->
<!-- wp:quote {"align":"center","className":"is-style-large"} -->
<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.\"" ) . '</p><cite>' . wp_kses_post( __( '— Anna Wong, <em>Volunteer</em>' ) ) . '</cite></blockquote>
<!-- /wp:quote -->
<!-- wp:separator {"className":"is-style-default"} -->
<hr class="wp-block-separator is-style-default"/>
<!-- /wp:separator --></div></div>
<!-- /wp:group -->',
'description' => _x( 'Testimonial quote with portrait', 'Block pattern description' ),
);

View File

@ -1,53 +0,0 @@
<?php
/**
* Two columns of text with offset heading.
*
* @package WordPress
*/
return array(
'title' => _x( 'Two columns of text with offset heading', 'Block pattern title' ),
'categories' => array( 'columns', 'text' ),
'content' => '<!-- wp:group {"align":"full","style":{"color":{"background":"#f2f0e9"}}} -->
<div class="wp-block-group alignfull has-background" style="background-color:#f2f0e9"><!-- wp:spacer {"height":70} -->
<div style="height:70px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:columns {"verticalAlignment":"center","align":"wide"} -->
<div class="wp-block-columns alignwide are-vertically-aligned-center"><!-- wp:column {"width":"50%"} -->
<div class="wp-block-column" style="flex-basis:50%"><!-- wp:paragraph {"style":{"typography":{"lineHeight":"1.1","fontSize":"30px"},"color":{"text":"#000000"}}} -->
<p class="has-text-color" style="color:#000000;font-size:30px;line-height:1.1"><strong>' . esc_html__( 'Oceanic Inspiration' ) . '</strong></p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->
<!-- wp:column {"width":"50%"} -->
<div class="wp-block-column" style="flex-basis:50%"><!-- wp:separator {"customColor":"#000000","className":"is-style-wide"} -->
<hr class="wp-block-separator has-text-color has-background is-style-wide" style="background-color:#000000;color:#000000"/>
<!-- /wp:separator --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
<!-- wp:columns {"align":"wide"} -->
<div class="wp-block-columns alignwide"><!-- wp:column -->
<div class="wp-block-column"></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"><!-- wp:paragraph {"style":{"color":{"text":"#000000"}},"fontSize":"extra-small"} -->
<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.' ) . '</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"><!-- wp:paragraph {"style":{"color":{"text":"#000000"}},"fontSize":"extra-small"} -->
<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.' ) . '</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
<!-- wp:spacer {"height":40} -->
<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer --></div>
<!-- /wp:group -->',
'description' => _x( 'Two columns of text with offset heading', 'Block pattern description' ),
);

View File

@ -1,31 +0,0 @@
<?php
/**
* Two columns text and title.
*
* @package WordPress
*/
return array(
'title' => _x( 'Two columns text and title', 'Block pattern title' ),
'categories' => array( 'columns', 'text' ),
'content' => '<!-- wp:group -->
<div class="wp-block-group"><div class="wp-block-group__inner-container"><!-- wp:heading {"style":{"typography":{"fontSize":38,"lineHeight":"1.4"}}} -->
<h2 style="font-size:38px;line-height:1.4"><strong>' . esc_html__( 'The voyage had begun, and had begun happily with a soft blue sky, and a calm sea.' ) . '</strong></h2>
<!-- /wp:heading -->
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:paragraph {"style":{"typography":{"fontSize":18}}} -->
<p style="font-size:18px">' . esc_html__( 'They followed her on to the deck. All the smoke and the houses had disappeared, and the ship was out in a wide space of sea very fresh and clear though pale in the early light. They had left London sitting on its mud. A very thin line of shadow tapered on the horizon, scarcely thick enough to stand the burden of Paris, which nevertheless rested upon it. They were free of roads, free of mankind, and the same exhilaration at their freedom ran through them all.' ) . '</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"><!-- wp:paragraph {"style":{"typography":{"fontSize":18}}} -->
<p style="font-size:18px">' . esc_html__( "The ship was making her way steadily through small waves which slapped her and then fizzled like effervescing water, leaving a little border of bubbles and foam on either side. The colourless October sky above was thinly clouded as if by the trail of wood-fire smoke, and the air was wonderfully salt and brisk. Indeed it was too cold to stand still. Mrs. Ambrose drew her arm within her husband's, and as they moved off it could be seen from the way in which her sloping cheek turned up to his that she had something private to communicate." ) . '</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns --></div></div>
<!-- /wp:group -->',
'description' => _x( 'Two columns text and title', 'Block pattern description' ),
);

View File

@ -1,44 +0,0 @@
<?php
/**
* Two columns of text.
*
* @package WordPress
*/
return array(
'title' => _x( 'Two columns of text', 'Block pattern title' ),
'categories' => array( 'columns', 'text' ),
'content' => '<!-- wp:columns {"align":"full"} -->
<div class="wp-block-columns"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:paragraph {"style":{"typography":{"fontSize":"21px"}, "color":{"text":"#000000"}}} -->
<p class="has-text-color" style="font-size:21px;color:#000000;"><strong>' . esc_html__( 'We have worked with:' ) . '</strong></p>
<!-- /wp:paragraph -->
<!-- wp:paragraph {"style":{"typography":{"fontSize":"24px","lineHeight":"1.2"}}} -->
<p style="font-size:24px;line-height:1.2"><a href="https://wordpress.org">' . wp_kses_post( __( 'EARTHFUND™<br>ARCHWEEKLY<br>FUTURE ROADS<br>BUILDING NY' ) ) . '</a></p>
<!-- /wp:paragraph -->
<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer --></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"><!-- wp:spacer {"height":160} -->
<div style="height:160px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:paragraph {"style":{"typography":{"fontSize":"24px","lineHeight":"1.2"}}} -->
<p style="font-size:24px;line-height:1.2"><a href="https://wordpress.org">' . wp_kses_post( __( 'DUBAI ROOFS<br>MAY WATSON STUDIO<br>Y.O.L<br>RUDIMENTAR' ) ) . '</a></p>
<!-- /wp:paragraph -->
<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->',
'description' => _x( 'Two columns of text', 'Block pattern description' ),
);

View File

@ -1,69 +0,0 @@
<?php
/**
* Three columns with images and text.
*
* @package WordPress
*/
return array(
'title' => _x( 'Three columns with images and text', 'Block pattern title' ),
'categories' => array( 'columns' ),
'content' => '<!-- wp:group {"align":"full","style":{"color":{"background":"#f8f4e4"}}} -->
<div class="wp-block-group alignfull has-background" style="background-color:#f8f4e4"><div class="wp-block-group__inner-container"><!-- wp:columns {"align":"wide"} -->
<div class="wp-block-columns alignwide"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:heading {"level":6,"style":{"color":{"text":"#000000"}}} -->
<h6 class="has-text-color" style="color:#000000">' . esc_html__( 'ECOLOGY' ) . '</h6>
<!-- /wp:heading -->
<!-- wp:paragraph {"style":{"typography":{"lineHeight":"1.1","fontSize":"5vw"},"color":{"text":"#000000"}}} -->
<p class="has-text-color" style="color:#000000;font-size:5vw;line-height:1.1"><strong>' . esc_html__( 'Natural resources.' ) . '</strong></p>
<!-- /wp:paragraph --><!-- wp:spacer {"height":5} -->
<div style="height:5px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
<!-- wp:columns {"align":"wide"} -->
<div class="wp-block-columns alignwide"><!-- wp:column {"width":"33.38%"} -->
<div class="wp-block-column" style="flex-basis:33.38%"><!-- wp:paragraph {"style":{"color":{"text":"#000000"}},"fontSize":"extra-small"} -->
<p class="has-text-color has-extra-small-font-size" style="color:#000000">' . wp_kses_post( __( '<em>Nature</em>, in the common sense, refers to essences unchanged by man; space, the air, the river, the leaf.&nbsp;<em>Art</em>&nbsp;is applied to the mixture of his will with the same things, as in a house, a canal, a statue, a picture. But his operations taken together are so insignificant, a little chipping, baking, patching, and washing, that in an impression so grand as that of the world on the human mind, they do not vary the result.' ) ) . '</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->
<!-- wp:column {"width":"33%"} -->
<div class="wp-block-column" style="flex-basis:33%"><!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:image {"id":null,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://s.w.org/images/core/5.8/outside-01.jpg" alt="' . esc_attr__( 'The sun setting through a dense forest of trees.' ) . '" /></figure>
<!-- /wp:image --></div>
<!-- /wp:column -->
<!-- wp:column {"width":"33.62%"} -->
<div class="wp-block-column" style="flex-basis:33.62%"><!-- wp:image {"id":null,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://s.w.org/images/core/5.8/outside-02.jpg" alt="' . esc_attr__( 'Wind turbines standing on a grassy plain, against a blue sky.' ) . '" /></figure>
<!-- /wp:image --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
<!-- wp:columns {"align":"wide"} -->
<div class="wp-block-columns alignwide"><!-- wp:column {"width":"67%"} -->
<div class="wp-block-column" style="flex-basis:67%"><!-- wp:image {"align":"right","id":null,"sizeSlug":"large","linkDestination":"none"} -->
<div class="wp-block-image"><figure class="alignright size-large"><img src="https://s.w.org/images/core/5.8/outside-03.jpg" alt="' . esc_attr__( 'The sun shining over a ridge leading down into the shore. In the distance, a car drives down a road.' ) . '" /></figure></div>
<!-- /wp:image --></div>
<!-- /wp:column -->
<!-- wp:column {"verticalAlignment":"center","width":"33%"} -->
<div class="wp-block-column is-vertically-aligned-center" style="flex-basis:33%"><!-- wp:paragraph {"style":{"color":{"text":"#000000"}},"fontSize":"extra-small"} -->
<p class="has-text-color has-extra-small-font-size" style="color:#000000">' . esc_html__( "Undoubtedly we have no questions to ask which are unanswerable. We must trust the perfection of the creation so far, as to believe that whatever curiosity the order of things has awakened in our minds, the order of things can satisfy. Every man's condition is a solution in hieroglyphic to those inquiries he would put." ) . '</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns --></div></div>
<!-- /wp:group -->',
'description' => _x( 'Three columns with images and text', 'Block pattern description' ),
);

View File

@ -1,43 +0,0 @@
<?php
/**
* Three columns of text.
*
* @package WordPress
*/
return array(
'title' => _x( 'Three columns of text', 'Block pattern title' ),
'categories' => array( 'columns', 'text' ),
'content' => '<!-- wp:columns {"align":"full","style":{"color":{"text":"#000000","background":"#ffffff"}}} -->
<div class="wp-block-columns alignfull has-text-color has-background" style="background-color:#ffffff;color:#000000"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:heading {"level":3,"style":{"typography":{"fontSize":"24px","lineHeight":"1.3"}}} -->
<h3 style="font-size:24px;line-height:1.3"><strong><a href="http://wordpress.org">' . esc_html__( 'Virtual Tour ' ) . '</a></strong></h3>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>' . esc_html__( 'Get a virtual tour of the museum. Ideal for schools and events.' ) . '</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"><!-- wp:heading {"level":3,"style":{"typography":{"fontSize":"24px","lineHeight":"1.3"}}} -->
<h3 style="font-size:24px;line-height:1.3"><strong><a href="https://wordpress.org">' . esc_html__( 'Current Shows ' ) . '</a></strong></h3>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>' . esc_html__( 'Stay updated and see our current exhibitions here.' ) . '</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"><!-- wp:heading {"level":3,"style":{"typography":{"fontSize":"24px","lineHeight":"1.3"}}} -->
<h3 style="font-size:24px;line-height:1.3"><strong><a href="https://wordpress.org">' . esc_html__( 'Useful Info ' ) . '</a></strong></h3>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>' . esc_html__( 'Get to know our opening times, ticket prices and discounts.' ) . '</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->',
'description' => _x( 'Three columns of text', 'Block pattern description' ),
);

View File

@ -1,43 +0,0 @@
<?php
/**
* Three columns with offset images.
*
* @package WordPress
*/
return array(
'title' => _x( 'Three columns with offset images', 'Block pattern title' ),
'categories' => array( 'gallery' ),
'content' => '<!-- wp:columns {"align":"wide"} -->
<div class="wp-block-columns alignwide"><!-- wp:column {"width":"25%"} -->
<div class="wp-block-column" style="flex-basis:25%"><!-- wp:image {"id":null,"sizeSlug":"large","linkDestination":"none","className":"is-style-default"} -->
<figure class="wp-block-image size-large is-style-default"><img src="https://s.w.org/images/core/5.8/architecture-01.jpg" alt="' . esc_attr__( 'Close-up, abstract view of geometric architecture.' ) . '" /></figure>
<!-- /wp:image --></div>
<!-- /wp:column -->
<!-- wp:column {"width":"25%"} -->
<div class="wp-block-column" style="flex-basis:25%"><!-- wp:spacer {"height":500} -->
<div style="height:500px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:spacer {"height":150} -->
<div style="height:150px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->
<!-- wp:image {"id":null,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large"><img src="https://s.w.org/images/core/5.8/architecture-02.jpg" alt="' . esc_attr__( 'Close-up, angled view of a window on a white building.' ) . '" /></figure>
<!-- /wp:image --></div>
<!-- /wp:column -->
<!-- wp:column {"width":"45%"} -->
<div class="wp-block-column" style="flex-basis:45%"><!-- wp:image {"id":null,"sizeSlug":"large","linkDestination":"none","className":"is-style-default"} -->
<figure class="wp-block-image size-large is-style-default"><img src="https://s.w.org/images/core/5.8/architecture-03.jpg" alt="' . esc_attr__( 'Close-up of the corner of a white, geometric building with both sharp points and round corners.' ) . '" /></figure>
<!-- /wp:image -->
<!-- wp:spacer {"height":285} -->
<div style="height:285px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->',
'description' => _x( 'Three columns with offset images', 'Block pattern description' ),
);

View File

@ -1,22 +0,0 @@
<?php
/**
* Two Buttons block pattern.
*
* @package WordPress
*/
return array(
'title' => _x( 'Two buttons', 'Block pattern title' ),
'content' => '<!-- wp:buttons {"contentJustification":"center"} -->
<div class="wp-block-buttons is-content-justification-center"><!-- wp:button {"borderRadius":0} -->
<div class="wp-block-button"><a class="wp-block-button__link no-border-radius">' . esc_html__( 'Our Work' ) . '</a></div>
<!-- /wp:button -->
<!-- wp:button {"borderRadius":1,"className":"is-style-outline"} -->
<div class="wp-block-button is-style-outline"><a class="wp-block-button__link" style="border-radius:1px">' . esc_html__( 'Where We Are' ) . '</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons -->',
'viewportWidth' => 500,
'categories' => array( 'buttons' ),
'description' => _x( 'Two buttons, one filled and one outlined, side by side.', 'Block pattern description' ),
);

View File

@ -1,15 +0,0 @@
<?php
/**
* Two images side by side.
*
* @package WordPress
*/
return array(
'title' => _x( 'Two images side by side', 'Block pattern title' ),
'categories' => array( 'gallery' ),
'content' => '<!-- wp:gallery {"ids":[null,null],"linkTo":"none","align":"wide"} -->
<figure class="wp-block-gallery alignwide columns-2 is-cropped"><ul class="blocks-gallery-grid"><li class="blocks-gallery-item"><figure><img src="https://s.w.org/images/core/5.8/nature-above-01.jpg" alt="' . esc_attr__( 'An aerial view of waves crashing against a shore.' ) . '" data-full-url="https://s.w.org/images/core/5.8/nature-above-01.jpg" data-link="#" /></figure></li><li class="blocks-gallery-item"><figure><img src="https://s.w.org/images/core/5.8/nature-above-02.jpg" alt="' . esc_attr__( 'An aerial view of a field. A road runs through the upper right corner.' ) . '" data-full-url="https://s.w.org/images/core/5.8/nature-above-02.jpg" data-link="#" /></figure></li></ul></figure>
<!-- /wp:gallery -->',
'description' => _x( 'Two images side by side', 'Block pattern description' ),
);

View File

@ -315,6 +315,7 @@ add_action( 'wp_footer', 'wp_print_footer_scripts', 20 );
add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 ); add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );
add_action( 'wp_print_footer_scripts', '_wp_footer_scripts' ); add_action( 'wp_print_footer_scripts', '_wp_footer_scripts' );
add_action( 'init', '_register_core_block_patterns_and_categories' ); add_action( 'init', '_register_core_block_patterns_and_categories' );
add_action( 'current_screen', '_load_remote_block_patterns' );
add_action( 'init', 'check_theme_switched', 99 ); add_action( 'init', 'check_theme_switched', 99 );
add_action( 'init', array( 'WP_Block_Supports', 'init' ), 22 ); add_action( 'init', array( 'WP_Block_Supports', 'init' ), 22 );
add_action( 'after_switch_theme', '_wp_menus_changed' ); add_action( 'after_switch_theme', '_wp_menus_changed' );

View File

@ -329,6 +329,10 @@ function create_initial_rest_routes() {
$controller = new WP_REST_Block_Directory_Controller(); $controller = new WP_REST_Block_Directory_Controller();
$controller->register_routes(); $controller->register_routes();
// Pattern Directory.
$controller = new WP_REST_Pattern_Directory_Controller();
$controller->register_routes();
// Site Health. // Site Health.
$site_health = WP_Site_Health::get_instance(); $site_health = WP_Site_Health::get_instance();
$controller = new WP_REST_Site_Health_Controller( $site_health ); $controller = new WP_REST_Site_Health_Controller( $site_health );

View File

@ -0,0 +1,297 @@
<?php
/**
* Block Pattern Directory REST API: WP_REST_Pattern_Directory_Controller class
*
* @package WordPress
* @subpackage REST_API
* @since 5.8.0
*/
/**
* Controller which provides REST endpoint for block patterns.
*
* This simply proxies the endpoint at http://api.wordpress.org/patterns/1.0/. That isn't necessary for
* functionality, but is desired for privacy. It prevents api.wordpress.org from knowing the user's IP address.
*
* @since 5.8.0
*
* @see WP_REST_Controller
*/
class WP_REST_Pattern_Directory_Controller extends WP_REST_Controller {
/**
* Constructs the controller.
*/
public function __construct() {
$this->namespace = 'wp/v2';
$this->rest_base = 'pattern-directory';
}
/**
* Registers the necessary REST API routes.
*/
public function register_routes() {
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/patterns',
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => $this->get_collection_params(),
),
'schema' => array( $this, 'get_public_item_schema' ),
)
);
}
/**
* Checks whether a given request has permission to view the local pattern directory.
*
* @since 5.8.0
*
* @param WP_REST_Request $request Full details about the request.
*
* @return WP_Error|bool True if the request has permission, WP_Error object otherwise.
*/
public function get_items_permissions_check( $request ) {
if ( current_user_can( 'edit_posts' ) ) {
return true;
}
foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
if ( current_user_can( $post_type->cap->edit_posts ) ) {
return true;
}
}
return new WP_Error(
'rest_pattern_directory_cannot_view',
__( 'Sorry, you are not allowed to browse the local block pattern directory.' ),
array( 'status' => rest_authorization_required_code() )
);
}
/**
* Search and retrieve block patterns metadata
*
* @since 5.8.0
*
* @param WP_REST_Request $request Full details about the request.
*
* @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
*/
public function get_items( $request ) {
$query_args = array();
$category_id = $request['category'];
$keyword_id = $request['keyword'];
$search_term = $request['search'];
if ( $category_id ) {
$query_args['pattern-categories'] = $category_id;
}
if ( $keyword_id ) {
$query_args['pattern-keywords'] = $keyword_id;
}
if ( $search_term ) {
$query_args['search'] = $search_term;
}
$api_url = add_query_arg(
array_map( 'rawurlencode', $query_args ),
'http://api.wordpress.org/patterns/1.0/'
);
if ( wp_http_supports( array( 'ssl' ) ) ) {
$api_url = set_url_scheme( $api_url, 'https' );
}
$wporg_response = wp_remote_get( $api_url );
$raw_patterns = json_decode( wp_remote_retrieve_body( $wporg_response ) );
if ( is_wp_error( $wporg_response ) ) {
$wporg_response->add_data( array( 'status' => 500 ) );
return $wporg_response;
}
// Make sure w.org returned valid data.
if ( ! is_array( $raw_patterns ) ) {
return new WP_Error(
'pattern_api_failed',
sprintf(
/* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
__( 'https://wordpress.org/support/forums/' )
),
array(
'status' => 500,
'response' => wp_remote_retrieve_body( $wporg_response ),
)
);
}
$response = array();
if ( $raw_patterns ) {
foreach ( $raw_patterns as $pattern ) {
$response[] = $this->prepare_response_for_collection(
$this->prepare_item_for_response( $pattern, $request )
);
}
}
return new WP_REST_Response( $response );
}
/**
* Prepare a raw pattern before it's output in an API response.
*
* @since 5.8.0
*
* @param object $raw_pattern A pattern from api.wordpress.org, before any changes.
* @param WP_REST_Request $request Request object.
*
* @return WP_REST_Response
*/
public function prepare_item_for_response( $raw_pattern, $request ) {
$prepared_pattern = array(
'id' => absint( $raw_pattern->id ),
'title' => sanitize_text_field( $raw_pattern->title->rendered ),
'content' => wp_kses_post( $raw_pattern->pattern_content ),
'categories' => array_map( 'sanitize_title', $raw_pattern->category_slugs ),
'keywords' => array_map( 'sanitize_title', $raw_pattern->keyword_slugs ),
'description' => sanitize_text_field( $raw_pattern->meta->wpop_description ),
'viewport_width' => absint( $raw_pattern->meta->wpop_viewport_width ),
);
$prepared_pattern = $this->add_additional_fields_to_object( $prepared_pattern, $request );
$response = new WP_REST_Response( $prepared_pattern );
/**
* Filters the REST API response for a pattern.
*
* @since 5.8.0
*
* @param WP_REST_Response $response The response object.
* @param object $raw_pattern The unprepared pattern.
* @param WP_REST_Request $request The request object.
*/
return apply_filters( 'rest_prepare_block_pattern', $response, $raw_pattern, $request );
}
/**
* Retrieves the pattern's schema, conforming to JSON Schema.
*
* @since 5.8.0
*
* @return array Item schema data.
*/
public function get_item_schema() {
if ( $this->schema ) {
return $this->add_additional_fields_schema( $this->schema );
}
$this->schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'pattern-directory-item',
'type' => 'object',
'properties' => array(
'id' => array(
'description' => __( 'The pattern ID.' ),
'type' => 'integer',
'minimum' => 1,
'context' => array( 'view', 'embed' ),
),
'title' => array(
'description' => __( 'The pattern title, in human readable format.' ),
'type' => 'string',
'minLength' => 1,
'context' => array( 'view', 'embed' ),
),
'content' => array(
'description' => __( 'The pattern content.' ),
'type' => 'string',
'minLength' => 1,
'context' => array( 'view', 'embed' ),
),
'categories' => array(
'description' => __( "The pattern's category slugs." ),
'type' => 'array',
'uniqueItems' => true,
'items' => array( 'type' => 'string' ),
'context' => array( 'view', 'embed' ),
),
'keywords' => array(
'description' => __( "The pattern's keyword slugs." ),
'type' => 'array',
'uniqueItems' => true,
'items' => array( 'type' => 'string' ),
'context' => array( 'view', 'embed' ),
),
'description' => array(
'description' => __( 'A description of the pattern.' ),
'type' => 'string',
'minLength' => 1,
'context' => array( 'view', 'embed' ),
),
'viewport_width' => array(
'description' => __( 'The preferred width of the viewport when previewing a pattern, in pixels.' ),
'type' => 'integer',
'context' => array( 'view', 'embed' ),
),
),
);
return $this->add_additional_fields_schema( $this->schema );
}
/**
* Retrieves the search params for the patterns collection.
*
* @since 5.8.0
*
* @return array Collection parameters.
*/
public function get_collection_params() {
$query_params = parent::get_collection_params();
// Pagination is not supported.
unset( $query_params['page'] );
unset( $query_params['per_page'] );
$query_params['search']['minLength'] = 1;
$query_params['context']['default'] = 'view';
$query_params['category'] = array(
'description' => __( 'Limit results to those matching a category ID.' ),
'type' => 'integer',
'minimum' => 1,
);
$query_params['keyword'] = array(
'description' => __( 'Limit results to those matching a keyword ID.' ),
'type' => 'integer',
'minimum' => 1,
);
/**
* Filter collection parameters for the pattern directory controller.
*
* @since 5.8.0
*
* @param array $query_params JSON Schema-formatted collection parameters.
*/
return apply_filters( 'rest_pattern_directory_collection_params', $query_params );
}
}

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.8-alpha-51020'; $wp_version = '5.8-alpha-51021';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -268,6 +268,7 @@ require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-settings-controller
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-themes-controller.php'; require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-themes-controller.php';
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-plugins-controller.php'; require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-plugins-controller.php';
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-block-directory-controller.php'; require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-block-directory-controller.php';
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php';
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-application-passwords-controller.php'; require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-application-passwords-controller.php';
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-site-health-controller.php'; require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-site-health-controller.php';
require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-sidebars-controller.php'; require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-sidebars-controller.php';