Skip to content

Instantly share code, notes, and snippets.

@alex-georgiou
Created April 23, 2021 18:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alex-georgiou/dafb963a2773b926109cd6ba980b4722 to your computer and use it in GitHub Desktop.
Save alex-georgiou/dafb963a2773b926109cd6ba980b4722 to your computer and use it in GitHub Desktop.
<?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