This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: WordPress admin pointer example | |
* Plugin URI: http://alexgeorgiou.gr/wordpress-admin-pointers-for-dummies/ | |
* Description: Showcasing how to create an admin pointer. Points to the settings menu. | |
* Version: 1.0 | |
* Requires at least: 3.3 | |
* Author: Alexandros Georgiou <alexgeorgiou@gmail.com> | |
* Author URI: https://alexgeorgiou.gr | |
* License: GPLv2 or later | |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
add_action( | |
'in_admin_header', | |
function() { | |
wp_enqueue_script( 'jquery' ); | |
wp_enqueue_style( 'wp-pointer' ); | |
wp_enqueue_script( 'wp-pointer' ); | |
if ( | |
! get_user_meta( | |
get_current_user_id(), | |
'my-pointer-slug-dismissed', | |
true | |
) | |
): | |
?> | |
<script> | |
jQuery( | |
function() { | |
jQuery('#menu-dashboard').first().pointer( | |
{ | |
content: | |
"<h3>WordPress dashboard<\/h3>" + | |
"<h4>Here is the admin dashboard<\/h4>" + | |
"<p>But, I'm guessing, you already knew this, didn't you?</p>" + | |
"<p>If so, you can <strong>dismiss<\/strong> this pointer, and it won't ever bother you again.</p>", | |
position: | |
{ | |
edge: 'top', | |
align: 'left' | |
}, | |
pointerClass: | |
'wp-pointer arrow-top', | |
pointerWidth: 420, | |
close: function() { | |
jQuery.post( | |
ajaxurl, | |
{ | |
pointer: 'my-pointer-slug', | |
action: 'dismiss-wp-pointer', | |
} | |
); | |
}, | |
} | |
).pointer('open'); | |
} | |
); | |
</script> | |
<?php | |
endif; | |
} | |
); | |
add_action( | |
'admin_init', | |
function() { | |
if ( isset( $_POST['action'] ) && 'dismiss-wp-pointer' == $_POST['action'] ) { | |
update_user_meta( | |
get_current_user_id(), | |
'my-pointer-slug-dismissed', | |
$_POST['pointer'], | |
true | |
); | |
} | |
} | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment