diff --git a/lib/compat/wordpress-5.8.php b/lib/compat/wordpress-5.8.php new file mode 100644 index 00000000000000..609db3cf9c605c --- /dev/null +++ b/lib/compat/wordpress-5.8.php @@ -0,0 +1,70 @@ + '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; + } +} diff --git a/lib/load.php b/lib/load.php index 784fbec1b2c006..7b65711eefe017 100644 --- a/lib/load.php +++ b/lib/load.php @@ -83,6 +83,7 @@ function gutenberg_is_experiment_enabled( $name ) { require_once __DIR__ . '/widgets-page.php'; require __DIR__ . '/compat.php'; +require __DIR__ . '/compat/wordpress-5.8.php'; require __DIR__ . '/utils.php'; require __DIR__ . '/editor-settings.php'; @@ -120,7 +121,6 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/navigation-page.php'; require __DIR__ . '/experiments-page.php'; require __DIR__ . '/global-styles.php'; -require __DIR__ . '/query-utils.php'; require __DIR__ . '/block-supports/generated-classname.php'; require __DIR__ . '/block-supports/colors.php'; diff --git a/lib/query-utils.php b/lib/query-utils.php deleted file mode 100644 index 42b88fca83a102..00000000000000 --- a/lib/query-utils.php +++ /dev/null @@ -1,67 +0,0 @@ - '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; -}