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

Limit block supports flag support to v2 #26106

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion lib/block-supports/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function gutenberg_apply_block_supports( $block_content, $block ) {

$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
// If no render_callback, assume styles have been previously handled.
if ( ! $block_type || ! $block_type->render_callback ) {
if ( ! $block_type || ! property_exists( $block_type, 'api_version' ) || $block_type->api_version < 2 || ! $block_type->render_callback ) {
return $block_content;
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/block-library/src/archives/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ function register_block_core_archives() {
register_block_type_from_metadata(
__DIR__ . '/archives',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_archives',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/calendar/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function register_block_core_calendar() {
register_block_type_from_metadata(
__DIR__ . '/calendar',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_calendar',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/categories/block.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"apiVersion": 2,
"name": "core/categories",
"category": "widgets",
"attributes": {
Expand Down
15 changes: 9 additions & 6 deletions packages/block-library/src/categories/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import {
} from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
import { InspectorControls } from '@wordpress/block-editor';
import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { pin } from '@wordpress/icons';

export default function CategoriesEdit( {
attributes: { displayAsDropdown, showHierarchy, showPostCounts },
className,
setAttributes,
} ) {
const blockProps = useBlockProps();
const selectId = useInstanceId( CategoriesEdit, 'blocks-category-select' );
const { categories, isRequesting } = useSelect( ( select ) => {
const { getEntityRecords } = select( 'core' );
Expand Down Expand Up @@ -150,16 +150,19 @@ export default function CategoriesEdit( {
return (
<>
{ inspectorControls }
<Placeholder icon={ pin } label={ __( 'Categories' ) }>
<Spinner />
</Placeholder>
<div { ...blockProps }>
<Placeholder icon={ pin } label={ __( 'Categories' ) }>
<Spinner />
</Placeholder>
</div>
</>
);
}

return (
<>
{ inspectorControls }
<div className={ className }>
<div { ...blockProps }>
{ displayAsDropdown
? renderCategoryDropdown()
: renderCategoryList() }
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/categories/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function register_block_core_categories() {
register_block_type_from_metadata(
__DIR__ . '/categories',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_categories',
)
);
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/cover/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
/**
* Supports `playsinline` attribute server side for `core/cover`.
*
* @todo Remove this file once we bump the minimum supported version to WordPress 5.5.
*
* @param array $attributes The block attributes.
* @param string $content HTML content of the block.
*
Expand All @@ -28,6 +30,7 @@ function register_block_core_cover() {
register_block_type_from_metadata(
__DIR__ . '/cover',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_cover',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/latest-comments/block.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"apiVersion": 2,
"name": "core/latest-comments",
"category": "widgets",
"attributes": {
Expand Down
17 changes: 10 additions & 7 deletions packages/block-library/src/latest-comments/edit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { InspectorControls } from '@wordpress/block-editor';
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
import {
Disabled,
PanelBody,
Expand Down Expand Up @@ -31,6 +31,7 @@ export default function LatestComments( { attributes, setAttributes } ) {
displayDate,
displayExcerpt,
} = attributes;
const blockProps = useBlockProps();

return (
<>
Expand Down Expand Up @@ -71,12 +72,14 @@ export default function LatestComments( { attributes, setAttributes } ) {
/>
</PanelBody>
</InspectorControls>
<Disabled>
<ServerSideRender
block="core/latest-comments"
attributes={ attributes }
/>
</Disabled>
<div { ...blockProps }>
<Disabled>
<ServerSideRender
block="core/latest-comments"
attributes={ attributes }
/>
</Disabled>
</div>
</>
);
}
1 change: 1 addition & 0 deletions packages/block-library/src/latest-comments/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ function register_block_core_latest_comments() {
register_block_type_from_metadata(
__DIR__ . '/latest-comments',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_latest_comments',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/latest-posts/block.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"apiVersion": 2,
"name": "core/latest-posts",
"category": "widgets",
"attributes": {
Expand Down
13 changes: 12 additions & 1 deletion packages/block-library/src/latest-posts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
BlockAlignmentToolbar,
BlockControls,
__experimentalImageSizeControl as ImageSizeControl,
useBlockProps,
} from '@wordpress/block-editor';
import { withSelect } from '@wordpress/data';
import { pin, list, grid } from '@wordpress/icons';
Expand Down Expand Up @@ -522,6 +523,16 @@ class LatestPostsEdit extends Component {
}
}

function LatestPostBlockWrapper( props ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we refactor the whole block to be a functional component, but this is better done on a separate PR. This should be enough for the moment.

const blockProps = useBlockProps();

return (
<div { ...blockProps }>
<LatestPostsEdit { ...props } />
</div>
);
}

export default withSelect( ( select, props ) => {
const {
featuredImageSizeSlug,
Expand Down Expand Up @@ -593,4 +604,4 @@ export default withSelect( ( select, props ) => {
return { ...post, featuredImageInfo };
} ),
};
} )( LatestPostsEdit );
} )( LatestPostBlockWrapper );
1 change: 1 addition & 0 deletions packages/block-library/src/latest-posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ function register_block_core_latest_posts() {
register_block_type_from_metadata(
__DIR__ . '/latest-posts',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_latest_posts',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ function register_block_core_navigation_link() {
register_block_type_from_metadata(
__DIR__ . '/navigation-link',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_navigation_link',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ function register_block_core_navigation() {
register_block_type_from_metadata(
__DIR__ . '/navigation',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_navigation',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/post-author/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function register_block_core_post_author() {
register_block_type_from_metadata(
__DIR__ . '/post-author',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_post_author',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/post-comment-author/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function register_block_core_post_comment_author() {
register_block_type_from_metadata(
__DIR__ . '/post-comment-author',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_post_comment_author',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/post-comment-content/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function register_block_core_post_comment_content() {
register_block_type_from_metadata(
__DIR__ . '/post-comment-content',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_post_comment_content',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/post-comment-date/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function register_block_core_post_comment_date() {
register_block_type_from_metadata(
__DIR__ . '/post-comment-date',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_post_comment_date',
)
);
Expand Down
5 changes: 4 additions & 1 deletion packages/block-library/src/post-comment/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
*/
function register_block_core_post_comment() {
register_block_type_from_metadata(
__DIR__ . '/post-comment'
__DIR__ . '/post-comment',
array(
'api_version' => 2,
)
);
}
add_action( 'init', 'register_block_core_post_comment' );
1 change: 1 addition & 0 deletions packages/block-library/src/post-comments-count/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function register_block_core_post_comments_count() {
register_block_type_from_metadata(
__DIR__ . '/post-comments-count',
array(
'api_version' => 2,
'attributes' => array(
'className' => array(
'type' => 'string',
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/post-comments-form/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function register_block_core_post_comments_form() {
register_block_type_from_metadata(
__DIR__ . '/post-comments-form',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_post_comments_form',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/post-comments/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function register_block_core_post_comments() {
register_block_type_from_metadata(
__DIR__ . '/post-comments',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_post_comments',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/post-content/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function register_block_core_post_content() {
register_block_type_from_metadata(
__DIR__ . '/post-content',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_post_content',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/post-date/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function register_block_core_post_date() {
register_block_type_from_metadata(
__DIR__ . '/post-date',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_post_date',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/post-excerpt/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function register_block_core_post_excerpt() {
register_block_type_from_metadata(
__DIR__ . '/post-excerpt',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_post_excerpt',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/post-featured-image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function register_block_core_post_featured_image() {
register_block_type_from_metadata(
__DIR__ . '/post-featured-image',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_post_featured_image',
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function register_block_core_post_hierarchical_terms() {
register_block_type_from_metadata(
__DIR__ . '/post-hierarchical-terms',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_post_hierarchical_terms',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/post-tags/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function register_block_core_post_tags() {
register_block_type_from_metadata(
__DIR__ . '/post-tags',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_post_tags',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/post-title/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function register_block_core_post_title() {
register_block_type_from_metadata(
__DIR__ . '/post-title',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_post_title',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/query-loop/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function register_block_core_query_loop() {
register_block_type_from_metadata(
__DIR__ . '/query-loop',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_query_loop',
'skip_inner_blocks' => true,
)
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/query-pagination/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function register_block_core_query_pagination() {
register_block_type_from_metadata(
__DIR__ . '/query-pagination',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_query_pagination',
)
);
Expand Down
5 changes: 4 additions & 1 deletion packages/block-library/src/query/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
*/
function register_block_core_query() {
register_block_type_from_metadata(
__DIR__ . '/query'
__DIR__ . '/query',
array(
'api_version' => 2,
)
);
}
add_action( 'init', 'register_block_core_query' );
1 change: 1 addition & 0 deletions packages/block-library/src/rss/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function register_block_core_rss() {
register_block_type_from_metadata(
__DIR__ . '/rss',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_rss',
)
);
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/search/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function register_block_core_search() {
register_block_type_from_metadata(
__DIR__ . '/search',
array(
'api_version' => 2,
'render_callback' => 'render_block_core_search',
)
);
Expand Down
Loading