PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.6.3
Kubio AI Page Builder v2.6.3
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 1 year 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 year 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 1 year 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 1 year ago
dismissable-notice.php
95 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 add_action(
22 'admin_notices',
23 function () use ( $name, $params, $callback, $classes ) {
24 $id = 'kubio-notice-' . uniqid();
25 $data = array(
26 'id' => $id,
27 'name' => $name,
28 );
29 ?>
30 <div data-kubio-notice-id="<?php echo esc_attr( $id ); ?>" class="notice is-dismissible <?php echo esc_attr( $classes ); ?>">
31 <?php call_user_func( $callback, $params ); ?>
32 <script>
33 jQuery(function($){
34 var data =<?php echo wp_json_encode( $data ); ?>;
35 $(document).on('click','[data-kubio-notice-id=' + data.id + '] .notice-dismiss',function(){
36 wp.ajax.post('kubio-dismissable-notice--dismiss',{
37 kubio_notice_name:data.name,
38 _wpnonce: '<?php echo esc_html( wp_create_nonce( 'kubio-dismissable-notice--dismiss-nonce' ) ); ?>'
39 });
40 });
41 });
42 </script>
43 </div>
44
45 <?php
46
47 $notices = get_option( '_kubio_dismissable_notices', array() );
48 $notices[ $name ] = array( 'dismiss_time' => 0 );
49 update_option( '_kubio_dismissable_notices', $notices );
50 }
51 );
52 }
53
54 /**
55 * This is an ajax callback which marks notices as dismissed.
56 *
57 * @return void
58 */
59 function _kubio_dismiss_dismissable_notice() {
60 check_ajax_referer( 'kubio-dismissable-notice--dismiss-nonce' );
61 $notice = Arr::get( $_REQUEST, 'kubio_notice_name', false );
62 $notices = get_option( '_kubio_dismissable_notices', array() );
63
64 if ( $notice && Arr::exists( $notices, $notice ) ) {
65 $notices[ $notice ] = array( 'dismiss_time' => time() );
66 update_option( '_kubio_dismissable_notices', $notices );
67 }
68 }
69
70 /**
71 * Checks if a named Kubio notice is dismissed at this moment.
72 * @param $name
73 * @param $repeat_after
74 * @return bool
75 */
76 function kubio_dismissable_notice_is_dismissed( $name, $repeat_after = 0 ) {
77 $notices = get_option( '_kubio_dismissable_notices', array() );
78
79 if ( Arr::has( $notices, $name ) ) {
80
81 $dismissed_time = Arr::get( $notices, "{$name}.dismiss_time", 0 );
82
83 if ( $repeat_after === 0 && $dismissed_time !== 0 ) {
84 return true;
85 }
86
87 if ( $dismissed_time && time() < $dismissed_time + $repeat_after ) {
88 return true;
89 }
90 }
91 return false;
92 }
93
94 add_action( 'wp_ajax_kubio-dismissable-notice--dismiss', '_kubio_dismiss_dismissable_notice' );
95