Skip to content

Commit

Permalink
feat: add support for Newspack Guest Contributor in HPP blocks (#1934)
Browse files Browse the repository at this point in the history
* feat: add support for Newspack Guest Contributor in HPP blocks

* feat: do not offload query to ES if use filters

* test: fix test
  • Loading branch information
leogermani authored Nov 26, 2024
1 parent 46cd5f0 commit c16849e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions includes/class-newspack-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,9 @@ public static function build_articles_query( $attributes, $block_name ) {
'authors' => $authors,
'coauthors' => $co_authors_names,
];

// Also, in these cases, never offload the query to Elastic Search.
$args['newspack_no_es_query'] = true;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,14 @@ public function get_authors( $request ) {
}
}
} else {
$role_in = [ 'Administrator', 'Editor', 'Author', 'Contributor' ];
// Support for Newspack's Guest Contributor Role.
if ( class_exists( 'Newspack\Guest_Contributor_Role' ) ) {
$role_in[] = Newspack\Guest_Contributor_Role::CONTRIBUTOR_NO_EDIT_ROLE_NAME;
}

$user_args = [
'role__in' => [ 'Administrator', 'Editor', 'Author', 'Contributor' ],
'role__in' => $role_in,
'offset' => $offset,
'orderby' => 'registered',
'order' => 'DESC',
Expand Down
5 changes: 3 additions & 2 deletions tests/test-homepage-posts-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public function test_hpb_build_articles_query() {
'authors' => [ 1 ],
],
'resulting_query_partial' => [
'posts_per_page' => 1,
'post_type' => 'some-type',
'posts_per_page' => 1,
'post_type' => 'some-type',
'newspack_no_es_query' => true,
],
'description' => 'With custom post type and author',
'ignore_tax_query' => true,
Expand Down

0 comments on commit c16849e

Please sign in to comment.