@@ -62,6 +62,8 @@ function ( Pointer $pointer ) use ( $hook_suffix ) {
6262 }
6363
6464 wp_enqueue_style ( 'wp-pointer ' );
65+ // Dashboard styles are required where pointers are used to ensure proper styling.
66+ wp_enqueue_style ( 'googlesitekit-wp-dashboard-css ' );
6567 wp_enqueue_script ( 'wp-pointer ' );
6668
6769 add_action (
@@ -103,6 +105,7 @@ function ( $pointer ) {
103105 * Prints script for a given pointer.
104106 *
105107 * @since 1.83.0
108+ * @since n.e.x.t Updated to support buttons and header dismiss icon.
106109 *
107110 * @param Pointer $pointer Pointer to print.
108111 */
@@ -112,38 +115,82 @@ private function print_pointer_script( $pointer ) {
112115 return ;
113116 }
114117
115- $ slug = $ pointer ->get_slug ();
118+ $ buttons = $ pointer ->get_buttons ();
119+ if ( $ buttons ) {
120+ // Content including buttons escaped below in the inline script with wp_kses.
121+ $ content .= '<div class="googlesitekit-pointer-buttons"> ' . $ buttons . '</div> ' ;
122+ }
116123
117- BC_Functions::wp_print_inline_script_tag (
118- sprintf (
119- '
120- jQuery( function() {
121- var options = {
122- content: "<h3>%s</h3>%s",
123- position: %s,
124- pointerWidth: 420,
125- close: function() {
126- jQuery.post(
127- window.ajaxurl,
128- {
129- pointer: "%s",
130- action: "dismiss-wp-pointer",
131- }
132- );
133- }
134- };
135-
136- jQuery( "#%s" ).pointer( options ).pointer( "open" );
137- } );
138- ' ,
139- esc_js ( $ pointer ->get_title () ),
140- $ content ,
141- wp_json_encode ( $ pointer ->get_position () ),
142- esc_js ( $ slug ),
143- esc_js ( $ pointer ->get_target_id () )
124+ $ class = array ( 'wp-pointer ' );
125+ if ( $ pointer ->get_class () ) {
126+ $ class [] = $ pointer ->get_class ();
127+ }
128+
129+ $ kses_title = array (
130+ 'span ' => array ( 'class ' => array () ),
131+ 'button ' => array (
132+ 'class ' => array (),
133+ 'type ' => array (),
134+ 'data-action ' => array (),
135+ ),
136+ );
137+
138+ $ kses_content = array (
139+ 'a ' => array (
140+ 'href ' => array (),
141+ 'class ' => array (),
142+ 'target ' => array (),
143+ 'rel ' => array (),
144+ 'data-action ' => array (),
145+ ),
146+ 'h4 ' => array (),
147+ 'p ' => array ( 'class ' => array () ),
148+ 'br ' => array (),
149+ 'strong ' => array (),
150+ 'em ' => array (),
151+ 'button ' => array (
152+ 'class ' => array (),
153+ 'type ' => array (),
154+ 'data-action ' => array (),
144155 ),
156+ 'div ' => array ( 'class ' => array () ),
157+ );
158+
159+ BC_Functions::wp_print_inline_script_tag (
160+ <<<'JS'
161+ (
162+ function ( $, wp, config ) {
163+ function initPointer() {
164+ const options = {
165+ content: '<h3>' + config.title + '</h3>' + config.content,
166+ position: JSON.parse( config.position ),
167+ pointerWidth: 420,
168+ pointerClass: config.class,
169+ close: function() {
170+ wp.ajax.post( 'dismiss-wp-pointer', { pointer: config.slug } );
171+ },
172+ buttons: function( event, container ) {
173+ container.pointer.on( 'click', '[data-action="dismiss"]', function() {
174+ container.element.pointer( 'close' );
175+ } );
176+ }
177+ };
178+
179+ $( '#' + config.targetId ).pointer( options ).pointer( 'open' );
180+ }
181+
182+ $( initPointer );
183+ }
184+ )( window.jQuery, window.wp, { ...document.currentScript.dataset } );
185+ JS
186+ ,
145187 array (
146- 'id ' => $ slug ,
188+ 'data-slug ' => $ pointer ->get_slug (),
189+ 'data-class ' => implode ( ' ' , $ class ),
190+ 'data-target-id ' => $ pointer ->get_target_id (),
191+ 'data-title ' => wp_kses ( $ pointer ->get_title (), $ kses_title ),
192+ 'data-content ' => wp_kses ( $ content , $ kses_content ),
193+ 'data-position ' => wp_json_encode ( $ pointer ->get_position () ),
147194 )
148195 );
149196 }
0 commit comments