PluginProbe ʕ •ᴥ•ʔ
YITH WooCommerce Wishlist / 4.0.1
YITH WooCommerce Wishlist v4.0.1
trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.17 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.18 3.0.19 3.0.2 3.0.20 3.0.21 3.0.22 3.0.23 3.0.25 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.10.0 3.11.0 3.12.0 3.13.0 3.14.0 3.15.0 3.16.0 3.17.0 3.18.0 3.19.0 3.2.0 3.20.0 3.21.0 3.22.0 3.23.0 3.24.0 3.25.0 3.26.0 3.27.0 3.28.0 3.29.0 3.3.0 3.30.0 3.31.0 3.32.0 3.33.0 3.34.0 3.35.0 3.36.0 3.37.0 3.38.0 3.4.0 3.5.0 3.6.0 3.7.0 3.8.0 3.9.0 4.0.0 4.0.1 4.1.0 4.10.0 4.10.1 4.10.2 4.11.0 4.12.0 4.13.0 4.14.0 4.15.0 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.8.0 4.9.0
yith-woocommerce-wishlist / plugin-fw / includes / class-yit-pointers.php
yith-woocommerce-wishlist / plugin-fw / includes Last commit date
builders 2 years ago privacy 2 years ago class-yit-ajax.php 2 years ago class-yit-assets.php 2 years ago class-yit-cpt-unlimited.php 5 years ago class-yit-gradients.php 2 years ago class-yit-help-desk.php 2 years ago class-yit-icons.php 2 years ago class-yit-metabox.php 2 years ago class-yit-plugin-common.php 5 years ago class-yit-plugin-licence.php 2 years ago class-yit-plugin-panel-woocommerce.php 1 year ago class-yit-plugin-panel.php 1 year ago class-yit-plugin-subpanel.php 2 years ago class-yit-pointers.php 2 years ago class-yit-theme-licence.php 2 years ago class-yit-upgrade.php 5 years ago class-yit-video.php 5 years ago class-yith-bh-onboarding.php 3 years ago class-yith-dashboard.php 4 years ago class-yith-debug.php 2 years ago class-yith-external-services.php 1 year ago class-yith-post-type-admin.php 2 years ago class-yith-system-status.php 1 year ago
class-yit-pointers.php
381 lines
1 <?php
2 /**
3 * YITH Pointers Class.
4 *
5 * @class YIT_Pointers
6 * @author YITH <plugins@yithemes.com>
7 * @package YITH\PluginFramework\Classes
8 */
9
10 defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
11
12 if ( ! class_exists( 'YIT_Pointers' ) ) {
13 /**
14 * YIT_Pointers class.
15 * Initializes the pointers.
16 */
17 class YIT_Pointers {
18
19 /**
20 * The single instance of the class.
21 *
22 * @var YIT_Pointers
23 */
24 private static $instance;
25
26 /**
27 * The screen IDs.
28 *
29 * @var array
30 */
31 public $screen_ids = array();
32
33 /**
34 * The pointers.
35 *
36 * @var array
37 */
38 public $pointers = array();
39
40 /**
41 * Special Screen Ids that require a particular action
42 *
43 * @var array|mixed|void
44 */
45 public $special_screen = array();
46
47 /**
48 * Default pointers.
49 *
50 * @var array|mixed
51 */
52 protected $default_pointer = array();
53
54 /**
55 * The default position
56 *
57 * @var string[]
58 */
59 protected $default_position = array(
60 'edge' => 'left',
61 'align' => 'center',
62 );
63
64 /**
65 * Singleton implementation.
66 *
67 * @return YIT_Pointers
68 */
69 public static function instance() {
70 return ! is_null( self::$instance ) ? self::$instance : self::$instance = new self();
71 }
72
73 /**
74 * Construct
75 *
76 * @since 1.0
77 */
78 private function __construct() {
79
80 $title = __( 'Plugins Activated', 'yith-plugin-fw' );
81 $message = __( 'From now on, you can find all plugin options in YITH menu. Plugin customization settings will be available as a new entry in YITH menu.', 'yith-plugin-fw' );
82 $discover_message = sprintf(
83 // translators: 1. YITH site link; 2. WordPress site link.
84 __( 'Discover all our plugins available on: %1$s and %2$s', 'yith-plugin-fw' ),
85 '<a href="https://yithemes.com/product-category/plugins/" target="_blank">yithemes.com</a>',
86 '<a href="https://profiles.wordpress.org/yithemes/" target="_blank">Wordpress.org</a>'
87 );
88
89 $this->default_pointer['plugins'] = array(
90 'screen_id' => 'plugins',
91 'options' => array(
92 'content' => "<h3>{$title}</h3><p>{$message}</p><p>{$discover_message}</p>",
93 ),
94 );
95
96 $title = __( 'Plugins Upgraded', 'yith-plugin-fw' );
97 $message = __( 'From now on, you can find the option panel of YITH plugins in YITH menu. Every time one of our plugins is added, a new entry will be added to this menu. For example, after the update, plugin options (such as for YITH WooCommerce Wishlist, YITH WooCommerce Ajax Search, etc.) will be moved from previous location to YITH menu.', 'yith-plugin-fw' );
98 $discover_message = sprintf(
99 // translators: 1. YITH site link; 2. WordPress site link.
100 __( 'Discover all our plugins available on: %1$s and %2$s', 'yith-plugin-fw' ),
101 '<a href="https://yithemes.com/product-category/plugins/" target="_blank">yithemes.com</a>',
102 '<a href="https://profiles.wordpress.org/yithemes/" target="_blank">Wordpress.org</a>'
103 );
104
105 $this->default_pointer['update'] = array(
106 'screen_id' => 'update',
107 'options' => array(
108 'content' => "<h3>{$title}</h3><p>{$message}</p><p>{$discover_message}</p>",
109 ),
110 );
111
112 $this->default_pointer = $this->parse_args( $this->default_pointer );
113
114 // DEPRECATED 'yit-pointer-special-screen' filter since 3.5 | use yith_plugin_fw_pointers_special_screens instead.
115 $this->special_screen = apply_filters( 'yit-pointer-special-screen', array( 'plugins', 'update' ) ); //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
116 $this->special_screen = apply_filters( 'yith_plugin_fw_pointers_special_screens', array( 'plugins', 'update' ) );
117
118 add_action( 'admin_enqueue_scripts', array( $this, 'pointer_load' ) );
119 add_action( 'admin_init', array( $this, 'add_pointers' ), 100 );
120 }
121
122 /**
123 * Parse args for the default pointer.
124 *
125 * @param array $args The arguments to be parse.
126 *
127 * @return array
128 */
129 public function parse_args( $args ) {
130 $default = array(
131 'pointer_id' => 'yith_default_pointer',
132 'target' => '#toplevel_page_yit_plugin_panel',
133 'init' => null,
134 );
135
136 foreach ( $args as $id => $pointer ) {
137 $args[ $id ] = wp_parse_args( $pointer, $default );
138 $args[ $id ]['options']['position'] = $this->default_position;
139 }
140
141 return $args;
142 }
143
144 /**
145 * Add pointers
146 */
147 public function add_pointers() {
148 if ( ! empty( $this->screen_ids ) ) {
149 foreach ( $this->screen_ids as $screen_id ) {
150 add_filter( "yit_pointers-{$screen_id}", array( $this, 'pointers' ) );
151 }
152 }
153 }
154
155 /**
156 * Register pointers.
157 *
158 * @param array $pointers The pointers.
159 */
160 public function register( $pointers ) {
161 foreach ( $pointers as $id => $pointer ) {
162 $pointer_id = isset( $pointer['pointer_id'] ) ? $pointer['pointer_id'] : false;
163 $target = isset( $pointer['target'] ) ? $pointer['target'] : false;
164 $content = isset( $pointer['content'] ) ? $pointer['content'] : false;
165 $position = isset( $pointer['position'] ) ? $pointer['position'] : false;
166 $screen_id = isset( $pointer['screen_id'] ) ? $pointer['screen_id'] : false;
167 $init = isset( $pointer['init'] ) ? $pointer['init'] : false;
168
169 if ( ! $pointer_id || ! $target || ! $content || ! $position || ! $screen_id ) {
170 continue;
171 }
172
173 if ( ! in_array( $screen_id, $this->screen_ids, true ) ) {
174 $this->screen_ids[] = $screen_id;
175 }
176
177 $this->pointers[ $screen_id ][ $pointer_id ] = array(
178 'target' => $target,
179 'options' => array(
180 'content' => $content,
181 'position' => $position,
182 ),
183 'init' => $init,
184 );
185 }
186 }
187
188 /**
189 * Retrieve the registered pointers array where the keys will be the plugin init(s).
190 *
191 * @param string $screen_id The screen ID.
192 *
193 * @return array
194 */
195 public function get_plugins_init( $screen_id ) {
196
197 $registered = array();
198
199 foreach ( $this->pointers[ $screen_id ] as $pointer_id => $pointer ) {
200 $registered[ $pointer['init'] ] = $pointer_id;
201 }
202
203 return $registered;
204 }
205
206 /**
207 * Load the pointer.
208 *
209 * @param bool $deprecated Deprecated param.
210 */
211 public function pointer_load( $deprecated = false ) {
212 // phpcs:disable WordPress.Security.NonceVerification.Recommended
213 // phpcs:disable WordPress.Security.NonceVerification.Missing
214
215 // Retrieve the pointers for the current screen.
216 $screen = get_current_screen();
217 $pointers = apply_filters( "yit_pointers-{$screen->id}", array() ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
218
219 if ( ! $pointers || ! is_array( $pointers ) ) {
220 return;
221 }
222
223 // Get dismissed pointers.
224 $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
225 $valid_pointers = array();
226
227 // Show pointers only on plugin activate action.
228 if ( in_array( $screen->id, $this->special_screen, true ) ) {
229 $show = false;
230 $registered = $this->get_plugins_init( $screen->id );
231 $recently_activate = get_option( 'yit_recently_activated', array() );
232
233 // For "plugins" screen.
234 $is_single_activate = isset( $_GET['activate'] ) && 'true' === $_GET['activate'];
235 $is_multi_activate = isset( $_GET['activate-multi'] ) && 'true' === $_GET['activate-multi'];
236
237 /**
238 * For "update" screen
239 * Single plugin update use GET method
240 * Multi update plugins with bulk action send two post args called "action" and "action2"
241 * action refer to first bulk action button (at the top of plugins table)
242 * action2 refer to last bulk action button (at the bottom of plugins table)
243 */
244 $is_single_upgrade = isset( $_GET['action'] ) && 'upgrade-plugin' === $_GET['action'];
245 $is_multi_upgrade = ( isset( $_POST['action'] ) && 'update-selected' === $_POST['action'] ) || ( isset( $_POST['action2'] ) && 'update-selected' === $_POST['action2'] );
246
247 if ( $is_single_activate || $is_single_upgrade ) {
248 foreach ( $registered as $init => $p_id ) {
249 if ( in_array( $init, $recently_activate, true ) ) {
250 $point_id = $p_id;
251 $pointer = $pointers[ $point_id ];
252
253 if ( ! ( in_array( $point_id, $dismissed, true ) || empty( $pointer ) || empty( $point_id ) || empty( $pointer['target'] ) || empty( $pointer['options'] ) ) ) {
254 $pointer['pointer_id'] = $point_id;
255 $valid_pointers['pointers'][] = $pointer;
256 $show = true;
257 }
258 break;
259 }
260 }
261 } elseif ( $is_multi_activate || $is_multi_upgrade ) {
262 $point_id = array();
263 $screen_id = $screen->id;
264
265 if ( $is_multi_upgrade && isset( $_POST['checked'] ) && ( count( $_POST['checked'] ) > 0 ) ) {
266 $recently_activate = sanitize_file_name( wp_unslash( $_POST['checked'] ) );
267 $screen_id = 'update';
268 $pointers = apply_filters( "yit_pointers-{$screen_id}", array() ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
269 }
270
271 foreach ( $registered as $init => $p_id ) {
272 if ( in_array( $init, $recently_activate, true ) ) {
273 $point_id[] = $p_id;
274 }
275 }
276
277 /**
278 * Bulk Action: Activate Plugins
279 * count( $point_id ) is the number of YITH plugins that have registered specific pointers
280 * case 0 -> No pointers -> Exit
281 * case 1 -> Only one pointers to show -> Use the specific plugin pointer
282 * default -> Two or more plugins need to show a pointer -> use a generic pointers
283 */
284 switch ( count( $point_id ) ) {
285 case 0:
286 $show = false;
287 break;
288
289 case 1:
290 $point_id = array_pop( $point_id );
291 $pointer = $pointers[ $point_id ];
292 if ( ! ( in_array( $point_id, $dismissed, true ) || empty( $pointer ) || empty( $point_id ) || empty( $pointer['target'] ) || empty( $pointer['options'] ) ) ) {
293 $pointer['pointer_id'] = $point_id;
294 $valid_pointers['pointers'][] = $pointer;
295 $show = true;
296 }
297 break;
298
299 default:
300 $valid_pointers['pointers'][] = $this->default_pointer[ $screen_id ];
301 $show = true;
302 break;
303 }
304 }
305
306 update_option( 'yit_recently_activated', array() );
307
308 if ( ! $show ) {
309 return;
310 }
311 } else {
312 // Check pointers and remove dismissed ones.
313 foreach ( $pointers as $pointer_id => $pointer ) {
314
315 if ( in_array( $pointer_id, $dismissed, true ) || empty( $pointer ) || empty( $pointer_id ) || empty( $pointer['target'] ) || empty( $pointer['options'] ) ) {
316 continue;
317 }
318
319 $pointer['pointer_id'] = $pointer_id;
320
321 $valid_pointers['pointers'][] = $pointer;
322 }
323 }
324
325 if ( empty( $valid_pointers ) ) {
326 return;
327 }
328
329 $script_file = function_exists( 'yit_load_js_file' ) ? yit_load_js_file( 'yit-wp-pointer.js' ) : 'yit-wp-pointer.min.js';
330
331 // Enqueue pointer scripts and styles.
332 wp_enqueue_style( 'wp-pointer' );
333 wp_enqueue_script( 'wp-pointer' );
334
335 wp_enqueue_script( 'yit-wp-pointer', YIT_CORE_PLUGIN_URL . '/assets/js/' . $script_file, array( 'wp-pointer' ), yith_plugin_fw_get_version(), true );
336 wp_localize_script( 'yit-wp-pointer', 'custom_pointer', $valid_pointers );
337
338 // phpcs:enable
339 }
340
341 /**
342 * Filter pointers.
343 *
344 * @param array $pointers The pointers.
345 *
346 * @return array
347 */
348 public function pointers( $pointers ) {
349 $screen_id = str_replace( 'yit_pointers-', '', current_filter() );
350 $pointers_to_add = $this->get_pointers( $screen_id );
351
352 return ! empty( $pointers_to_add ) ? array_merge( $pointers, $pointers_to_add ) : $pointers;
353 }
354
355 /**
356 * Retrieve pointers for the specified screen ID.
357 *
358 * @param string $screen_id The Screen ID.
359 *
360 * @return array|mixed
361 */
362 public function get_pointers( $screen_id ) {
363 return isset( $this->pointers[ $screen_id ] ) ? $this->pointers[ $screen_id ] : array();
364 }
365 }
366 }
367
368 if ( ! function_exists( 'YIT_Pointers' ) ) {
369
370 /**
371 * Single instance of YIT_Pointers
372 *
373 * @return YIT_Pointers
374 */
375 function YIT_Pointers() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
376 return YIT_Pointers::instance();
377 }
378 }
379
380 YIT_Pointers();
381