Skip to content
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

Merged
merged 3 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fix fatal error in admin bar
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Copy link
Contributor

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)

Copy link
Member Author

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.

Copy link
Contributor

@arthur791004 arthur791004 Jul 25, 2024

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 );
}

$args = (array) $args;
}

if ( empty( $args['href'] ) ) {
parent::add_node( $args );
return;
Expand Down
Loading