1

I would like to dump the content of the $wp_admin_bar object in order to remove some menu items with the remove_menu() method.

What is the suggested way to do it without printing anything on the website?

I have enabled WP_DEBUG and WP_DEBUG_LOG in wp-config.php. I was thinking about printing it in debug.log

Thanks for the suggestions!

1

You can use error_log() and print_r():

add_action( 'wp_footer', 'wpse_debug_toolbar' );
function wpse_debug_toolbar() {
    global  $wp_admin_bar;
    error_log( print_r( $wp_admin_bar, true ) );
}

Note that when using print_r() we've set the second parameter $return to true so that the results are returned and not echo'd.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.