-
Notifications
You must be signed in to change notification settings - Fork 800
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
Fix class-wpcom-admin-bar.php fatal error #38526
Conversation
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. Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped. |
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
@@ -60,6 +60,11 @@ class WPCOM_Admin_Bar extends \WP_Admin_Bar { | |||
* } | |||
*/ | |||
public function add_node( $args ) { | |||
// Ensure $args is an array. | |||
if ( is_object( $args ) ) { |
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.
I think the most robust way is to just call parent::add_node( $args );
and bail, if $args
is not an array. Similar to the next if-block at line 68.
(It means we only care to manipulate the nodes on wpcom side only if $args
is array)
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.
Yeah, I like that. 👍 I updated the PR.
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.
yep, it looks better to return early if it's not an array because the args might be a string as well 😓
Or we have to add the following lines before processing
// Shim for old method signature: add_node( $parent_id, $menu_obj, $args ).
if ( func_num_args() >= 3 && is_string( $args ) ) {
$args = array_merge( array( 'parent' => $args ), func_get_arg( 2 ) );
}
if ( is_object( $args ) ) {
$args = get_object_vars( $args );
}
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.
Confirmed the critical error has gone and the instructions in #38377 looked well to me. ✅
CC: @fushar @arthur791004
Merging this PR, as I saw ✅ from @arthur791004 |
Fixes p1721840431003479-slack-C02FMH4G8
Proposed changes:
We saw the following fatal error with class-wpcom-admin-bar.php while it was in production before it was rolled back.
This error can be reproduced on an Atomic site by adding the Elementor plugin.
This PR addresses the fatal error by ensuring $args is an array before continuing.
Other information:
Jetpack product discussion
No.
Does this pull request change what data or activity we track or use?
Testing instructions:
wp plugin deactivate elementor
the error should disappear.