PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.6
Kubio AI Page Builder v2.8.6
2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / filters / dismissable-notice.php
kubio / lib / filters Last commit date
after-kubio-activation.php 4 months ago allow-kubio-blog-override.php 2 years ago cache-plugins.php 4 years ago default-editor-overlay.php 1 year ago dismissable-notice.php 1 month ago gutenerg-plugin-check.php 1 year ago image-size-auto-fix.php 1 year ago kubio-fresh-site.php 2 years ago post-insert.php 3 months ago register-meta-fields.php 3 years ago requirements-notices.php 1 year ago site-urls.php 1 year ago starter-sites-feature.php 1 year ago svg-kses.php 1 year ago wp-import.php 2 months ago
dismissable-notice.php
96 lines
1 <?php
2
3 use IlluminateAgnostic\Arr\Support\Arr;
4
5 /**
6 * This function adds an action which hooks into admin_notices and creates a dismissible notices via AJAX.
7 *
8 * @param string $name
9 * @param callable $callback
10 * @param integer $repeat_after - use 0 to disable the reappearance time limit
11 * @param array $params
12 * @param string $classes
13 * @return void
14 */
15 function kubio_add_dismissable_notice( $name, $callback, $repeat_after = 0, $params = array(), $classes = '' ) {
16
17 if ( kubio_dismissable_notice_is_dismissed( $name, $repeat_after ) ) {
18 return;
19 }
20
21 wp_enqueue_script( 'wp-util' );
22 add_action(
23 'admin_notices',
24 function () use ( $name, $params, $callback, $classes ) {
25 $id = 'kubio-notice-' . uniqid();
26 $data = array(
27 'id' => $id,
28 'name' => $name,
29 );
30 ?>
31 <div data-kubio-notice-id="<?php echo esc_attr( $id ); ?>" class="kubio-notice notice is-dismissible <?php echo esc_attr( $classes ); ?>">
32 <?php call_user_func( $callback, $params ); ?>
33 <script>
34 jQuery(function($){
35 var data =<?php echo wp_json_encode( $data ); ?>;
36 $(document).on('click','[data-kubio-notice-id=' + data.id + '] .notice-dismiss',function(){
37 wp.ajax.post('kubio-dismissable-notice--dismiss',{
38 kubio_notice_name:data.name,
39 _wpnonce: '<?php echo esc_html( wp_create_nonce( 'kubio-dismissable-notice--dismiss-nonce' ) ); ?>'
40 });
41 });
42 });
43 </script>
44 </div>
45
46 <?php
47
48 $notices = get_option( '_kubio_dismissable_notices', array() );
49 $notices[ $name ] = array( 'dismiss_time' => 0 );
50 update_option( '_kubio_dismissable_notices', $notices );
51 }
52 );
53 }
54
55 /**
56 * This is an ajax callback which marks notices as dismissed.
57 *
58 * @return void
59 */
60 function _kubio_dismiss_dismissable_notice() {
61 check_ajax_referer( 'kubio-dismissable-notice--dismiss-nonce' );
62 $notice = Arr::get( $_REQUEST, 'kubio_notice_name', false );
63 $notices = get_option( '_kubio_dismissable_notices', array() );
64
65 if ( $notice && Arr::exists( $notices, $notice ) ) {
66 $notices[ $notice ] = array( 'dismiss_time' => time() );
67 update_option( '_kubio_dismissable_notices', $notices );
68 }
69 }
70
71 /**
72 * Checks if a named Kubio notice is dismissed at this moment.
73 * @param $name
74 * @param $repeat_after
75 * @return bool
76 */
77 function kubio_dismissable_notice_is_dismissed( $name, $repeat_after = 0 ) {
78 $notices = get_option( '_kubio_dismissable_notices', array() );
79
80 if ( Arr::has( $notices, $name ) ) {
81
82 $dismissed_time = Arr::get( $notices, "{$name}.dismiss_time", 0 );
83
84 if ( $repeat_after === 0 && $dismissed_time !== 0 ) {
85 return true;
86 }
87
88 if ( $dismissed_time && time() < $dismissed_time + $repeat_after ) {
89 return true;
90 }
91 }
92 return false;
93 }
94
95 add_action( 'wp_ajax_kubio-dismissable-notice--dismiss', '_kubio_dismiss_dismissable_notice' );
96