Creating admin bar link with nonce
-
I’m trying to create an admin bar link to clear a plugin cache that currently requires me to go to the plugin page to clear it. The clearing link on the plugin admin page looks like this:
https://dev.udcus.com/wp-admin/admin.php?page=debloat-delete-cache&_wpnonce=XXXXXXXXXX
This is my code:
function custom_toolbar_link($wp_admin_bar) { $wp_admin_bar->add_node(array( 'id' => 'clear-all-caches', 'title' => 'Clear All Caches', 'href' => false, )); $urlDebloat = wp_nonce_url( '/wp-admin/admin.php?page=debloat-delete-cache', 'debloat' ); $wp_admin_bar->add_node(array( 'parent' => 'clear-all-caches', 'id' => 'clear_debloat_cache', 'title' => 'Clear Debloat Cache', 'href' => $urlDebloat, )); } add_action('admin_bar_menu', 'custom_toolbar_link', 999);It creates the link, and adds a nonce, but the nonce is different from the one that I get on the plugin admin page clearing link, and I get “The link you followed has expired” when I use it. Hopefully, I don’t have to deep dive on understanding everything about nonces to make this work?
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
You must be logged in to reply to this topic.