Make WordPress Core


Ignore:
Timestamp:
05/19/2021 03:07:55 PM (3 years ago)
Author:
gziolo
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r50928 r50929  
    962962    return true === $block_support || is_array( $block_support );
    963963}
     964
     965/**
     966 * Helper function that constructs a WP_Query args array from
     967 * a `Query` block properties.
     968 *
     969 * It's used in Query Loop, Query Pagination Numbers and Query Pagination Next blocks.
     970 *
     971 * @since 5.8.0
     972 *
     973 * @param WP_Block $block Block instance.
     974 * @param int      $page  Current query's page.
     975 *
     976 * @return array Returns the constructed WP_Query arguments.
     977 */
     978function construct_wp_query_args( $block, $page ) {
     979    $query = array(
     980        'post_type'    => 'post',
     981        'order'        => 'DESC',
     982        'orderby'      => 'date',
     983        'post__not_in' => array(),
     984    );
     985
     986    if ( isset( $block->context['query'] ) ) {
     987        if ( isset( $block->context['query']['postType'] ) ) {
     988            $query['post_type'] = $block->context['query']['postType'];
     989        }
     990        if ( isset( $block->context['query']['sticky'] ) && ! empty( $block->context['query']['sticky'] ) ) {
     991            $sticky = get_option( 'sticky_posts' );
     992            if ( 'only' === $block->context['query']['sticky'] ) {
     993                $query['post__in'] = $sticky;
     994            } else {
     995                $query['post__not_in'] = array_merge( $query['post__not_in'], $sticky );
     996            }
     997        }
     998        if ( isset( $block->context['query']['exclude'] ) ) {
     999            $query['post__not_in'] = array_merge( $query['post__not_in'], $block->context['query']['exclude'] );
     1000        }
     1001        if ( isset( $block->context['query']['perPage'] ) ) {
     1002            $query['offset']         = ( $block->context['query']['perPage'] * ( $page - 1 ) ) + $block->context['query']['offset'];
     1003            $query['posts_per_page'] = $block->context['query']['perPage'];
     1004        }
     1005        if ( isset( $block->context['query']['categoryIds'] ) ) {
     1006            $query['category__in'] = $block->context['query']['categoryIds'];
     1007        }
     1008        if ( isset( $block->context['query']['tagIds'] ) ) {
     1009            $query['tag__in'] = $block->context['query']['tagIds'];
     1010        }
     1011        if ( isset( $block->context['query']['order'] ) ) {
     1012            $query['order'] = strtoupper( $block->context['query']['order'] );
     1013        }
     1014        if ( isset( $block->context['query']['orderBy'] ) ) {
     1015            $query['orderby'] = $block->context['query']['orderBy'];
     1016        }
     1017        if ( isset( $block->context['query']['author'] ) ) {
     1018            $query['author'] = $block->context['query']['author'];
     1019        }
     1020        if ( isset( $block->context['query']['search'] ) ) {
     1021            $query['s'] = $block->context['query']['search'];
     1022        }
     1023    }
     1024    return $query;
     1025}
Note: See TracChangeset for help on using the changeset viewer.