Skip to content

Commit

Permalink
User Queries: update parameters to take into account changes in WP 5.9 (
Browse files Browse the repository at this point in the history
#22559)

Co-authored-by: Samiff <samiff@users.noreply.github.com>
  • Loading branch information
jeherve and samiff authored Feb 3, 2022
1 parent bab7139 commit fdecb31
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Widget Visibility: update to match new user query parameter introduced in WordPress 5.9.
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,21 @@ function callback( $path = '', $blog_id = 0 ) {
}

$query = array(
'number' => $args['number'],
'offset' => $args['offset'],
'order' => $args['order'],
'orderby' => $args['order_by'],
'fields' => 'ID',
'number' => $args['number'],
'offset' => $args['offset'],
'order' => $args['order'],
'orderby' => $args['order_by'],
'fields' => 'ID',
);

if ( $authors_only ) {
$query['who'] = 'authors';
$query['capability'] = array( 'edit_posts' );
// To-do: remove this once Jetpack requires WordPress 5.9.
global $wp_version;
if ( version_compare( $wp_version, '5.9-alpha', '<' ) ) {
$query['who'] = 'authors';
unset( $query['capability'] );
}
}

if ( ! empty( $args['search'] ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,24 @@ public static function widget_admin_setup() {
$widget_conditions_data['author'] = array();
$widget_conditions_data['author'][] = array( '', __( 'All author pages', 'jetpack' ) );

// Only users with publish caps.
$authors = get_users(
array(
'orderby' => 'name',
'who' => 'authors',
'fields' => array( 'ID', 'display_name' ),
)
/*
* Query for users with publish caps.
*/
$authors_args = array(
'orderby' => 'name',
'capability' => array( 'edit_posts' ),
'fields' => array( 'ID', 'display_name' ),
);

// To-do: remove this once Jetpack requires WordPress 5.9.
global $wp_version;
if ( version_compare( $wp_version, '5.9-alpha', '<' ) ) {
$authors_args['who'] = 'authors';
unset( $authors_args['capability'] );
}

$authors = get_users( $authors_args );

foreach ( $authors as $author ) {
$widget_conditions_data['author'][] = array( (string) $author->ID, $author->display_name );
}
Expand Down
11 changes: 9 additions & 2 deletions projects/plugins/jetpack/modules/widgets/authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,18 @@ public function widget( $args, $instance ) {
$get_author_params = apply_filters(
'jetpack_widget_authors_params',
array(
'who' => 'authors',
'exclude' => (array) $excluded_authors,
'capability' => array( 'edit_posts' ),
'exclude' => (array) $excluded_authors,
)
);

// To-do: remove this once Jetpack requires WordPress 5.9.
global $wp_version;
if ( version_compare( $wp_version, '5.9-alpha', '<' ) ) {
$get_author_params['who'] = 'authors';
unset( $get_author_params['capability'] );
}

$authors = get_users( $get_author_params );

echo $args['before_widget'];
Expand Down

0 comments on commit fdecb31

Please sign in to comment.