Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'd like to give users a little welcome message on their first login to the admin area. Once they hide the message it should not appear again. I noticed admin_notice is a hook but don't know where to start. Thanks.

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

something like:

add_action('admin_notices', 'my_notice');    
add_action('wp_ajax_hide_my_notice', 'hide_my_notice');

function hide_my_notice(){
  check_ajax_referer('hide-my-notice');
  $user = wp_get_current_user();

  // update status for this user
  $seen_notice = get_option('my_notice');
  $seen_notice[$user->ID] = true;
  update_option('my_notice', $seen_notice);
  exit;
} 

function my_notice(){

  $user = wp_get_current_user();
  $seen_notice = get_option('my_notice');

  // already seen it?
  if(isset($seen_notice[$user->ID]) && $seen_notice[$user->ID])
    return;

  ?>
  <div class="updated fade below-h2">
    <p>
      Hi <?php print esc_attr($user->user_login); ?>! Duuuuuude, whatz upp???
      <a class="hide-me"> X </a>
    </p>
   </div>  

   <script type="text/javascript">    

     // this should go in a javascript file;
     // use wp_localize_script() to send variables from PHP to it
     jQuery(document).ready(function($) {

       $('a.hide-me').on('click', function(){

         $.ajax({
           url: '<?php print admin_url("admin-ajax.php"); ?>',
           type: 'GET',
           context: this,
           data: ({
             action: 'hide_my_notice',
             _ajax_nonce: '<?php print wp_create_nonce('hide-my-notice'); ?>'
           }),
           success: function(response){ 
             $(this).closest('div').remove();
           }    
         });
       });

     });

   </script>    
  <?php     
}

You can also use options cookies or transients to store the notice status

share|improve this answer
    
Nice, but why the obscure variable? $$$ (or is there more to it then that?).. –  t31os Dec 20 '10 at 10:43
    
no, it's just a variable like any other :) –  onetrickpony Dec 20 '10 at 16:59
    
Great stuff. Just one more question is how to get it to appear under the H2 like other notices. It has the class below-h2 but doesn't appear there. Thanks. –  agileapricot Dec 21 '10 at 8:36
    
does it work if you remove the "below-h2" class? –  onetrickpony Dec 21 '10 at 10:17
    
Hmm, it appears the notice doesn't get hidden when i come back to the page :P Does it work for anyone else? How might i go about using the other two methods for hiding it? Sorry i'm in experinced. –  agileapricot Dec 21 '10 at 12:03
show 4 more comments

WordPress 3.3 has Pointers for this.

Example of a pointer

WordPress 3.3 is planned for November [2011] and we published the scope a while ago here on Theme.fm. As mentioned in that post, 3.3 will get a series of UI improvements, one of which is Pointers (or Admin Pointers). We learned about pointers in WordPress a few hours ago from one of Daryl Koopersmith’s changesets so we decided to give it a spin ourselves.

What are Admin Pointers?

Here’s what Jane wrote in the trac ticket for WordPress pointers:

When a new user-facing feature is included in a core update, display a new feature pointer that highlights the new feature a la Facebook, Gmail, etc.

share|improve this answer
add comment

Your Answer

 
discard

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.