List $wp_admin_bar menu items (debug)
-
16-03-2021 - |
Domanda
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!
Soluzione
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.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange