Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing appareanceTools flags and sort alphabetically #1972

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8f87db5
Add support to post types
talldan Nov 24, 2021
77a5e68
Add author support to templates REST API controller
talldan Nov 24, 2021
bdb04b3
Update unit tests
talldan Nov 24, 2021
0095e94
Fix linting issue
talldan Nov 25, 2021
39e5f91
Add origin field to templates
talldan Nov 25, 2021
11e1a10
Handle errors from `prepare_item_for_database` in REST templates cont…
talldan Nov 25, 2021
8888852
Update tests to support origin
talldan Nov 25, 2021
63d008a
Address review feedback
talldan Nov 25, 2021
51c768e
Linting fix
talldan Nov 25, 2021
89ea62c
Remove empty lines
talldan Nov 29, 2021
0b939f4
Update @wordpress packages
noisysocks Nov 29, 2021
36bbe07
Changes from lib/class-wp-theme-json-gutenberg.php
noisysocks Nov 29, 2021
2f870e0
Changes from lib/class-wp-theme-json-resolver-gutenberg.php
noisysocks Nov 29, 2021
b494b8e
Changes from lib/class-gutenberg-rest-global-styles-controller.php
noisysocks Nov 29, 2021
ac24a4d
Changes from lib/compat/wordpress-5.9/class-gutenberg-rest-templates-…
noisysocks Nov 29, 2021
c693450
Changes from lib/compat/wordpress-5.9/get-global-styles-and-settings.php
noisysocks Nov 29, 2021
2f4b9c0
Changes from lib/compat/wordpress-5.9/rest-active-global-styles.php
noisysocks Nov 29, 2021
a40c236
Changes from lib/full-site-editing/edit-site-page.php
noisysocks Nov 29, 2021
8177764
Changes from lib/global-styles.php
noisysocks Nov 29, 2021
d7bc3a2
Changes from phpunit/class-gutenberg-rest-template-controller-test.php
noisysocks Nov 29, 2021
0f23bca
Changes from phpunit/class-wp-theme-json-resolver-test.php
noisysocks Nov 29, 2021
7771284
Changes from phpunit/class-wp-theme-json-test.php
noisysocks Nov 29, 2021
c0cc27a
Merge remote-tracking branch 'talldan/add/author-support-to-templates…
noisysocks Nov 29, 2021
f8745dc
Move call to maybe_opt_in_into_settings() to right place
noisysocks Nov 29, 2021
fa3f5c7
Use WP class names
noisysocks Nov 29, 2021
9a4ec9f
Fix 'is_custom' assertions in PHPUnit tests
Mamaduka Nov 29, 2021
df9d23f
Update tests/phpunit/tests/rest-api/wpRestTemplatesController.php
noisysocks Nov 29, 2021
cdabd26
Update tests/phpunit/tests/rest-api/wpRestTemplatesController.php
noisysocks Nov 29, 2021
bd3461a
Update tests/phpunit/tests/rest-api/wpRestTemplatesController.php
noisysocks Nov 29, 2021
00ba632
Sort keys alphabetically so it is easier to compare
oandregal Nov 29, 2021
a633c19
Add missing appearanceTools flag
oandregal Nov 29, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
268 changes: 135 additions & 133 deletions package-lock.json

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,53 +82,53 @@
"@wordpress/api-fetch": "5.2.6",
"@wordpress/autop": "3.2.3",
"@wordpress/blob": "3.2.2",
"@wordpress/block-directory": "3.0.11",
"@wordpress/block-editor": "8.0.5",
"@wordpress/block-library": "6.0.9",
"@wordpress/block-directory": "3.0.12",
"@wordpress/block-editor": "8.0.6",
"@wordpress/block-library": "6.0.10",
"@wordpress/block-serialization-default-parser": "4.2.3",
"@wordpress/blocks": "11.1.4",
"@wordpress/components": "19.0.5",
"@wordpress/components": "19.1.0",
"@wordpress/compose": "5.0.6",
"@wordpress/core-data": "4.0.7",
"@wordpress/customize-widgets": "2.0.11",
"@wordpress/core-data": "4.0.8",
"@wordpress/customize-widgets": "2.0.12",
"@wordpress/data": "6.1.4",
"@wordpress/data-controls": "2.2.7",
"@wordpress/date": "4.2.3",
"@wordpress/deprecated": "3.2.3",
"@wordpress/dom": "3.2.7",
"@wordpress/dom-ready": "3.2.3",
"@wordpress/edit-post": "5.0.11",
"@wordpress/edit-site": "3.0.11",
"@wordpress/edit-widgets": "3.1.6",
"@wordpress/editor": "12.0.8",
"@wordpress/edit-post": "5.0.12",
"@wordpress/edit-site": "3.0.12",
"@wordpress/edit-widgets": "3.1.7",
"@wordpress/editor": "12.0.9",
"@wordpress/element": "4.0.4",
"@wordpress/escape-html": "2.2.3",
"@wordpress/format-library": "3.0.11",
"@wordpress/format-library": "3.0.12",
"@wordpress/hooks": "3.2.2",
"@wordpress/html-entities": "3.2.3",
"@wordpress/i18n": "4.2.4",
"@wordpress/icons": "6.1.1",
"@wordpress/interface": "4.1.7",
"@wordpress/interface": "4.1.8",
"@wordpress/is-shallow-equal": "4.2.1",
"@wordpress/keyboard-shortcuts": "3.0.6",
"@wordpress/keycodes": "3.2.4",
"@wordpress/list-reusable-blocks": "3.0.9",
"@wordpress/list-reusable-blocks": "3.0.10",
"@wordpress/media-utils": "3.0.5",
"@wordpress/notices": "3.2.7",
"@wordpress/nux": "5.0.9",
"@wordpress/nux": "5.0.10",
"@wordpress/plugins": "4.0.6",
"@wordpress/primitives": "3.0.4",
"@wordpress/priority-queue": "2.2.3",
"@wordpress/redux-routine": "4.2.2",
"@wordpress/reusable-blocks": "3.0.11",
"@wordpress/reusable-blocks": "3.0.12",
"@wordpress/rich-text": "5.0.6",
"@wordpress/server-side-render": "3.0.9",
"@wordpress/server-side-render": "3.0.10",
"@wordpress/shortcode": "3.2.3",
"@wordpress/token-list": "2.2.2",
"@wordpress/url": "3.3.1",
"@wordpress/viewport": "4.0.6",
"@wordpress/warning": "2.2.2",
"@wordpress/widgets": "2.0.11",
"@wordpress/widgets": "2.0.12",
"@wordpress/wordcount": "3.2.3",
"backbone": "1.4.0",
"clipboard": "2.0.8",
Expand Down
8 changes: 6 additions & 2 deletions src/wp-admin/site-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
wp_die( __( 'The theme you are currently using is not compatible with Full Site Editing.' ) );
}

// Used in the HTML title tag.
$title = __( 'Editor (beta)' );
$parent_file = 'themes.php';

// Flag that we're loading the block editor.
Expand Down Expand Up @@ -59,6 +57,9 @@ static function( $classes ) {
wp_die( __( 'Invalid post type.' ) );
}

// Used in the HTML title tag.
$title = $post_type->labels->name;

$preload_paths = array(
'/',
'/wp/v2/types/' . $post_type->name . '?context=edit',
Expand All @@ -81,6 +82,9 @@ static function( $classes ) {

} else {

// Used in the HTML title tag.
$title = __( 'Editor (beta)' );

$active_global_styles_id = WP_Theme_JSON_Resolver::get_user_custom_post_type_id();
$active_theme = wp_get_theme()->get_stylesheet();
$preload_paths = array(
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/assets/script-loader-packages.php

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/wp-includes/block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,26 +338,26 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex
// These settings may need to be updated based on data coming from theme.json sources.
if ( isset( $editor_settings['__experimentalFeatures']['color']['palette'] ) ) {
$colors_by_origin = $editor_settings['__experimentalFeatures']['color']['palette'];
$editor_settings['colors'] = isset( $colors_by_origin['user'] ) ?
$colors_by_origin['user'] : (
$editor_settings['colors'] = isset( $colors_by_origin['custom'] ) ?
$colors_by_origin['custom'] : (
isset( $colors_by_origin['theme'] ) ?
$colors_by_origin['theme'] :
$colors_by_origin['default']
);
}
if ( isset( $editor_settings['__experimentalFeatures']['color']['gradients'] ) ) {
$gradients_by_origin = $editor_settings['__experimentalFeatures']['color']['gradients'];
$editor_settings['gradients'] = isset( $gradients_by_origin['user'] ) ?
$gradients_by_origin['user'] : (
$editor_settings['gradients'] = isset( $gradients_by_origin['custom'] ) ?
$gradients_by_origin['custom'] : (
isset( $gradients_by_origin['theme'] ) ?
$gradients_by_origin['theme'] :
$gradients_by_origin['default']
);
}
if ( isset( $editor_settings['__experimentalFeatures']['typography']['fontSizes'] ) ) {
$font_sizes_by_origin = $editor_settings['__experimentalFeatures']['typography']['fontSizes'];
$editor_settings['fontSizes'] = isset( $font_sizes_by_origin['user'] ) ?
$font_sizes_by_origin['user'] : (
$editor_settings['fontSizes'] = isset( $font_sizes_by_origin['custom'] ) ?
$font_sizes_by_origin['custom'] : (
isset( $font_sizes_by_origin['theme'] ) ?
$font_sizes_by_origin['theme'] :
$font_sizes_by_origin['default']
Expand Down
4 changes: 4 additions & 0 deletions src/wp-includes/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,19 +525,23 @@ function _build_block_template_result_from_post( $post ) {
$has_theme_file = wp_get_theme()->get_stylesheet() === $theme &&
null !== _get_block_template_file( $post->post_type, $post->post_name );

$origin = get_post_meta( $post->ID, 'origin', true );

$template = new WP_Block_Template();
$template->wp_id = $post->ID;
$template->id = $theme . '//' . $post->post_name;
$template->theme = $theme;
$template->content = $post->post_content;
$template->slug = $post->post_name;
$template->source = 'custom';
$template->origin = ! empty( $origin ) ? $origin : null;
$template->type = $post->post_type;
$template->description = $post->post_excerpt;
$template->title = $post->post_title;
$template->status = $post->post_status;
$template->has_theme_file = $has_theme_file;
$template->is_custom = true;
$template->author = $post->post_author;

if ( 'wp_template' === $post->post_type && isset( $default_template_types[ $template->slug ] ) ) {
$template->is_custom = false;
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/blocks/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function block_core_calendar_has_published_posts() {
}

// On single sites we try our own cached option first.
$has_published_posts = get_option( 'gutenberg_calendar_block_has_published_posts', null );
$has_published_posts = get_option( 'wp_calendar_block_has_published_posts', null );
if ( null !== $has_published_posts ) {
return (bool) $has_published_posts;
}
Expand All @@ -103,7 +103,7 @@ function block_core_calendar_has_published_posts() {
function block_core_calendar_update_has_published_posts() {
global $wpdb;
$has_published_posts = (bool) $wpdb->get_var( "SELECT 1 as test FROM {$wpdb->posts} WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1" );
update_option( 'gutenberg_calendar_block_has_published_posts', $has_published_posts );
update_option( 'wp_calendar_block_has_published_posts', $has_published_posts );
return $has_published_posts;
}

Expand Down
142 changes: 128 additions & 14 deletions src/wp-includes/blocks/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
* Build an array with CSS classes and inline styles defining the colors
* which will be applied to the navigation markup in the front-end.
*
* @param array $attributes Navigation block attributes.
* @param array $attributes Navigation block attributes.
*
* @return array Colors CSS classes and inline styles.
*/
function block_core_navigation_build_css_colors( $attributes ) {
Expand Down Expand Up @@ -99,7 +100,8 @@ function block_core_navigation_build_css_colors( $attributes ) {
* Build an array with CSS classes and inline styles defining the font sizes
* which will be applied to the navigation markup in the front-end.
*
* @param array $attributes Navigation block attributes.
* @param array $attributes Navigation block attributes.
*
* @return array Font size CSS classes and inline styles.
*/
function block_core_navigation_build_css_font_sizes( $attributes ) {
Expand Down Expand Up @@ -132,6 +134,100 @@ function block_core_navigation_render_submenu_icon() {
return '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" role="img" aria-hidden="true" focusable="false"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg>';
}


/**
* Finds the first non-empty `wp_navigation` Post.
*
* @return WP_Post|null the first non-empty Navigation or null.
*/
function block_core_navigation_get_first_non_empty_navigation() {
// Order and orderby args set to mirror those in `wp_get_nav_menus`
// see:
// - https://github.com/WordPress/wordpress-develop/blob/ba943e113d3b31b121f77a2d30aebe14b047c69d/src/wp-includes/nav-menu.php#L613-L619.
// - https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters.
$navigation_posts = get_posts(
array(
'post_type' => 'wp_navigation',
'order' => 'ASC',
'orderby' => 'name',
'posts_per_page' => 1, // only the first post.
's' => '<!-- wp:', // look for block indicators to ensure we only include non-empty Navigations.
)
);
return count( $navigation_posts ) ? $navigation_posts[0] : null;

}

/**
* Filter out empty "null" blocks from the block list.
* 'parse_blocks' includes a null block with '\n\n' as the content when
* it encounters whitespace. This is not a bug but rather how the parser
* is designed.
*
* @param array $parsed_blocks the parsed blocks to be normalized.
* @return array the normalized parsed blocks.
*/
function block_core_navigation_filter_out_empty_blocks( $parsed_blocks ) {
$filtered = array_filter(
$parsed_blocks,
function( $block ) {
return isset( $block['blockName'] );
}
);

// Reset keys.
return array_values( $filtered );
}

/**
* Retrieves the appropriate fallback to be used on the front of the
* site when there is no menu assigned to the Nav block.
*
* This aims to mirror how the fallback mechanic for wp_nav_menu works.
* See https://developer.wordpress.org/reference/functions/wp_nav_menu/#more-information.
*
* @return array the array of blocks to be used as a fallback.
*/
function block_core_navigation_get_fallback_blocks() {
$page_list_fallback = array(
array(
'blockName' => 'core/page-list',
'attrs' => array(
'__unstableMaxPages' => 4,
),
),
);

$registry = WP_Block_Type_Registry::get_instance();

// If `core/page-list` is not registered then return empty blocks.
$fallback_blocks = $registry->is_registered( 'core/page-list' ) ? $page_list_fallback : array();

// Default to a list of Pages.

$navigation_post = block_core_navigation_get_first_non_empty_navigation();

// Prefer using the first non-empty Navigation as fallback if available.
if ( $navigation_post ) {
$maybe_fallback = block_core_navigation_filter_out_empty_blocks( parse_blocks( $navigation_post->post_content ) );

// Normalizing blocks may result in an empty array of blocks if they were all `null` blocks.
// In this case default to the (Page List) fallback.
$fallback_blocks = ! empty( $maybe_fallback ) ? $maybe_fallback : $fallback_blocks;
}

/**
* Filters the fallback experience for the Navigation block.
*
* Returning a falsey value will opt out of the fallback and cause the block not to render.
* To customise the blocks provided return an array of blocks - these should be valid
* children of the `core/navigation` block.
*
* @param array[] default fallback blocks provided by the default block mechanic.
*/
return apply_filters( 'block_core_navigation_render_fallback', $fallback_blocks );
}

/**
* Renders the `core/navigation` block on server.
*
Expand All @@ -142,6 +238,11 @@ function block_core_navigation_render_submenu_icon() {
* @return string Returns the post content with the legacy widget added.
*/
function render_block_core_navigation( $attributes, $content, $block ) {

// Flag used to indicate whether the rendered output is considered to be
// a fallback (i.e. the block has no menu associated with it).
$is_fallback = false;

/**
* Deprecated:
* The rgbTextColor and rgbBackgroundColor attributes
Expand Down Expand Up @@ -187,13 +288,17 @@ function render_block_core_navigation( $attributes, $content, $block ) {
$area = $block->context['navigationArea'];
$mapping = get_option( 'wp_navigation_areas', array() );
if ( ! empty( $mapping[ $area ] ) ) {
$attributes['navigationMenuId'] = $mapping[ $area ];
$attributes['ref'] = $mapping[ $area ];
}
}

// Load inner blocks from the navigation post.
// Ensure that blocks saved with the legacy ref attribute name (navigationMenuId) continue to render.
if ( array_key_exists( 'navigationMenuId', $attributes ) ) {
$navigation_post = get_post( $attributes['navigationMenuId'] );
$attributes['ref'] = $attributes['navigationMenuId'];
}
// Load inner blocks from the navigation post.
if ( array_key_exists( 'ref', $attributes ) ) {
$navigation_post = get_post( $attributes['ref'] );
if ( ! isset( $navigation_post ) ) {
return '';
}
Expand All @@ -202,20 +307,26 @@ function render_block_core_navigation( $attributes, $content, $block ) {

// 'parse_blocks' includes a null block with '\n\n' as the content when
// it encounters whitespace. This code strips it.
$compacted_blocks = array_filter(
$parsed_blocks,
function( $block ) {
return isset( $block['blockName'] );
}
);
$compacted_blocks = block_core_navigation_filter_out_empty_blocks( $parsed_blocks );

// TODO - this uses the full navigation block attributes for the
// context which could be refined.
$inner_blocks = new WP_Block_List( $compacted_blocks, $attributes );
}

// If there are no inner blocks then fallback to rendering an appropriate fallback.
if ( empty( $inner_blocks ) ) {
return '';
$is_fallback = true; // indicate we are rendering the fallback.

$fallback_blocks = block_core_navigation_get_fallback_blocks();

// Fallback my have been filtered so do basic test for validity.
if ( empty( $fallback_blocks ) || ! is_array( $fallback_blocks ) ) {
return '';
}

$inner_blocks = new WP_Block_List( $fallback_blocks, $attributes );

}

// Restore legacy classnames for submenu positioning.
Expand All @@ -234,7 +345,8 @@ function( $block ) {
$colors['css_classes'],
$font_sizes['css_classes'],
$is_responsive_menu ? array( 'is-responsive' ) : array(),
$layout_class ? array( $layout_class ) : array()
$layout_class ? array( $layout_class ) : array(),
$is_fallback ? array( 'is-fallback' ) : array()
);

$inner_blocks_html = '';
Expand Down Expand Up @@ -323,8 +435,8 @@ function( $block ) {
/**
* Register the navigation block.
*
* @uses render_block_core_navigation()
* @throws WP_Error An WP_Error exception parsing the block definition.
* @uses render_block_core_navigation()
*/
function register_block_core_navigation() {
register_block_type_from_metadata(
Expand All @@ -341,6 +453,7 @@ function register_block_core_navigation() {
* Filter that changes the parsed attribute values of navigation blocks contain typographic presets to contain the values directly.
*
* @param array $parsed_block The block being rendered.
*
* @return array The block being rendered without typographic presets.
*/
function block_core_navigation_typographic_presets_backcompatibility( $parsed_block ) {
Expand All @@ -364,6 +477,7 @@ function block_core_navigation_typographic_presets_backcompatibility( $parsed_bl
}
}
}

return $parsed_block;
}

Expand Down
Loading