WordPress and buddypress programming

How to show a custom notification to a specific user

Viewing 0 reply threads
  • Author
    Posts
    • #8851
      Michael Mc
      Keymaster
      @mkmcst

      You can show admin notices via the admin_notices action. You can display it for a specific user by checking the contents of the global $current_user:

      function wpa80367_admin_notice() {
          global $current_user;
          if ( 'someusername' == $current_user->user_login ):
              echo '<div class="updated"><p>';
              echo 'This is an admin notice just for you, someusername.';
              echo '</p></div>';
          endif;
      }
      add_action( 'admin_notices', 'wpa80367_admin_notice' );

      You could also extend this by saving per-user notices as user metadata via add_user_meta, then checking if a user has a notice in the above function via get_user_meta.

Viewing 0 reply threads
  • You must be logged in to reply to this topic.