From fdecb31529797b5b18b9b3405e4498711adbe8fc Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Thu, 3 Feb 2022 09:14:22 +0100 Subject: [PATCH] User Queries: update parameters to take into account changes in WP 5.9 (#22559) Co-authored-by: Samiff --- .../fix-widget-visibility-deprecation | 4 ++++ ...ass.wpcom-json-api-list-users-endpoint.php | 18 ++++++++++----- .../widget-visibility/widget-conditions.php | 23 +++++++++++++------ .../jetpack/modules/widgets/authors.php | 11 +++++++-- 4 files changed, 41 insertions(+), 15 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/fix-widget-visibility-deprecation diff --git a/projects/plugins/jetpack/changelog/fix-widget-visibility-deprecation b/projects/plugins/jetpack/changelog/fix-widget-visibility-deprecation new file mode 100644 index 0000000000000..d5cfd600c9cfa --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-widget-visibility-deprecation @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +Widget Visibility: update to match new user query parameter introduced in WordPress 5.9. diff --git a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-users-endpoint.php b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-users-endpoint.php index 489223b78ee49..113e9fd012954 100644 --- a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-users-endpoint.php +++ b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-users-endpoint.php @@ -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'] ) ) { diff --git a/projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php b/projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php index 5a03db9123c69..5423f049ee3aa 100644 --- a/projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php +++ b/projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php @@ -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 ); } diff --git a/projects/plugins/jetpack/modules/widgets/authors.php b/projects/plugins/jetpack/modules/widgets/authors.php index 402794fc9cc97..4ed2e8d1e483b 100644 --- a/projects/plugins/jetpack/modules/widgets/authors.php +++ b/projects/plugins/jetpack/modules/widgets/authors.php @@ -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'];