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]>
  • Loading branch information
2 people authored and gogdzl committed Oct 25, 2024
1 parent a16aa72 commit 463ebbc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
'json-endpoints/class.wpcom-json-api-list-posts-endpoint.php' => ['PhanNoopNew', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgument', 'PhanTypeMismatchDefault', 'PhanTypeMismatchReturn', 'PhanTypePossiblyInvalidDimOffset'],
'json-endpoints/class.wpcom-json-api-list-posts-v1-1-endpoint.php' => ['PhanNoopNew', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeInvalidDimOffset', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternalReal', 'PhanTypeMismatchDefault', 'PhanTypeMismatchReturn', 'PhanTypePossiblyInvalidDimOffset'],
'json-endpoints/class.wpcom-json-api-list-posts-v1-2-endpoint.php' => ['PhanNoopNew', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeInvalidDimOffset', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternalReal', 'PhanTypeMismatchDefault', 'PhanTypeMismatchReturn', 'PhanTypePossiblyInvalidDimOffset'],
'json-endpoints/class.wpcom-json-api-list-roles-endpoint.php' => ['PhanDeprecatedPartiallySupportedCallable', 'PhanNoopNew', 'PhanTypeMismatchDefault', 'PhanTypeMismatchReturn', 'PhanTypeSuspiciousNonTraversableForeach'],
'json-endpoints/class.wpcom-json-api-list-roles-endpoint.php' => ['PhanDeprecatedPartiallySupportedCallable', 'PhanNoopNew', 'PhanTypeMismatchDefault', 'PhanTypeMismatchReturn'],
'json-endpoints/class.wpcom-json-api-list-shortcodes-endpoint.php' => ['PhanNoopNew', 'PhanTypeMismatchDefault', 'PhanTypeMismatchReturn'],
'json-endpoints/class.wpcom-json-api-list-terms-endpoint.php' => ['PhanNoopNew', 'PhanTypeMismatchDefault', 'PhanTypeMismatchReturn', 'PhanTypeSuspiciousNonTraversableForeach'],
'json-endpoints/class.wpcom-json-api-list-users-endpoint.php' => ['PhanNoopNew', 'PhanRedundantCondition', 'PhanTypeMismatchDefault', 'PhanTypeMismatchReturn', 'PhanUndeclaredProperty'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Change done to avoid fatal in wpcom when using v1 endpoint with force wpcom param
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 463ebbc

Please sign in to comment.