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

Query loop / Post template: Enable post format filter #64167

Merged
merged 65 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
1bbceed
Enable post format filter in the query loop
carolinan Aug 1, 2024
d12d992
try to fix CS issues
carolinan Aug 1, 2024
e803527
how about this cs fix then?
carolinan Aug 1, 2024
ada8db4
Create a new option for post formats
carolinan Aug 2, 2024
63883ac
Update the control to use the post format theme support
carolinan Aug 5, 2024
800ee24
Post template preview: Get the ID of the post format to use in the qu…
carolinan Aug 5, 2024
ac44e6f
Filter the query loop vars to support post formats on the front.
carolinan Aug 6, 2024
63bad0f
Remove the post type from PostFormatControls
carolinan Aug 6, 2024
6f6e3e8
PHPCS fixes
carolinan Aug 6, 2024
d5ad75b
Merge branch 'trunk' into try/post-format-query
carolinan Aug 12, 2024
7482122
Update the condition for when then post format control should show
carolinan Aug 13, 2024
d3fa212
WIP: Try to add format to the REST API posts controller through a cus…
carolinan Aug 13, 2024
ca718ef
Merge branch 'trunk' into try/post-format-query
carolinan Aug 13, 2024
4ab896c
Update since
carolinan Aug 13, 2024
367f6c1
Regenerate the fixture for the query loop, including postFormat.
carolinan Aug 13, 2024
2f6e716
Revert removing the post formats from TaxonomyControls
carolinan Aug 13, 2024
def06f2
Update class-gutenberg-rest-posts-controller-6-7.php
carolinan Aug 13, 2024
8d87706
Combine the post format with the tax_query array instead of replacing…
carolinan Aug 13, 2024
7a989f9
WIP: comment out breaking code to allow testing.
carolinan Aug 13, 2024
976bb04
Merge branch 'trunk' into try/post-format-query
carolinan Aug 22, 2024
7008f76
edit.js: Don't convert the post format to a string
carolinan Aug 22, 2024
7c6ac16
Update edit.js
carolinan Aug 22, 2024
5154069
Simplify the format array in get_item_schema
carolinan Aug 22, 2024
c09d093
Remove the changes to get_collection_params()
carolinan Aug 22, 2024
713786e
Allow filtering for the standard post format
carolinan Aug 22, 2024
c7d7c88
Filter register_post_type_args instead of using rest_api_init
carolinan Aug 22, 2024
96b408b
Merge branch 'trunk' into try/post-format-query
carolinan Aug 27, 2024
c13e920
Rename "postFormat" parameter to "format"
carolinan Aug 27, 2024
bf67232
Merge branch 'trunk' into try/post-format-query
carolinan Aug 29, 2024
a1a561b
Add format to get_collection_params()
carolinan Aug 29, 2024
b87d25c
Update lib/compat/wordpress-6.7/class-gutenberg-rest-posts-controller…
carolinan Aug 29, 2024
4786c24
Update class-gutenberg-rest-posts-controller-6-7.php
carolinan Aug 29, 2024
c41fbbb
Merge branch 'try/post-format-query' of https://github.com/WordPress/…
carolinan Aug 29, 2024
78470b0
PHPCS: remove white space
carolinan Aug 29, 2024
8f32caf
Remove get_item_schema()
carolinan Aug 29, 2024
deab94c
Update the logic for the standard post format in gutenberg_filter_qu…
carolinan Aug 29, 2024
c4d9e1d
Replace SelectControl with FormTokenField
carolinan Aug 30, 2024
f2f9045
Merge branch 'trunk' into try/post-format-query
carolinan Aug 31, 2024
e2b82d3
Set the constant format to an empty array when format is not queried
carolinan Aug 31, 2024
5739bf3
Hide the control and reset the format value if the post type does not…
carolinan Sep 1, 2024
90fbdd9
Rename postFormatSupportMap to postTypeFormatSupportMap
carolinan Sep 1, 2024
1573c10
Merge branch 'trunk' into try/post-format-query
carolinan Sep 1, 2024
33119d7
Merge branch 'trunk' into try/post-format-query
carolinan Sep 3, 2024
a1017ef
Fix REST API controller override condition
Mamaduka Sep 4, 2024
601644f
Don't set the default post format in the schema
Mamaduka Sep 4, 2024
8eab071
Satisfy PHP linter
Mamaduka Sep 4, 2024
8121870
Update the 'FormatsControl' to match suggestion labels to their stati…
Mamaduka Sep 4, 2024
1b291ed
Refactor showFormatControl logic
Mamaduka Sep 4, 2024
d31086d
Merge branch 'trunk' into try/post-format-query
carolinan Sep 5, 2024
e798f3b
gutenberg_filter_query_loop_block_query_vars_post_format: Switch to u…
carolinan Sep 5, 2024
664b745
Update lib/compat/wordpress-6.7/post-formats.php
carolinan Sep 5, 2024
812c372
End the comment with a full stop.
carolinan Sep 5, 2024
2e7e901
Merge branch 'trunk' into try/post-format-query
carolinan Sep 9, 2024
ce0583b
Update doc blocks and replace aray_diff with unset and array_search.
carolinan Sep 9, 2024
83d02bc
Update doc block
carolinan Sep 9, 2024
9cbe2ad
Add backport changelog
carolinan Sep 9, 2024
4b46ea2
Oops: Fix the copy-paste typo in the changelog entry.
carolinan Sep 9, 2024
d98fbaa
Update lib/compat/wordpress-6.7/class-gutenberg-rest-posts-controller…
carolinan Sep 10, 2024
9514a05
Rename gutenberg_filter_query_loop_block_query_vars_post_format to gu…
carolinan Sep 10, 2024
a702271
Gutenberg_REST_Posts_Controller_6_7 get_items: remove the array conve…
carolinan Sep 10, 2024
4df4639
Add two checks that help fail gracefully when errors occur
carolinan Sep 11, 2024
25ceeec
Update the docBlock for gutenberg_add_format_query_vars_to_query_loop…
carolinan Sep 11, 2024
a85a919
FormatControls: simplify array conversion
carolinan Sep 11, 2024
f182af0
Merge branch 'trunk' into try/post-format-query
carolinan Sep 13, 2024
8031da7
Merge branch 'trunk' into try/post-format-query
carolinan Sep 16, 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
3 changes: 3 additions & 0 deletions backport-changelog/6.7/7314.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/7314

* https://github.com/WordPress/gutenberg/pull/64167
60 changes: 60 additions & 0 deletions lib/compat/wordpress-6.7/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,63 @@ function gutenberg_filter_block_type_metadata_settings_allow_variations_php_file
return $settings;
}
add_filter( 'block_type_metadata_settings', 'gutenberg_filter_block_type_metadata_settings_allow_variations_php_file', 10, 2 );

/**
* Adds post format query vars to the query loop block's WP_Query when the block's attributes call for them.
*
* @see query_loop_block_query_vars
carolinan marked this conversation as resolved.
Show resolved Hide resolved
*
* @param array $query The query vars.
* @param WP_Block $block Block instance.
* @return array The filtered query vars.
*/
function gutenberg_add_format_query_vars_to_query_loop_block( $query, $block ) {
// Return early if there is no format or if the format is not an array.
if ( empty( $block->context['query']['format'] ) || ! is_array( $block->context['query']['format'] ) ) {
return $query;
}

$formats = $block->context['query']['format'];
$tax_query = array( 'relation' => 'OR' );

// The default post format, 'standard', is not stored in the database.
// If 'standard' is part of the request, the query needs to exclude all post items that
// have a format assigned.
if ( in_array( 'standard', $formats, true ) ) {
$tax_query[] = array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array(),
'operator' => 'NOT EXISTS',
);
// Remove the standard format, since it cannot be queried.
unset( $formats[ array_search( 'standard', $formats, true ) ] );
}

// Add any remaining formats to the tax query.
if ( ! empty( $formats ) ) {
// Add the post-format- prefix.
$terms = array_map(
static function ( $format ) {
return 'post-format-' . $format;
},
$formats
);

$tax_query[] = array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => $terms,
'operator' => 'IN',
);
}

// This condition is intended to prevent $tax_query from being added to $query
// if it only contains the relation.
if ( count( $tax_query ) > 1 ) {
$query['tax_query'][] = $tax_query;
}
carolinan marked this conversation as resolved.
Show resolved Hide resolved

return $query;
}
add_filter( 'query_loop_block_query_vars', 'gutenberg_add_format_query_vars_to_query_loop_block', 10, 2 );
Loading
Loading