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

Remove building wp_template_parts variation call for frontend #5718

Closed
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7a95c4f
remove varation
kt-12 Nov 29, 2023
70fb7aa
introduce get all variation
kt-12 Dec 1, 2023
a41c600
cs fixes
kt-12 Dec 1, 2023
04de489
cs fixes
kt-12 Dec 1, 2023
9146a55
filter to callback
kt-12 Dec 5, 2023
d495db0
Add Variation to block-types rest api
kt-12 Dec 7, 2023
3f8b154
navigation link and post term to block varation to callback
kt-12 Dec 7, 2023
d382bb9
Update src/wp-includes/class-wp-block-type.php
kt-12 Dec 7, 2023
26baa27
Merge branch 'enhancement/remove-variation-fontend' of https://github…
kt-12 Dec 7, 2023
cc598f2
doc block
kt-12 Dec 7, 2023
c174980
dock block
kt-12 Dec 7, 2023
8ad9728
phpcs fixes
kt-12 Dec 7, 2023
d9dabaa
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
kt-12 Dec 7, 2023
e8ebb6f
Update src/wp-includes/class-wp-block-type.php
kt-12 Dec 11, 2023
9d5812d
Making name consistant
kt-12 Dec 11, 2023
6a4433d
Merge branch 'enhancement/remove-variation-fontend' of https://github…
kt-12 Dec 11, 2023
5c3ad2c
callback support with backward compatibility
kt-12 Jan 5, 2024
b1d3664
Allow setting of value. Doc block for variation callback
kt-12 Jan 5, 2024
9c475a9
variations set to null initially
kt-12 Jan 8, 2024
3cb7d40
isset logic
kt-12 Jan 9, 2024
0351ae6
test cases for variation callback
kt-12 Jan 10, 2024
5480c0f
remove isset as variations will never be returned as null.
kt-12 Jan 10, 2024
a68e5e0
isset always true for variations
kt-12 Jan 10, 2024
cd38417
revert back navigation-link to
kt-12 Jan 16, 2024
b604464
revert back to trunk
kt-12 Jan 16, 2024
93e4457
Merge branch 'trunk' into enhancement/remove-variation-fontend
kt-12 Jan 16, 2024
39ee3ee
set to null
kt-12 Jan 17, 2024
34bcc84
test cases for multiple cases
kt-12 Jan 18, 2024
94aa0fe
additional test cases
kt-12 Jan 18, 2024
bae4e71
change message
kt-12 Jan 18, 2024
2918539
cs fixes
kt-12 Jan 18, 2024
686c243
Update tests/phpunit/tests/blocks/wpBlockType.php
kt-12 Jan 18, 2024
689d48c
Update tests/phpunit/tests/blocks/wpBlockType.php
kt-12 Jan 18, 2024
aafceda
Move filter function one up
kt-12 Jan 19, 2024
b0730c7
remove filters and expand doc block defnetion
kt-12 Jan 19, 2024
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
5 changes: 5 additions & 0 deletions src/wp-admin/includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -2317,6 +2317,11 @@ function get_block_editor_server_block_settings() {

$blocks[ $block_name ][ $key ] = $block_type->{ $field };
}

// If the block has a variations callback, call it and add the variations to the block.
if ( is_callable( $block_type->variations ) ) {
$blocks[ $block_name ]['variations'] = call_user_func( $block_type->variations );
}
}

return $blocks;
Expand Down
18 changes: 13 additions & 5 deletions src/wp-includes/blocks/navigation-link.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,11 @@ function build_variation_for_navigation_link( $entity, $kind ) {
}

/**
* Register the navigation link block.
* Returns an array of variations for the navigation link block.
*
* @uses render_block_core_navigation()
* @throws WP_Error An WP_Error exception parsing the block definition.
* @return array
*/
function register_block_core_navigation_link() {
function build_navigation_link_block_variations() {
joemcgill marked this conversation as resolved.
Show resolved Hide resolved
$post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' );
$taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'objects' );

Expand Down Expand Up @@ -359,12 +358,21 @@ function register_block_core_navigation_link() {
}
}
}
return array_merge( $built_ins, $variations );
}

/**
* Register the navigation link block.
*
* @uses render_block_core_navigation()
* @throws WP_Error An WP_Error exception parsing the block definition.
*/
function register_block_core_navigation_link() {
register_block_type_from_metadata(
__DIR__ . '/navigation-link',
array(
'render_callback' => 'render_block_core_navigation_link',
'variations' => array_merge( $built_ins, $variations ),
'variations' => 'build_navigation_link_block_variations',
)
);
}
Expand Down
14 changes: 11 additions & 3 deletions src/wp-includes/blocks/post-terms.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ function render_block_core_post_terms( $attributes, $content, $block ) {
}

/**
* Registers the `core/post-terms` block on the server.
* Returns the available variations for the `core/post-terms` block.
*
* @return array The available variations for the block.
*/
function register_block_core_post_terms() {
function build_post_term_block_variations() {
$taxonomies = get_taxonomies(
array(
'publicly_queryable' => true,
Expand Down Expand Up @@ -102,12 +104,18 @@ function register_block_core_post_terms() {
$custom_variations[] = $variation;
}
}
return array_merge( $built_ins, $custom_variations );
}

/**
* Registers the `core/post-terms` block on the server.
*/
function register_block_core_post_terms() {
register_block_type_from_metadata(
__DIR__ . '/post-terms',
array(
'render_callback' => 'render_block_core_post_terms',
'variations' => array_merge( $built_ins, $custom_variations ),
'variations' => 'build_post_term_block_variations',
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/blocks/template-part.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ function register_block_core_template_part() {
__DIR__ . '/template-part',
array(
'render_callback' => 'render_block_core_template_part',
'variations' => build_template_part_block_variations(),
'variations' => 'build_template_part_block_variations',
Copy link
Member

Choose a reason for hiding this comment

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

I think it's okay to have these changes here for now and remove them before merging into the core. Then, we can update the code in the block-library package in a backward compatible way. The Gutenberg plugin supports multiple WP versions.

)
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/wp-includes/class-wp-block-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ class WP_Block_Type {
* Block variations.
*
* @since 5.8.0
* @var array[]
* @since 6.5.0 Added callback support.
* @var callable|array[]
kt-12 marked this conversation as resolved.
Show resolved Hide resolved
*/
public $variations = array();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ public function prepare_item_for_response( $item, $request ) {
'view_script_handles',
'editor_style_handles',
'style_handles',
'variations',
'block_hooks',
),
$deprecated_fields
Expand All @@ -314,6 +313,14 @@ public function prepare_item_for_response( $item, $request ) {
}
}

if ( rest_is_field_included( 'variations', $fields ) ) {
$field = $block_type->variations;
if ( is_callable( $block_type->variations ) ) {
$field = call_user_func( $block_type->variations );
}
$data['variations'] = rest_sanitize_value_from_schema( $field, $schema['properties']['variations'] );
}
joemcgill marked this conversation as resolved.
Show resolved Hide resolved

if ( rest_is_field_included( 'styles', $fields ) ) {
$styles = $this->style_registry->get_registered_styles_for_block( $block_type->name );
$styles = array_values( $styles );
Expand Down
Loading