DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Introduce Your Plugin With WordPress Pointers

Paul Underwood user avatar by
Paul Underwood
·
Jan. 17, 13 · Interview
Like (0)
Save
Tweet
Share
3.39K Views

Join the DZone community and get the full member experience.

Join For Free

In version 3.3 WordPress released a new feature called pointers. These are little pop-up notification boxes which you can use to point to new information on your WordPress admin area.

Pointer

This is a great idea if you are a plugin or theme developer, you can make it so that when a user installs your new plugin you can use the pointers to show exactly how they are suppose to use it.

For example if the plugin adds a new menu item to the WordPress admin area, you can use pointers to show the user that there is a new menu item and what it allows you to do with your wordpress site.

You can assign a pointer to be displayed on any HTML ID or class, it is just a jQuery widget which has a title bar, text area and close button.

How To Use Pointers?

To use WordPress pointers you first need to include the pointers styling and javascript's on to the page. As these are already registered with the core WordPress you just need to call them using the wp_enqueue_script() and wp_enqueue_style().

// Use the pointers
wp_enqueue_style( 'wp-pointer' );
wp_enqueue_script( 'wp-pointer' );

Now that the pointer javascript is added to the page there is a pointer object which is now available to use in your jQuery code.

To use this jQuery pointer object you just need to add some Javascript to the page assigning a pointer to a HTML element.

//

The most basic way of using the pointers will have 2 options the content and the position of the pointer. If you want the pointer to have a title you can add a h3 tag to the content object.

To use this in WordPress all you have to do is put the above all together, below is some example code of how to add a pointer to the admin area. In this example we are just going to add a pointer to the settings menu item, just add the following to your functions.php file.

// Register the pointer styles and scripts
add_action( 'admin_enqueue_scripts', 'enqueue_scripts' );
// Add pointer javascript
add_action( 'admin_print_footer_scripts', 'add_pointer_scripts' );
// enqueue javascripts and styles
public function enqueue_scripts()
{
	wp_enqueue_style( 'wp-pointer' );
	wp_enqueue_script( 'wp-pointer' );
}
// Add the pointer javascript
public function add_pointer_scripts()
{
	$content = '
<h3>Define New Settings</h3>
';
	$content .= '
Edit the settings of your WordPress website.';
?>
	//<![CDATA[
	jQuery(document).ready( function($) {
	    $('#menu-settings').pointer({
	        content: '',
	        position: {
                edge: 'left',
                align: 'center'
            },
	        close: function() {
	            // what to do after the object is closed
	        }
	    }).pointer('open');
	});
	//]]>
<?php
}
Pointer (computer programming) WordPress

Published at DZone with permission of Paul Underwood, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Simulate Network Latency and Packet Drop In Linux
  • Mr. Over, the Engineer [Comic]
  • How To Validate Three Common Document Types in Python
  • Distributed Stateful Edge Platforms

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: