-
Notifications
You must be signed in to change notification settings - Fork 799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Roles endpoint: Use instance of for checking wp roles #39634
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Follow this PR Review Process:
Still unsure? Reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
@@ -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 ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could be more defensive here and also check if $wp_roles
is actually an array next?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reviewing, I addressed it in 6540dbd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great!
Tested on both Jetpack and Simple sites and ensured we don't fatal anymore for requests for Jetpack sites with ?force=wpcom
Fixes a Fatal in wpcom when using the endpoint with the
force=wpcom
param.Based on https://bugs.php.net/bug.php?id=79623 it looks like this was introduced when switching to PHP8
Proposed changes:
Use
instanceof WP_Roles
check instead ofmethod_exists
since in the Jetpack Shadow Site$wp_roles
is an array not an object.Other information:
Jetpack product discussion
b3afe066ca610f6dd94a60779e59882e-logstash
Does this pull request change what data or activity we track or use?
No
Testing instructions:
Call the endpoints for 3 scenarios:
Simple site (Should go through WPCOM)
Jetpack site
Jetpack site with query_param
force=wpcom
(Should go through WPCOM)