Skip to content

Commit

Permalink
Merge branch 'trunk' into update/selectcontrol-margin
Browse files Browse the repository at this point in the history
  • Loading branch information
brookewp authored Dec 13, 2022
2 parents 473699f + 6a54882 commit 36aaa60
Show file tree
Hide file tree
Showing 97 changed files with 2,493 additions and 659 deletions.
4 changes: 2 additions & 2 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ Contains the block elements used to render a post, like the title, date, feature

- **Name:** core/post-template
- **Category:** theme
- **Supports:** align, typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
- **Supports:** align, color (background, gradients, link, text), typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
- **Attributes:**

## Post Terms
Expand Down Expand Up @@ -617,7 +617,7 @@ An advanced block that allows displaying post types based on different query par

- **Name:** core/query
- **Category:** theme
- **Supports:** align (full, wide), color (background, gradients, link, text), ~~html~~
- **Supports:** align (full, wide), ~~html~~
- **Attributes:** displayLayout, namespace, query, queryId, tagName

## No results
Expand Down
41 changes: 28 additions & 13 deletions docs/reference-guides/data/data-core-edit-site.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ _Returns_

- `Array`: Template parts and their blocks in an array.

### getEditedPostContext

> **Deprecated**
Returns the edited post's context object.

_Parameters_

- _state_ `Object`: Global application state.

_Returns_

- `Object`: Page.

### getEditedPostId

Returns the ID of the currently edited template or template part.
Expand Down Expand Up @@ -72,22 +86,16 @@ _Returns_

### getHomeTemplateId

Returns the current home template ID.

_Parameters_

- _state_ `Object`: Global application state.

_Returns_

- `number?`: Home template ID.
> **Deprecated**
### getNavigationPanelActiveMenu

> **Deprecated**
### getPage

> **Deprecated**
Returns the current page object.

_Parameters_
Expand Down Expand Up @@ -230,14 +238,21 @@ _Parameters_
- _options_ `[Object]`:
- _options.allowUndo_ `[boolean]`: Whether to allow the user to undo reverting the template. Default true.

### setHomeTemplateId
### setEditedPostContext

Action that sets the home template ID to the template ID of the page resolved
from a given path.
Set's the current block editor context.

_Parameters_

- _homeTemplateId_ `number`: The template ID for the homepage.
- _context_ `Object`: The context object.

_Returns_

- `number`: The resolved template ID for the page route.

### setHomeTemplateId

> **Deprecated**
### setIsInserterOpened

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* REST API: Gutenberg_REST_Block_Patterns_Controller class
* REST API: Gutenberg_REST_Block_Patterns_Controller_6_1 class
*
* @package Gutenberg
* @subpackage REST_API
Expand All @@ -13,104 +13,12 @@
*
* @see WP_REST_Controller
*/
class Gutenberg_REST_Block_Patterns_Controller extends WP_REST_Controller {

/**
* Defines whether remote patterns should be loaded.
*
* @since 6.0.0
* @var bool
*/
private $remote_patterns_loaded;

/**
* Constructs the controller.
*
* @since 6.0.0
*/
public function __construct() {
$this->namespace = 'wp/v2';
$this->rest_base = 'block-patterns/patterns';
}

/**
* Registers the routes for the objects of the controller.
*
* @since 6.0.0
*/
public function register_routes() {
register_rest_route(
$this->namespace,
'/' . $this->rest_base,
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
),
'schema' => array( $this, 'get_public_item_schema' ),
),
true
);
}

/**
* Checks whether a given request has permission to read block patterns.
*
* @since 6.0.0
*
* @param WP_REST_Request $request Full details about the request.
* @return true|WP_Error True if the request has read access, WP_Error object otherwise.
*/
public function get_items_permissions_check( $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
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_cannot_view',
__( 'Sorry, you are not allowed to view the registered block patterns.', 'gutenberg' ),
array( 'status' => rest_authorization_required_code() )
);
}

/**
* Retrieves all block patterns.
*
* @since 6.0.0
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_items( $request ) {
if ( ! $this->remote_patterns_loaded ) {
// Load block patterns from w.org.
_load_remote_block_patterns(); // Patterns with the `core` keyword.
_load_remote_featured_patterns(); // Patterns in the `featured` category.
_register_remote_theme_patterns(); // Patterns requested by current theme.

$this->remote_patterns_loaded = true;
}

$response = array();
$patterns = WP_Block_Patterns_Registry::get_instance()->get_all_registered();
foreach ( $patterns as $pattern ) {
$prepared_pattern = $this->prepare_item_for_response( $pattern, $request );
$response[] = $this->prepare_response_for_collection( $prepared_pattern );
}
return rest_ensure_response( $response );
}

class Gutenberg_REST_Block_Patterns_Controller_6_1 extends WP_REST_Block_Patterns_Controller {
/**
* Prepare a raw block pattern before it gets output in a REST API response.
*
* @since 6.0.0
* @since 6.1.0 Added `postTypes` property.
*
* @param array $item Raw pattern as registered, before any changes.
* @param WP_REST_Request $request Request object.
Expand Down Expand Up @@ -147,6 +55,7 @@ public function prepare_item_for_response( $item, $request ) {
* Retrieves the block pattern schema, conforming to JSON Schema.
*
* @since 6.0.0
* @since 6.1.0 Added `post_types` property.
*
* @return array Item schema data.
*/
Expand Down
9 changes: 0 additions & 9 deletions lib/compat/wordpress-6.1/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ function gutenberg_update_post_types_rest_response( $response, $post_type ) {
}
add_filter( 'rest_prepare_post_type', 'gutenberg_update_post_types_rest_response', 10, 2 );

/**
* Registers the block patterns REST API routes.
*/
function gutenberg_register_gutenberg_rest_block_patterns() {
$block_patterns = new Gutenberg_REST_Block_Patterns_Controller();
$block_patterns->register_routes();
}
add_action( 'rest_api_init', 'gutenberg_register_gutenberg_rest_block_patterns', 100 );

/**
* Exposes the site logo URL through the WordPress REST API.
*
Expand Down
28 changes: 28 additions & 0 deletions lib/compat/wordpress-6.2/block-editor-settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Adds settings to the block editor.
*
* @package gutenberg
*/

/**
* Adds styles and __experimentalFeatures to the block editor settings.
*
* @param array $settings Existing block editor settings.
*
* @return array New block editor settings.
*/
function gutenberg_get_block_editor_settings_6_2( $settings ) {
if ( wp_theme_has_theme_json() ) {
// Add the custom CSS as separate style sheet so any invalid CSS entered by users does not break other global styles.
$settings['styles'][] = array(
'css' => gutenberg_get_global_stylesheet( array( 'custom-css' ) ),
'__unstableType' => 'user',
'isGlobalStyles' => true,
);
}

return $settings;
}

add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings_6_2', PHP_INT_MAX );
Loading

0 comments on commit 36aaa60

Please sign in to comment.