Skip to content

Commit

Permalink
Roles endpoint: Use instance of for checking wp roles (#39634)
Browse files Browse the repository at this point in the history
* Improve roles check

* changelog

* Added defensive check for arrays

* Updated phan baseline

* Jetpack plugin: Update phan baselines

---------

Co-authored-by: Foteini Giannaropoulou <[email protected]>

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/11161713106

Upstream-Ref: Automattic/jetpack@f3687fc
  • Loading branch information
darssen authored and matticbot committed Oct 3, 2024
1 parent c2ac5ab commit 589a074
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This is an alpha version! The changes listed here are not final.

### Other changes <!-- Non-user-facing changes go here. This section will not be copied to readme.txt. -->
- Admin menu: Adding tests to check for 'current' class when menu item selected.
- Change done to avoid fatal in wpcom when using v1 endpoint with force wpcom param
- Email preview modal: visually improved error state
- Unify connection nudge design on Jetpack Settings
- Unify connection related CTAs on At A Glance
Expand Down
4 changes: 2 additions & 2 deletions json-endpoints/class.wpcom-json-api-list-roles-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function callback( $path = '', $blog_id = 0 ) {
return new WP_Error( 'unauthorized', 'User cannot view roles for specified site', 403 );
}

if ( method_exists( $wp_roles, 'get_names' ) ) {
if ( $wp_roles instanceof WP_Roles ) {
$role_names = $wp_roles->get_names();

$role_keys = array_keys( $role_names );
Expand All @@ -134,7 +134,7 @@ public function callback( $path = '', $blog_id = 0 ) {
$role_details->display_name = translate_user_role( $role_names[ $role_key ] );
$roles[] = $role_details;
}
} else {
} elseif ( is_array( $wp_roles ) ) {
// Jetpack Shadow Site side of things.
foreach ( $wp_roles as $role_key => $role ) {
$roles[] = (object) array(
Expand Down

0 comments on commit 589a074

Please sign in to comment.