WP_Internal_Pointers::print_js
Prints the pointer JavaScript data.
Method of the class: WP_Internal_Pointers{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = WP_Internal_Pointers::print_js( $pointer_id, $selector, $args );
- $pointer_id(string) (required)
- The pointer ID.
- $selector(string) (required)
- The HTML elements, on which the pointer should be attached.
- $args(array) (required)
- Arguments to be passed to the pointer JS (see wp-pointer.js).
Changelog
| Since 3.3.0 | Introduced. |
WP_Internal_Pointers::print_js() WP Internal Pointers::print js code WP 7.0
<?php
private static function print_js( $pointer_id, $selector, $args ) {
if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args['content'] ) ) {
return;
}
?>
<script>
(function($){
var options = <?php echo wp_json_encode( $args, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?>, setup;
if ( ! options )
return;
options = $.extend( options, {
close: function() {
$.post( ajaxurl, {
pointer: '<?php echo $pointer_id; ?>',
action: 'dismiss-wp-pointer'
});
}
});
setup = function() {
$('<?php echo $selector; ?>').first().pointer( options ).pointer('open');
};
if ( options.position && options.position.defer_loading )
$(window).bind( 'load.wp-pointers', setup );
else
$( function() {
setup();
} );
})( jQuery );
</script>
<?php
}