Created
May 5, 2015 11:29
-
-
Save vishalbasnet23/795ad46a4b36d2e5c32f to your computer and use it in GitHub Desktop.
Simple WP Pointer Helper Function.
This file contains hidden or 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
jQuery(document).ready( function($) { | |
cpm_open_pointer(0); | |
function cpm_open_pointer(i) { | |
pointer = cpmPointer.pointers[i]; | |
options = $.extend( pointer.options, { | |
close: function() { | |
$.post( ajaxurl, { | |
pointer: pointer.pointer_id, | |
action: 'dismiss-wp-pointer' | |
}); | |
} | |
}); | |
$(pointer.target).pointer( options ).pointer('open'); | |
} | |
}); |
This file contains hidden or 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 | |
/** | |
* Adding WP Tool tip Helper Function | |
*/ | |
add_action( 'admin_enqueue_scripts', 'cpm_pointer_load'); | |
function cpm_pointer_load( $hook_suffix ) { | |
// Helper function goes here | |
// Don't run on WP < 3.3 | |
if ( get_bloginfo( 'version' ) < '3.3' ) | |
return; | |
// Get the screen ID | |
$screen = get_current_screen(); | |
$screen_id = $screen->id; | |
// Get pointers for this screen | |
$pointers = apply_filters( 'cpm__pointers-' . $screen_id, array() ); | |
// No pointers? Then we stop. | |
if ( ! $pointers || ! is_array( $pointers ) ) | |
return; | |
$valid_pointers = array(); | |
// Check pointers and remove dismissed ones. | |
foreach ( $pointers as $pointer_id => $pointer ) { | |
$pointer['pointer_id'] = $pointer_id; | |
// Add the pointer to $valid_pointers array | |
$valid_pointers['pointers'][] = $pointer; | |
} | |
// No valid pointers? Stop here. | |
if ( empty( $valid_pointers ) ) | |
return; | |
// Add pointers style to queue. | |
wp_enqueue_style( 'wp-pointer' ); | |
wp_enqueue_script( 'cpm-pointer', plugins_url( 'js/cpm-pointer.js', __FILE__ ), array( 'wp-pointer' ) ); | |
wp_localize_script( 'cpm-pointer', 'cpmPointer', $valid_pointers ); | |
} | |
add_filter( 'cpm_wp_poll_pointers-post', 'cpm_wp_poll_register_pointer' ); //adds to default WP Post | |
function cpm_wp_poll_register_pointer( $p ) { | |
$p['xyz140'] = array( | |
'target' => '#sample-permalink', | |
'options' => array( | |
'content' => sprintf( '<h3> %s </h3> <p> %s </p>', | |
__( 'Title' ,'_cpm'), | |
__( 'Lorem Ipsum','_cpm') | |
), | |
'position' => array( 'edge' => 'left', 'align' => 'middle' ) | |
) | |
); | |
return $p; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment