mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Update @wordpress packages
Update packages to include these bug fixes from Gutenberg: - Update Pattern block category and add documentation - Fix non existent menu handling in nav block - Make Reusable blocks available in the Site Editor - Add caching to WP_Theme_JSON_Resolver_Gutenberg::get_user_data_from_custom_post_type() - theme.json: add appearanceTools flag to opt-in into appearance UI controls - Update the block theme folders to templates and parts - Remove reference to gutenberg_, swap with wp_ - Use table layout in templates list screen - Update featured image placeholder graphic. - [Inserter]: Adjust order of theme blocks and reorder inserter items - Implement suitable fallback for Nav block on front end of site when no menu selected - Toggle Group Control: add tooltip - Use first non-empty Nav post as primary fallback for Nav block - Change .nvmrc and documentation for Node.js version (LTS to 14.18.1) - Update: Migrate global styles user database data on the rest endpoint - Update global styles public API - Update: Rename user preset origin to custom - Try always generating navigation post title - Show all templates and template parts on the site editor list screens - Highlight "Site" in the navigation panel - Fix template part slug generation when creating through the block placeholder - [Block Library - Post Title]: Fix render error when setting Page to homepage - Add 'Clear customizations' button to template list page - Gallery v1: Allow clicks within replace media placeholder state - Site Editor: Set the <title> on the list page to be same as the CPT name - Gallery: Fix stuck image size options loader - Cover: Fix undo trap - Add success and error snackbars to the templates list page - Fix: theme colors cannot override defaults - Fix: Color palette is not being stored - Add elements support to the typography panel in global styles - Make links plural in global styles - Add: Gradient palette editor - Update some small style regressions in the template list - Add: Transparency support on global styles colors - Fix: apply by slug on all origins - Render empty Nav block if no fallback block can be utilised - Allow filtering of Nav block fallback - Fix Nav block fallback DB query to match on full block grammar start tag - Remove unstable max pages attribute from Nav block - DateTimePicker: set PM hours correctly - Update delete template button - Site Editor: Template list add rename action - Fix Nav block editing wrong entity on creation of new Menu - [REST] Restore the missing double slash in the ID received by /templates - Add icons to navigation sidebar items - Update function names for the public global styles API functions - Templates Controller: Add missing 'is_custom' prop - Rename gutenberg_ to wp_ for some functions that land in WordPress 5.9 - [Block Library - Template Part]:Remove support for conversion to Reusable block - Global Styles: Call "palettes" and not "color palettes" on panel label - Add button text when no colors found - Update: Global Styes: Count all color palette origins on the palette counter - Rename navigationMenuId to ref - Offset the parent iframe when computing Popover position - Fix: Failing PHPUnit test - Show theme, plugin or author in Added By column with appropriate icon or avatar - Add origin and author to template rest api See #54487. Props talldanwp, mamaduka, oandregal. git-svn-id: https://develop.svn.wordpress.org/trunk@52275 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -232,12 +232,16 @@ class WP_REST_Global_Styles_Controller extends WP_REST_Controller {
|
||||
* @return WP_REST_Response $data
|
||||
*/
|
||||
public function prepare_item_for_response( $post, $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
|
||||
$config = json_decode( $post->post_content, true );
|
||||
$is_global_styles_user_theme_json = isset( $config['isGlobalStylesUserThemeJSON'] ) && true === $config['isGlobalStylesUserThemeJSON'];
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$raw_config = json_decode( $post->post_content, true );
|
||||
$is_global_styles_user_theme_json = isset( $raw_config['isGlobalStylesUserThemeJSON'] ) && true === $raw_config['isGlobalStylesUserThemeJSON'];
|
||||
$config = array();
|
||||
if ( $is_global_styles_user_theme_json ) {
|
||||
$config = ( new WP_Theme_JSON( $raw_config, 'custom' ) )->get_raw_data();
|
||||
}
|
||||
|
||||
// Base fields for every post.
|
||||
$data = array();
|
||||
$data = array();
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
|
||||
if ( rest_is_field_included( 'id', $fields ) ) {
|
||||
$data['id'] = $post->ID;
|
||||
|
||||
@@ -72,8 +72,9 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
||||
array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'The id of a template' ),
|
||||
'type' => 'string',
|
||||
'description' => __( 'The id of a template' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => array( $this, '_sanitize_template_id' ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -131,6 +132,39 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requesting this endpoint for a template like 'twentytwentytwo//home'
|
||||
* requires using a path like /wp/v2/templates/twentytwentytwo//home. There
|
||||
* are special cases when WordPress routing corrects the name to contain
|
||||
* only a single slash like 'twentytwentytwo/home'.
|
||||
*
|
||||
* This method doubles the last slash if it's not already doubled. It relies
|
||||
* on the template ID format {theme_name}//{template_slug} and the fact that
|
||||
* slugs cannot contain slashes.
|
||||
*
|
||||
* @since 5.9.0
|
||||
* @see https://core.trac.wordpress.org/ticket/54507
|
||||
*
|
||||
* @param string $id Template ID.
|
||||
* @return string Sanitized template ID.
|
||||
*/
|
||||
public function _sanitize_template_id( $id ) {
|
||||
$last_slash_pos = strrpos( $id, '/' );
|
||||
if ( false === $last_slash_pos ) {
|
||||
return $id;
|
||||
}
|
||||
|
||||
$is_double_slashed = substr( $id, $last_slash_pos - 1, 1 ) === '/';
|
||||
if ( $is_double_slashed ) {
|
||||
return $id;
|
||||
}
|
||||
return (
|
||||
substr( $id, 0, $last_slash_pos )
|
||||
. '/'
|
||||
. substr( $id, $last_slash_pos )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given request has access to read templates.
|
||||
*
|
||||
@@ -244,6 +278,10 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
||||
|
||||
$changes = $this->prepare_item_for_database( $request );
|
||||
|
||||
if ( is_wp_error( $changes ) ) {
|
||||
return $changes;
|
||||
}
|
||||
|
||||
if ( 'custom' === $template->source ) {
|
||||
$result = wp_update_post( wp_slash( (array) $changes ), true );
|
||||
} else {
|
||||
@@ -298,6 +336,11 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
||||
*/
|
||||
public function create_item( $request ) {
|
||||
$prepared_post = $this->prepare_item_for_database( $request );
|
||||
|
||||
if ( is_wp_error( $prepared_post ) ) {
|
||||
return $prepared_post;
|
||||
}
|
||||
|
||||
$prepared_post->post_name = $request['slug'];
|
||||
$post_id = wp_insert_post( wp_slash( (array) $prepared_post ), true );
|
||||
if ( is_wp_error( $post_id ) ) {
|
||||
@@ -430,6 +473,9 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
||||
$changes->tax_input = array(
|
||||
'wp_theme' => $template->theme,
|
||||
);
|
||||
$changes->meta_input = array(
|
||||
'origin' => $template->source,
|
||||
);
|
||||
} else {
|
||||
$changes->post_name = $template->slug;
|
||||
$changes->ID = $template->wp_id;
|
||||
@@ -469,6 +515,24 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $request['author'] ) ) {
|
||||
$post_author = (int) $request['author'];
|
||||
|
||||
if ( get_current_user_id() !== $post_author ) {
|
||||
$user_obj = get_userdata( $post_author );
|
||||
|
||||
if ( ! $user_obj ) {
|
||||
return new WP_Error(
|
||||
'rest_invalid_author',
|
||||
__( 'Invalid author ID.' ),
|
||||
array( 'status' => 400 )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$changes->post_author = $post_author;
|
||||
}
|
||||
|
||||
return $changes;
|
||||
}
|
||||
|
||||
@@ -518,6 +582,10 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
||||
$data['source'] = $template->source;
|
||||
}
|
||||
|
||||
if ( rest_is_field_included( 'origin', $fields ) ) {
|
||||
$data['origin'] = $template->origin;
|
||||
}
|
||||
|
||||
if ( rest_is_field_included( 'type', $fields ) ) {
|
||||
$data['type'] = $template->type;
|
||||
}
|
||||
@@ -555,6 +623,14 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
||||
$data['has_theme_file'] = (bool) $template->has_theme_file;
|
||||
}
|
||||
|
||||
if ( rest_is_field_included( 'is_custom', $fields ) && 'wp_template' === $template->type ) {
|
||||
$data['is_custom'] = $template->is_custom;
|
||||
}
|
||||
|
||||
if ( rest_is_field_included( 'author', $fields ) ) {
|
||||
$data['author'] = (int) $template->author;
|
||||
}
|
||||
|
||||
if ( rest_is_field_included( 'area', $fields ) && 'wp_template_part' === $template->type ) {
|
||||
$data['area'] = $template->area;
|
||||
}
|
||||
@@ -703,6 +779,12 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'origin' => array(
|
||||
'description' => __( 'Source of a customized template' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'content' => array(
|
||||
'description' => __( 'Content of template.' ),
|
||||
'type' => array( 'object', 'string' ),
|
||||
@@ -766,9 +848,23 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'author' => array(
|
||||
'description' => __( 'The ID for the author of the template.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if ( 'wp_template' === $this->post_type ) {
|
||||
$schema['properties']['is_custom'] = array(
|
||||
'description' => __( 'Whether a template is a custom template.' ),
|
||||
'type' => 'bool',
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
);
|
||||
}
|
||||
|
||||
if ( 'wp_template_part' === $this->post_type ) {
|
||||
$schema['properties']['area'] = array(
|
||||
'description' => __( 'Where the template part is intended for use (header, footer, etc.)' ),
|
||||
|
||||
@@ -320,22 +320,8 @@ class WP_REST_Themes_Controller extends WP_REST_Controller {
|
||||
// This creates a record for the current theme if not existent.
|
||||
$id = WP_Theme_JSON_Resolver::get_user_custom_post_type_id();
|
||||
} else {
|
||||
$wp_query_args = array(
|
||||
'post_status' => 'publish',
|
||||
'post_type' => 'wp_global_styles',
|
||||
'posts_per_page' => 1,
|
||||
'no_found_rows' => true,
|
||||
'fields' => 'ids',
|
||||
'tax_query' => array(
|
||||
array(
|
||||
'taxonomy' => 'wp_theme',
|
||||
'field' => 'name',
|
||||
'terms' => $theme->get_stylesheet(),
|
||||
),
|
||||
),
|
||||
);
|
||||
$global_styles_query = new WP_Query( $wp_query_args );
|
||||
$id = ! empty( $global_styles_query->posts ) ? array_shift( $global_styles_query->posts ) : null;
|
||||
$user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_custom_post_type( $theme );
|
||||
$id = isset( $user_cpt['ID'] ) ? $user_cpt['ID'] : null;
|
||||
}
|
||||
|
||||
if ( $id ) {
|
||||
|
||||
Reference in New Issue
Block a user