WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know I'm probably doing something dumb here but I just can't get this to run. I'm trying to set up a little API for my plugin and to create a class to display admin notices a little easier. Here's what I have:

// Send data to class to get HTML for admin notice
$plugin_update = $efpd->efpd_admin_notice(
    $notice_info = array(
        'type' => 'update',
        'message' => 'The plugin has just been updated.',
        'button' => 'Click for details'
//wp_die(var_dump($plugin_update)); // Testing output of admin notice HTML code
add_action('admin_notices',function(){echo $plugin_update;});

And in my class, there is this function:

public function efpd_admin_notice($data=array()){
    extract($data); // Extracts $message, $type, and $button from $data array
    if(empty($message) && !empty($type)){ // If no message was passed through the $data array, create one based on the type of notice passed, also begin the HTML output here
            case 'error':
                $message = 'There\'s been an error!';
                $return = "<div id=\"message\" class=\"error\">\n";
            case 'update':
                $message = 'There\'s been an update!';
                $return = "<div id=\"message\" class=\"updated\">\n";
                $message = 'There\'s something wrong with your code...';
                $return = "<div id=\"message\" class=\"error\">\n";
    if(empty($button)) $button = 'Click Here';
    $return .= "    <p style=\"float: left;\">{$message}</p>\n";
    $return .= "    <p style=\"float: left;\"><a href=\"{$settings_url}&amp;clear_cache=y\">{$button}</a></p>\n";
    $return .= "</div>\n";
    return $return;

So I guess I'm asking, what am I doing wrong to get this admin notice to not show? Is there a workaround to get this to work? Thanks.

share|improve this question
up vote 2 down vote accepted

Try this. I cleaned up your arg array and placed everything in a function. Also, why are you using the getInstance method when your efpd_admin_notice is public? See the code below for accessing this method properly.

function plugin_update(){
    $plugin_update = Efpdd::efpd_admin_notice(array(
        'type' => 'update',
        'message' => 'The plugin has just been updated.',
        'button' => 'Click for details'
    echo $plugin_update;
add_action('admin_notices', 'plugin_update');
share|improve this answer
Thanks, I appreciate it, seems to be working fine now. To be honest I'm very tired, not sure why I've done half the things I have to my code. :P – Jared Oct 26 '11 at 15:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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