Skip to content

Commit

Permalink
Merge branch 'release/2.0.0' into bug/looper-preview
Browse files Browse the repository at this point in the history
  • Loading branch information
tomusborne committed Dec 4, 2024
2 parents 840759f + ebc8cfd commit 132402a
Show file tree
Hide file tree
Showing 18 changed files with 2,286 additions and 4,193 deletions.
2 changes: 1 addition & 1 deletion dist/blocks/looper/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-rich-text', 'generateblocks-block-styles', 'generateblocks-components', 'generateblocks-styles-builder'), 'version' => '12e29db64b51cfd610e8');
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-primitives', 'wp-rich-text', 'generateblocks-block-styles', 'generateblocks-components', 'generateblocks-styles-builder'), 'version' => 'e9e5d83981434eb4002e');
5 changes: 4 additions & 1 deletion dist/blocks/looper/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/blocks/query/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-primitives', 'wp-rich-text', 'generateblocks-block-styles', 'generateblocks-components', 'generateblocks-styles-builder'), 'version' => 'c5923e6febeb396b0997');
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-primitives', 'wp-rich-text', 'generateblocks-block-styles', 'generateblocks-components', 'generateblocks-styles-builder'), 'version' => '59a496955ff5c3c40029');
4 changes: 2 additions & 2 deletions dist/blocks/query/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/blocks/shape/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-rich-text', 'generateblocks-block-styles', 'generateblocks-components', 'generateblocks-styles-builder'), 'version' => 'd908f5b4fad32e70103d');
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-rich-text', 'generateblocks-block-styles', 'generateblocks-components', 'generateblocks-styles-builder'), 'version' => '28692b7a0f9aeec1cad0');
2 changes: 1 addition & 1 deletion dist/blocks/shape/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/blocks/text/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-primitives', 'wp-rich-text', 'generateblocks-block-styles', 'generateblocks-components', 'generateblocks-styles-builder'), 'version' => '895f979a7fda18614c5b');
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-primitives', 'wp-rich-text', 'generateblocks-block-styles', 'generateblocks-components', 'generateblocks-styles-builder'), 'version' => 'a7dc5b092caa4a62fe6d');
2 changes: 1 addition & 1 deletion dist/blocks/text/index.js

Large diffs are not rendered by default.

71 changes: 25 additions & 46 deletions includes/class-query-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,52 +95,20 @@ public function get_wp_query( $request ) {
$args = $request->get_param( 'args' );
$page = $args['paged'] ?? $request->get_param( 'page' ) ?? 1;
$attributes = $request->get_param( 'attributes' ) ?? [];
$current_post = $request->get_param( 'currentPost' ) ?? null;
$current_author = $current_post['author'] ?? 0;

// Handle current entity values.
if ( $current_post ) {
$included_posts = $args['post__in'] ?? [];
$excluded_posts = $args['post__not_in'] ?? [];

foreach ( $included_posts as &$the_post ) {
if ( 'current' === $the_post ) {
$the_post = $current_post;
}
}

foreach ( $excluded_posts as &$the_post ) {
if ( 'current' === $the_post ) {
$the_post = $current_post;
}
}

$args['post__in'] = $included_posts;
$args['post__not_in'] = $excluded_posts;
}

if ( $current_author ) {
$included_authors = $args['author__in'] ?? [];
$excluded_authors = $args['author__not_in'] ?? [];

foreach ( $included_authors as &$the_post ) {
if ( 'current' === $the_post ) {
$the_post = $current_author;
}
}

foreach ( $excluded_authors as &$the_post ) {
if ( 'current' === $the_post ) {
$the_post = $current_author;
}
}

$args['author__in'] = $included_authors;
$args['author__not_in'] = $excluded_authors;
}
$current_post = $request->get_param( 'postId' ) ?? null;
$current_author = $request->get_param( 'authorId' ) ?? null;

$query = new WP_Query(
self::get_wp_query_args( $args, $page, $attributes )
self::get_wp_query_args(
$args,
$page,
$attributes,
null,
[
'post_id' => $current_post,
'author_id' => $current_author,
]
)
);

return rest_ensure_response( $query );
Expand All @@ -153,10 +121,14 @@ public function get_wp_query( $request ) {
* @param int $page Current query's page.
* @param array $attributes The query block's attributes. Used for reference in the filters.
* @param WP_Block|array $block The current block.
* @param array $current Array of current entities (post, author, etc.).
*
* @return array $query_args The optimized WP_Query args array.
*/
public static function get_wp_query_args( $args = [], $page = 1, $attributes = [], $block = null ) {
public static function get_wp_query_args( $args = [], $page = 1, $attributes = [], $block = null, $current = [] ) {
$current_post_id = $current['post_id'] ?? get_the_ID();
$current_author_id = $current['author_id'] ?? get_the_author_meta( 'ID' );

// Set up our pagination.
if ( ! isset( $args['paged'] ) && -1 < (int) $page ) {
$args['paged'] = $page;
Expand Down Expand Up @@ -261,12 +233,19 @@ function( $value ) {
* @param array @query_args The array of args for the WP_Query.
* @param array $attributes The block attributes.
* @param WP_Block|array $block The current block.
* @param array $current The current entities (post, author, etc.).
*
* @return $args The modified query arguments.
*/
return apply_filters(
'generateblocks_query_wp_query_args',
$args,
$attributes,
null === $block ? new stdClass() : $block
null === $block ? new stdClass() : $block,
[
'post_id' => $current_post_id,
'author_id' => $current_author_id,
]
);
}

Expand Down
Loading

0 comments on commit 132402a

Please sign in to comment.