PluginProbe
Polylang / 2.7
Polylang v2.7
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.7, at include/pointer.php

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