PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
← All changes | inc/admin/class-lp-admin-notice.php +5 -412 4.2.04.4.8 View file →
@@ -47,53 +47,8 @@
47 47 */
48 48 protected $option_id = 'lp_admin_notices';
49 49
50 50 /**
51 - * @var string
52 - */
53 - protected $dismissed_option_id = 'lp_admin_dismissed_notices';
54 -
55 - /**
56 - * LP_Admin_Notice construct
57 - */
58 - protected function __construct() {
59 - //add_action( 'init', array( $this, 'dismiss_notice' ) );
60 - //add_action( 'init', array( $this, 'load' ) );
61 - //add_action( 'admin_notices', array( $this, 'admin_notices' ) );
62 - }
63 -
64 - /**
65 - * Show notices in admin
66 - *
67 - * @return void
68 - * @deprecated 4.1.7.3.2
69 - */
70 - public function admin_notices() {
71 - try {
72 - $rules = [
73 - 'check_right_plugin_base' => [
74 - 'class' => 'notice-error',
75 - 'template' => 'admin-notices/wrong-name-plugin.php',
76 - 'display' => call_user_func( [ $this, 'check_right_plugin_base' ] ),
77 - ],
78 - 'notices' => [
79 - 'class' => 'notice-error',
80 - 'template' => 'admin-notices/wrong-name-plugin.php',
81 - 'display' => call_user_func( [ $this, 'check_right_plugin_base' ] ),
82 - ],
83 - ];
84 -
85 - foreach ( $rules as $rule => $template_data ) {
86 - if ( $template_data['display'] ) {
87 - learn_press_admin_view( $template_data['template'] ?? '', [ 'data' => $template_data ], true );
88 - }
89 - }
90 - } catch ( Throwable $e ) {
91 - error_log( $e->getMessage() );
92 - }
93 - }
94 -
95 - /**
96 51 * Check is right plugin base.
97 52 *
98 53 * @return bool
99 54 */
@@ -175,32 +130,15 @@
175 130 $test_url = add_query_arg( 'lp_test_wp_remote', 1, home_url() );
176 131 $args = [
177 132 'timeout' => 30,
178 133 ];
179 - $result = wp_safe_remote_get( $test_url, $args );
134 + $result = wp_remote_post( $test_url, $args );
180 135 $body = ! is_wp_error( $result ) ? wp_remote_retrieve_body( $result ) : $result;
181 136
182 - return $body === '[TEST_REMOTE]' ? true : $result;
137 + return $body === '[TEST_REMOTE]' ? true : $body;
183 138 }
184 139
185 140 /**
186 - * @deprecated 4.1.7.3.2
187 - */
188 - /*public function load() {
189 - $notices = get_option( $this->option_id );
190 -
191 - if ( ! $notices ) {
192 - return false;
193 - }
194 -
195 - $this->notices = array_merge( $notices, $this->notices );
196 -
197 - delete_option( $this->option_id );
198 -
199 - return true;
200 - }*/
201 -
202 - /**
203 141 * Add new notice to show in admin page.
204 142 *
205 143 * @since 3.2.6
206 144 *
@@ -211,10 +149,13 @@
211 149 * @param bool $redirect
212 150 * @param bool $override
213 151 *
214 152 * @return boolean
153 + * @deprecated 4.2.5
215 154 */
216 155 public function add( $message, $type = 'success', $dismissible = true, $id = '', $redirect = false, $override = false ) {
156 + _deprecated_function( __METHOD__, '4.2.5' );
157 + return false;
217 158 if ( ! $id ) {
218 159 $id = uniqid();
219 160 }
220 161
@@ -232,84 +173,8 @@
232 173 return false;
233 174 }
234 175
235 176 /**
236 - * @param string|WP_Error $message
237 - * @param string $type
238 - * @param bool $dismissible
239 - * @param string $id
240 - * @param bool $override
241 - *
242 - * @return bool
243 - */
244 - public function add_redirect( $message, $type = 'success', $dismissible = false, $id = '', $override = false ) {
245 - return $this->add( $message, $type, $dismissible, $id, true, $override );
246 - }
247 -
248 - /**
249 - * Show all notices.
250 - *
251 - * @return bool
252 - */
253 - public function show_notices() {
254 - if ( empty( $this->notices ) ) {
255 - return false;
256 - }
257 -
258 - $redirect_notices = array();
259 -
260 - foreach ( $this->notices as $id => $notice ) {
261 - $notice['message'] = $notice['message'] instanceof WP_Error ? $notice['message']->get_error_message() : $notice['message'];
262 -
263 - if ( $notice['redirect'] ) {
264 - $notice['redirect'] = false;
265 - $redirect_notices[ $id ] = $notice;
266 - } else {
267 - if ( ! $this->has_dismissed_notice( $id ) ) {
268 - if ( preg_match( '/.php$/', $notice['message'] ) ) {
269 - $view = $notice['message'];
270 - } else {
271 - $view = 'admin-notice.php';
272 - }
273 -
274 - learn_press_admin_view( $view, array_merge( $notice, array( 'id' => $id ) ) );
275 - }
276 - }
277 - }
278 -
279 - if ( $redirect_notices ) {
280 - update_option( $this->option_id, $redirect_notices );
281 - }
282 -
283 - return true;
284 - }
285 -
286 - /**
287 - * Check if a notice is already added by id.
288 - *
289 - * @since 3.2.6
290 - *
291 - * @param string[] $notice
292 - *
293 - * @return bool
294 - */
295 - public function has_notice( $notice ) {
296 - settype( $notice, 'array' );
297 -
298 - if ( ! $this->notices ) {
299 - return false;
300 - }
301 -
302 - foreach ( $notice as $id ) {
303 - if ( ! empty( $this->notices[ $id ] ) ) {
304 - return true;
305 - }
306 - }
307 -
308 - return false;
309 - }
310 -
311 - /**
312 177 * Remove one or more notices from queue by ids.
313 178 *
314 179 * @since 3.2.6
315 180 *
@@ -352,280 +217,8 @@
352 217 */
353 218 public function clear() {
354 219 $this->notices = array();
355 220 delete_option( $this->option_id );
356 - }
357 -
358 - /**
359 - * @since 3.2.6
360 - */
361 - /*public function dismiss_notice() {
362 - $id = LP_Request::get( 'lp-dismiss-notice' );
363 -
364 - if ( ! $id ) {
365 - return;
366 - }
367 -
368 - $dismissed = get_option( $this->dismissed_option_id );
369 -
370 - if ( ! $dismissed ) {
371 - $dismissed = array();
372 - }
373 -
374 - do_action( 'learn-press/before-dismiss-notice', $id );
375 -
376 - if ( array_search( $id, $dismissed ) === false ) {
377 - $dismissed[] = $id;
378 - update_option( $this->dismissed_option_id, $dismissed );
379 - }
380 -
381 - do_action( 'learn-press/dismissed-notice', $id );
382 -
383 - learn_press_send_json(
384 - apply_filters(
385 - 'learn-press/dismissed-notice-response',
386 - array(
387 - 'dismissed' => $id,
388 - ),
389 - $id
390 - )
391 - );
392 - }*/
393 -
394 - /**
395 - * Update option to turn-off a notice.
396 - *
397 - * @since 3.2.6
398 - *
399 - * @param string $name
400 - * @param string $value
401 - * @param int $expired
402 - * @deprecated 4.1.7.3.2
403 - */
404 - public function dismiss_notice_2( $name, $value, $expired = 0 ) {
405 - if ( $expired ) {
406 - set_transient( 'lp_dismiss_notice' . $name, $value, $expired );
407 - } else {
408 - $values = get_option( 'lp_dismiss_notice' );
409 - if ( ! $values ) {
410 - $values = array( $name => $value );
411 - } else {
412 - $values[ $name ] = $value;
413 - }
414 -
415 - update_option( 'lp_dismiss_notice', $values );
416 - }
417 - }
418 -
419 - /**
420 - * Check if a notice has dismissed.
421 - *
422 - * @since 3.2.6
423 - *
424 - * @param string $name
425 - *
426 - * @return bool
427 - * @deprecated 4.1.7.3.2
428 - */
429 - public function has_dismissed_notice( $name ) {
430 -
431 - $dismissed = get_option( $this->dismissed_option_id );
432 -
433 - if ( ! $dismissed ) {
434 - return false;
435 - }
436 -
437 - return array_search( $name, $dismissed ) !== false;
438 - }
439 -
440 - /**
441 - * Restore dismissed notices by id.
442 - *
443 - * @since 3.2.6
444 - *
445 - * @param string[] $notice
446 - *
447 - * @return bool
448 - * @deprecated 4.1.7.3.2
449 - */
450 - public function restore_dismissed_notice( $notice ) {
451 - $dismissed = get_option( $this->dismissed_option_id );
452 -
453 - if ( ! $dismissed ) {
454 - return false;
455 - }
456 -
457 - settype( $notice, 'array' );
458 -
459 - foreach ( $notice as $id ) {
460 - $at = array_search( $id, $dismissed );
461 -
462 - if ( false !== $at ) {
463 - unset( $dismissed[ $at ] );
464 - }
465 - }
466 -
467 - update_option( $this->dismissed_option_id, $dismissed );
468 -
469 - return true;
470 - }
471 -
472 - /**
473 - * Clear all notices has dismissed.
474 - *
475 - * @since 3.2.6
476 - * @deprecated 4.1.7.3.2
477 - */
478 - public function clear_dismissed_notice() {
479 - delete_option( $this->dismissed_option_id );
480 - }
481 -
482 - /**
483 - * Remove a notice has been dismissed.
484 - *
485 - * @since 3.2.6
486 - *
487 - * @param string|array $name - Optional. NULL will remove all notices.
488 - * @param bool $expired - Optional. TRUE if dismiss notice as transient (in case $name passed).
489 - *
490 - * @return bool
491 - * @deprecated 4.1.7.3.2
492 - */
493 - public function remove_dismissed_notice( $name = '' ) {
494 - if ( ! $name ) {
495 - global $wpdb;
496 -
497 - $query = $wpdb->prepare( "SELECT SUBSTR(option_name, 12) FROM {$wpdb->options} WHERE option_name LIKE %s", '%' . $wpdb->esc_like( '_transient_lp_dismiss_notice' ) . '%' );
498 -
499 - $all_notices = $wpdb->get_col( $query );
500 -
501 - if ( $all_notices ) {
502 - foreach ( $all_notices as $notice ) {
503 - delete_transient( $notice );
504 - }
505 - }
506 -
507 - delete_option( 'lp_dismiss_notice' );
508 -
509 - return true;
510 -
511 - } elseif ( is_array( $name ) ) {
512 - foreach ( $name as $notice ) {
513 - $this->remove_dismissed_notice( $notice );
514 - }
515 -
516 - return true;
517 - }
518 -
519 - delete_transient( 'lp_dismiss_notice' . $name );
520 -
521 - $values = get_option( 'lp_dismiss_notice' );
522 -
523 - if ( ! $values ) {
524 - return false;
525 - } else {
526 - if ( array_key_exists( $name, $values ) ) {
527 - unset( $values[ $name ] );
528 -
529 - update_option( 'lp_dismiss_notice', $values );
530 -
531 - return $values;
532 - }
533 - }
534 -
535 - return false;
536 - }
537 -
538 - /**
539 - * @deprecated 3.2.6
540 - */
541 - public function dismiss_notice_deprecated() {
542 - $notice = learn_press_get_request( 'lp-hide-notice' );
543 -
544 - if ( ! $notice ) {
545 - return;
546 - }
547 -
548 - $transient = learn_press_get_request( 't' );
549 -
550 - if ( $transient ) {
551 - set_transient( 'lp-hide-notice-' . $notice, 'yes', $transient );
552 - } else {
553 - learn_press_update_user_option( 'hide-notice-' . $notice, 'yes' );
554 - }
555 -
556 - $redirect = apply_filters( 'learn_press_hide_notice_redirect', esc_url_raw( remove_query_arg( 'lp-hide-notice' ) ) );
557 - if ( $redirect ) {
558 - wp_redirect( untrailingslashit( $redirect ) );
559 - exit();
560 - }
561 - }
562 -
563 - /**
564 - * Add new notice to queue
565 - *
566 - * @deprecated 3.2.6
567 - *
568 - * @param string $message The message want to display
569 - * @param string $type The class name of WP message type updated|update-nag|error
570 - * @param string $id Custom id for html element's ID
571 - * @param bool
572 - */
573 - public static function add_deprecated( $message, $type = 'success', $id = '', $redirect = false ) {
574 - if ( $redirect ) {
575 - $notices = get_transient( 'learn_press_redirect_notices' );
576 - if ( empty( $notices ) ) {
577 - $notices = array();
578 - }
579 - $notices[] = array(
580 - 'type' => $type,
581 - 'message' => $message,
582 - 'id' => $id,
583 - );
584 - set_transient( 'learn_press_redirect_notices', $notices );
585 - } else {
586 - self::$_notices[] = array(
587 - 'type' => $type,
588 - 'message' => $message,
589 - 'id' => $id,
590 - );
591 - }
592 - }
593 -
594 - /**
595 - * @deprecated 4.1.7.3.2
596 - */
597 - public static function add_redirect_reprecated( $message, $type = 'updated', $id = '' ) {
598 - self::add( $message, $type, $id, true );
599 - }
600 -
601 - /**
602 - * Show all notices has registered
603 - *
604 - * @deprecated 3.2.6
605 - */
606 - public static function show_notices_deprecated() {
607 - /*if ( self::$_notices ) {
608 - foreach ( self::$_notices as $notice ) {
609 - if ( empty( $notice ) ) {
610 - continue;
611 - }
612 - learn_press_admin_view( 'admin-notice.php', $notice );
613 - }
614 - }
615 -
616 - $notices = get_transient( 'learn_press_redirect_notices' );
617 - if ( $notices ) {
618 - foreach ( $notices as $notice ) {
619 - if ( empty( $notice ) ) {
620 - continue;
621 - }
622 -
623 - learn_press_admin_view( 'admin-notice.php', $notice );
624 - }
625 -
626 - delete_transient( 'learn_press_redirect_notices' );
627 - }*/
628 221 }
629 222
630 223 /**
631 224 * Get single instance of this class