mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Editor: Update WordPress packages published for Gutenberg 10.6
It contains several changes in addition to regular update to WordPress packages: - All newly exposed blocks are now registered on the server. - Dutone block support was added. - Border block support was updated. - New shared function `construct_wp_query_args` was added for the family of Query blocks - it might need some further work. Props youknowriad. See #52991. git-svn-id: https://develop.svn.wordpress.org/trunk@50929 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -961,3 +961,65 @@ function block_has_support( $block_type, $feature, $default = false ) {
|
||||
|
||||
return true === $block_support || is_array( $block_support );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that constructs a WP_Query args array from
|
||||
* a `Query` block properties.
|
||||
*
|
||||
* It's used in Query Loop, Query Pagination Numbers and Query Pagination Next blocks.
|
||||
*
|
||||
* @since 5.8.0
|
||||
*
|
||||
* @param WP_Block $block Block instance.
|
||||
* @param int $page Current query's page.
|
||||
*
|
||||
* @return array Returns the constructed WP_Query arguments.
|
||||
*/
|
||||
function construct_wp_query_args( $block, $page ) {
|
||||
$query = array(
|
||||
'post_type' => 'post',
|
||||
'order' => 'DESC',
|
||||
'orderby' => 'date',
|
||||
'post__not_in' => array(),
|
||||
);
|
||||
|
||||
if ( isset( $block->context['query'] ) ) {
|
||||
if ( isset( $block->context['query']['postType'] ) ) {
|
||||
$query['post_type'] = $block->context['query']['postType'];
|
||||
}
|
||||
if ( isset( $block->context['query']['sticky'] ) && ! empty( $block->context['query']['sticky'] ) ) {
|
||||
$sticky = get_option( 'sticky_posts' );
|
||||
if ( 'only' === $block->context['query']['sticky'] ) {
|
||||
$query['post__in'] = $sticky;
|
||||
} else {
|
||||
$query['post__not_in'] = array_merge( $query['post__not_in'], $sticky );
|
||||
}
|
||||
}
|
||||
if ( isset( $block->context['query']['exclude'] ) ) {
|
||||
$query['post__not_in'] = array_merge( $query['post__not_in'], $block->context['query']['exclude'] );
|
||||
}
|
||||
if ( isset( $block->context['query']['perPage'] ) ) {
|
||||
$query['offset'] = ( $block->context['query']['perPage'] * ( $page - 1 ) ) + $block->context['query']['offset'];
|
||||
$query['posts_per_page'] = $block->context['query']['perPage'];
|
||||
}
|
||||
if ( isset( $block->context['query']['categoryIds'] ) ) {
|
||||
$query['category__in'] = $block->context['query']['categoryIds'];
|
||||
}
|
||||
if ( isset( $block->context['query']['tagIds'] ) ) {
|
||||
$query['tag__in'] = $block->context['query']['tagIds'];
|
||||
}
|
||||
if ( isset( $block->context['query']['order'] ) ) {
|
||||
$query['order'] = strtoupper( $block->context['query']['order'] );
|
||||
}
|
||||
if ( isset( $block->context['query']['orderBy'] ) ) {
|
||||
$query['orderby'] = $block->context['query']['orderBy'];
|
||||
}
|
||||
if ( isset( $block->context['query']['author'] ) ) {
|
||||
$query['author'] = $block->context['query']['author'];
|
||||
}
|
||||
if ( isset( $block->context['query']['search'] ) ) {
|
||||
$query['s'] = $block->context['query']['search'];
|
||||
}
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user