Skip to content

Instantly share code, notes, and snippets.

@alimd
Last active December 20, 2015 14:19
Show Gist options
  • Save alimd/6145755 to your computer and use it in GitHub Desktop.
Save alimd/6145755 to your computer and use it in GitHub Desktop.
Wordpress Admin Welcome Notice
<?php
add_action('admin_notices', 'welcome_notice');
function welcome_notice() {
global $current_user;
if ( !get_user_meta($current_user->ID, 'notice_ignored',true) ) {
echo '<div class="updated"><p>';
printf(__('<h2>Thanks for purchasing my theme. </h2><a href="%1$s" class="remove_message">Remove this message</a>'), '?welcome_notice_ignore=1');
echo '</p></div>';
}
}
add_action('admin_init', 'welcome_notice_ignore');
function welcome_notice_ignore() {
global $current_user;
get_currentuserinfo();
if ( isset($_GET['welcome_notice_ignore']) ) {
update_user_meta($current_user->ID, 'notice_ignored', (int)$_GET['welcome_notice_ignore']);
}
}

Wordpress Admin Welcome Notice

Get current user data

add_action('admin_init', 'get_user_info');
function get_user_info(){
  global $current_user;
  get_currentuserinfo();
}

Create welcome notice box

add_action('admin_notices', 'welcome_notice');
function welcome_notice() {
  global $current_user;
  if ( !get_user_meta($current_user->ID, 'notice_ignored',true) ) {
    echo '<div class="updated"><p>';
    printf(__('<h2>Thanks for purchasing my theme. </h2><a href="%1$s" class="remove_message">Remove this message</a>'), '?welcome_notice_ignore=1');
    echo '</p></div>';
  }
}

Ignore option

add_action('admin_init', 'welcome_notice_ignore');
function welcome_notice_ignore() {
  global $current_user;
  if ( isset($_GET['welcome_notice_ignore']) ) {
    update_user_meta($current_user->ID, 'notice_ignored', (int)$_GET['welcome_notice_ignore']);
  }
}

Functions Refrences

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment