Skip to content

Commit

Permalink
prep build 12/17
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Dec 17, 2021
2 parents 6654255 + 77a8622 commit 27ad726
Show file tree
Hide file tree
Showing 94 changed files with 2,634 additions and 984 deletions.
264 changes: 264 additions & 0 deletions changelog.txt

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/reference-guides/data/data-core-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ _Parameters_

- _state_ `Object`: Editor state.
- _clientId_ `string`: Block client ID.
- _rootClientId_ `?string`: Optional root client ID of block list.

_Returns_

Expand Down
101 changes: 4 additions & 97 deletions lib/block-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function gutenberg_register_gutenberg_patterns() {
'title' => _x( 'Standard', 'Block pattern title', 'gutenberg' ),
'blockTypes' => array( 'core/query' ),
'categories' => array( 'query' ),
'content' => '<!-- wp:query {"query":{"perPage":3,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false}} -->
'content' => '<!-- wp:query {"query":{"perPage":1,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false}} -->
<div class="wp-block-query">
<!-- wp:post-template -->
<!-- wp:post-title {"isLink":true} /-->
Expand All @@ -37,7 +37,7 @@ function gutenberg_register_gutenberg_patterns() {
'title' => _x( 'Image at left', 'Block pattern title', 'gutenberg' ),
'blockTypes' => array( 'core/query' ),
'categories' => array( 'query' ),
'content' => '<!-- wp:query {"query":{"perPage":3,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false}} -->
'content' => '<!-- wp:query {"query":{"perPage":1,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false}} -->
<div class="wp-block-query">
<!-- wp:post-template -->
<!-- wp:columns {"align":"wide"} -->
Expand All @@ -57,7 +57,7 @@ function gutenberg_register_gutenberg_patterns() {
'title' => _x( 'Small image and title', 'Block pattern title', 'gutenberg' ),
'blockTypes' => array( 'core/query' ),
'categories' => array( 'query' ),
'content' => '<!-- wp:query {"query":{"perPage":3,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false}} -->
'content' => '<!-- wp:query {"query":{"perPage":1,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false}} -->
<div class="wp-block-query">
<!-- wp:post-template -->
<!-- wp:columns {"verticalAlignment":"center"} -->
Expand All @@ -76,7 +76,7 @@ function gutenberg_register_gutenberg_patterns() {
'title' => _x( 'Grid', 'Block pattern title', 'gutenberg' ),
'blockTypes' => array( 'core/query' ),
'categories' => array( 'query' ),
'content' => '<!-- wp:query {"query":{"perPage":6,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"exclude","inherit":false},"displayLayout":{"type":"flex","columns":3}} -->
'content' => '<!-- wp:query {"query":{"perPage":3,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"exclude","inherit":false},"displayLayout":{"type":"flex","columns":3}} -->
<div class="wp-block-query">
<!-- wp:post-template -->
<!-- wp:group {"style":{"spacing":{"padding":{"top":"30px","right":"30px","bottom":"30px","left":"30px"}}},"layout":{"inherit":false}} -->
Expand Down Expand Up @@ -199,84 +199,6 @@ function gutenberg_remove_core_patterns() {
}
}

/**
* Register Core's official patterns from wordpress.org/patterns.
*
* @since 5.8.0
*/
function gutenberg_load_remote_core_patterns() {
// This is the core function that provides the same feature.
if ( function_exists( '_load_remote_block_patterns' ) ) {
return;
}

/**
* 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 ( $should_load_remote ) {
$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();

foreach ( $patterns as $settings ) {
$pattern_name = 'core/' . sanitize_title( $settings['title'] );
register_block_pattern( $pattern_name, (array) $settings );
}
}
}

/**
* Register `Featured` (category) patterns from wordpress.org/patterns.
*
* @since 5.9.0
*/
function gutenberg_load_remote_featured_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 ( ! $should_load_remote ) {
return;
}

if ( ! WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( 'featured' ) ) {
register_block_pattern_category( 'featured', array( 'label' => __( 'Featured', 'gutenberg' ) ) );
}
$request = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns' );
$request['category'] = 26; // This is the `Featured` category id from pattern directory.
$response = rest_do_request( $request );
if ( $response->is_error() ) {
return;
}
$patterns = $response->get_data();
foreach ( $patterns as $pattern ) {
$pattern_name = sanitize_title( $pattern['title'] );
$registry = WP_Block_Patterns_Registry::get_instance();
// Some patterns might be already registerd as `core patterns with the `core` prefix.
$is_registered = $registry->is_registered( $pattern_name ) || $registry->is_registered( "core/$pattern_name" );
if ( ! $is_registered ) {
register_block_pattern( $pattern_name, (array) $pattern );
}
}
}


add_action(
'init',
function() {
Expand All @@ -287,18 +209,3 @@ function() {
gutenberg_register_gutenberg_patterns();
}
);

add_action(
'current_screen',
function( $current_screen ) {
if ( ! get_theme_support( 'core-block-patterns' ) ) {
return;
}

$is_site_editor = ( function_exists( 'gutenberg_is_edit_site_page' ) && gutenberg_is_edit_site_page( $current_screen->id ) );
if ( $current_screen->is_block_editor || $is_site_editor ) {
gutenberg_load_remote_core_patterns();
gutenberg_load_remote_featured_patterns();
}
}
);
54 changes: 54 additions & 0 deletions lib/compat/wordpress-5.8/block-patterns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Block patterns functions.
*
* @package gutenberg
*/

if ( ! function_exists( '_load_remote_block_patterns' ) ) {
/**
* Register Core's official patterns from wordpress.org/patterns.
*
* @since 5.8.0
*/
function _load_remote_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 ( $should_load_remote ) {
$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();

foreach ( $patterns as $settings ) {
$pattern_name = 'core/' . sanitize_title( $settings['title'] );
register_block_pattern( $pattern_name, (array) $settings );
}
}
}

add_action(
'current_screen',
function( $current_screen ) {
if ( ! get_theme_support( 'core-block-patterns' ) ) {
return;
}

$is_site_editor = ( function_exists( 'gutenberg_is_edit_site_page' ) && gutenberg_is_edit_site_page( $current_screen->id ) );
if ( $current_screen->is_block_editor || $is_site_editor ) {
_load_remote_block_patterns();
}
}
);
}
60 changes: 60 additions & 0 deletions lib/compat/wordpress-5.9/block-patterns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Block patterns functions.
*
* @package gutenberg
*/

if ( ! function_exists( '_load_remote_featured_patterns' ) ) {
/**
* Loads featured patterns from patterns directory.
*/
function _load_remote_featured_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 ( ! $should_load_remote ) {
return;
}

if ( ! WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( 'featured' ) ) {
register_block_pattern_category( 'featured', array( 'label' => __( 'Featured', 'gutenberg' ) ) );
}
$request = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns' );
$request['category'] = 26; // This is the `Featured` category id from pattern directory.
$response = rest_do_request( $request );
if ( $response->is_error() ) {
return;
}
$patterns = $response->get_data();
foreach ( $patterns as $pattern ) {
$pattern_name = sanitize_title( $pattern['title'] );
$registry = WP_Block_Patterns_Registry::get_instance();
// Some patterns might be already registerd as `core patterns with the `core` prefix.
$is_registered = $registry->is_registered( $pattern_name ) || $registry->is_registered( "core/$pattern_name" );
if ( ! $is_registered ) {
register_block_pattern( $pattern_name, (array) $pattern );
}
}
}

add_action(
'current_screen',
function( $current_screen ) {
if ( ! get_theme_support( 'core-block-patterns' ) ) {
return;
}

$is_site_editor = ( function_exists( 'gutenberg_is_edit_site_page' ) && gutenberg_is_edit_site_page( $current_screen->id ) );
if ( $current_screen->is_block_editor || $is_site_editor ) {
_load_remote_featured_patterns();
}
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function register_routes() {
// List themes global styles.
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/themes/(?P<stylesheet>[^.\/]+(?:\/[^.\/]+)?)',
'/' . $this->rest_base . '/themes/(?P<stylesheet>[\/\s%\w\.\(\)\[\]\@_\-]+)',
array(
array(
'methods' => WP_REST_Server::READABLE,
Expand All @@ -46,16 +46,17 @@ public function register_routes() {
// Lists/updates a single global style variation based on the given id.
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<id>[\/\w-]+)',
'/' . $this->rest_base . '/(?P<id>[\/\s%\w\.\(\)\[\]\@_\-]+)',
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
'permission_callback' => array( $this, 'get_item_permissions_check' ),
'args' => array(
'id' => array(
'description' => __( 'The id of the global style variation', 'gutenberg' ),
'type' => 'string',
'description' => __( 'The id of the global style variation', 'gutenberg' ),
'type' => 'string',
'sanitize_callback' => array( $this, '_sanitize_global_styles_callback' ),
),
),
),
Expand All @@ -70,6 +71,20 @@ public function register_routes() {
);
}

/**
* Sanitize the global styles ID or stylesheet to decode endpoint.
* For example, `wp/v2/global-styles/templatetwentytwo%200.4.0`
* would be decoded to `templatetwentytwo 0.4.0`.
*
* @since 5.9.0
*
* @param string $id_or_stylesheet Global styles ID or stylesheet.
* @return string Sanitized global styles ID or stylesheet.
*/
public function _sanitize_global_styles_callback( $id_or_stylesheet ) {
return urldecode( $id_or_stylesheet );
}

/**
* Checks if the user has permissions to make the request.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function register_routes() {
// Lists/updates a single template based on the given id.
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/(?P<id>[\/\w-]+)',
'/' . $this->rest_base . '/(?P<id>[\/\s%\w\.\(\)\[\]\@_\-]+)',
array(
array(
'methods' => WP_REST_Server::READABLE,
Expand Down Expand Up @@ -131,7 +131,10 @@ protected function permissions_check() {
* @return string Sanitized template ID.
*/
public function _sanitize_template_id( $id ) {
// Decode empty space.
$last_slash_pos = strrpos( $id, '/' );
$id = urldecode( $id );

if ( false === $last_slash_pos ) {
return $id;
}
Expand Down
Loading

0 comments on commit 27ad726

Please sign in to comment.