PluginProbe
Polylang / 2.8
Polylang v2.8
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / include / pointer.php

pointer.php in Polylang 2.8, at include/pointer.php

117 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Polylang
4 */
5
6 /**
7 * A class to manage WP pointers
8 * offers the possibility to have customized buttons
9 *
10 * @since 1.7.7
11 * @deprecated 2.3.9
12 */
13 class PLL_Pointer {
14 protected $args;
15
16 /**
17 * Constructor
18 * enqueues the pointer script
19 *
20 * List of parameters accepted in $args:
21 *
22 * pointer => required, unique identifier of the pointer
23 * id => required, the pointer will be attached to this html id
24 * position => optional array, if used both sub parameters are required
25 * edge => 'top' or 'bottom'
26 * align => 'right' or 'left'
27 * width => optional, the width in px
28 * title => required, title
29 * content => required, content
30 * buttons => optional array of arrays, by default the pointer uses the standard dismiss button offered by WP
31 * label => the label of the button
32 * link => optional link for the button. By default, the button just dismisses the pointer
33 *
34 * @since 1.7.7
35 *
36 * @param array $args
37 */
38 public function __construct( $args ) {
39 trigger_error( 'The class PLL_Pointer has been deprecated since Polylang 2.3.9 and will be removed in a future version.', E_USER_ERROR ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions
40
41 $this->args = $args;
42 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
43 }
44
45 /**
46 * Enqueue javascripts and styles if the pointer has not been dismissed
47 *
48 * @since 1.7.7
49 */
50 public function enqueue_scripts() {
51 $dismissed = explode( ',', get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
52 if ( in_array( $this->args['pointer'], $dismissed ) || ! current_user_can( 'manage_options' ) ) {
53 return;
54 }
55
56 // Add pointer javascript
57 add_action( 'admin_print_footer_scripts', array( $this, 'print_js' ) );
58
59 wp_enqueue_style( 'wp-pointer' );
60 wp_enqueue_script( 'wp-pointer' );
61 }
62
63 /**
64 * Adds the javascript of our pointer to the page
65 *
66 * @since 1.7.7
67 */
68 public function print_js() {
69
70 // Add optional buttons
71 if ( ! empty( $this->args['buttons'] ) ) {
72 $b = "
73 var widget = pointer.pointer( 'widget' );
74 var buttons = $( '.wp-pointer-buttons', widget );
75 $( 'a.close', widget ).remove();"; // removes the WP button
76
77 // All the buttons use the standard WP ajax action to remember the pointer has been dismissed
78 foreach ( $this->args['buttons'] as $button ) {
79 $b .= sprintf(
80 "$( '<a>' ).addClass( '%s' ).html( '%s' ).css( 'margin-left', '10px' ).click( function() {
81 $.post( ajaxurl, {
82 pointer: '%s',
83 action: 'dismiss-wp-pointer'
84 }, function( response ) {
85 %s
86 } );
87 } ).appendTo( buttons );",
88 empty( $button['link'] ) ? 'button' : 'button button-primary',
89 esc_html( $button['label'] ),
90 $this->args['pointer'],
91 empty( $button['link'] ) ? "pointer.pointer( 'close' )" : sprintf( "location.href = '%s'", $button['link'] )
92 );
93 }
94 }
95
96 $js = sprintf(
97 "//<![CDATA[
98 jQuery( document ).ready( function( $ ) {
99 var pointer = $( '#%s' ).pointer( {
100 content: '%s',
101 %s
102 %s
103 } );
104 pointer.pointer( 'open' );
105 %s
106 } );
107 // ]]>",
108 $this->args['id'],
109 sprintf( '<h3>%s</h3><p>%s</p>', esc_html( $this->args['title'] ), esc_html( $this->args['content'] ) ),
110 empty( $this->args['position'] ) ? '' : sprintf( 'position: {edge: "%s", align: "%s",},', $this->args['position']['edge'], $this->args['position']['align'] ),
111 empty( $this->args['width'] ) ? '' : sprintf( 'pointerWidth: %d,', $this->args['width'] ),
112 empty( $b ) ? '' : $b
113 );
114 echo '<script type="text/javascript">' . $js . '</script>'; // phpcs:ignore WordPress.Security.EscapeOutput
115 }
116 }
117