PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 19, 2022

[FIXED] How can I add a link to the Wordpress Admin Bar that runs my function onclick?

 October 19, 2022     admin, function, php, wordpress     No comments   

Issue

I am wanting to add a link to the Wordpress admin bar that will eventually purge all cache. At the moment I am trying to add the link to the admin bar but seem to be having problems.

I have followed a few methods I had found on Google, but for some reason I couldn't get them to work. (I don't know if this is due to the examples being outdated with the version of Wordpress?)

Here is what I am using so far:

function time_to_purge($wp_admin_bar) {
$args = array(
'id' => 'DaylesPurge',
'title' => 'Purge Cache',
'href' => '#',
'meta' => array(
'class' => 'DaylesPurge'
)
);
$wp_admin_bar->add_node($args);
}

add_action('admin_bar_menu', 'time_to_purge', 50);

function PurgeConfirmation() {
document.getElementById("PurgeConfirmation").innerHTML = "Are you sure you 
wish to purge the cash?";
}

[EDIT] Never-mind, this works perfectly. It was a matter of a simple spelling mistake in my code that was preventing it from displaying.


Solution

function time_to_purge($wp_admin_bar) {
$args = array(
'id' => 'DaylesPurge',
'title' => 'Purge Cache',
'href' => '#',
'meta' => array(
'class' => 'DaylesPurge'
)
);
$wp_admin_bar->add_node($args);
}

add_action('admin_bar_menu', 'time_to_purge', 50);

function PurgeConfirmation() {
document.getElementById("PurgeConfirmation").innerHTML = "Are you sure you 
wish to purge the cash?";
}


Answered By - Dayley
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing