PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 3.5.3
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v3.5.3
4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / vendor / priyomukul / wp-notice / src / Dismiss.php
embedpress / vendor / priyomukul / wp-notice / src Last commit date
Utils 4 years ago Dismiss.php 4 years ago Notice.php 4 years ago Notices.php 4 years ago
Dismiss.php
151 lines
1 <?php
2
3 namespace PriyoMukul\WPNotice;
4
5 use PriyoMukul\WPNotice\Utils\Base;
6 use PriyoMukul\WPNotice\Utils\Helper;
7 use PriyoMukul\WPNotice\Utils\Storage;
8
9 class Dismiss extends Base {
10 use Helper;
11
12 private $id;
13 private $scope = 'user';
14 private $app = null;
15 private $hook = null;
16
17 public function __construct( $id, $options, $app ){
18 $this->id = $id;
19 $this->app = $app;
20
21 if( ! empty( $options ) ) {
22 foreach( $options as $key => $_value ) {
23 $this->{$key} = $_value;
24 }
25 }
26
27 $this->hook = $this->app->app .'_wpnotice_dismiss_notice';
28
29 add_action( 'wp_ajax_'. $this->hook, [ $this, 'ajax_maybe_dismiss_notice' ] );
30 }
31
32 /**
33 * Print the script for dismissing the notice.
34 *
35 * @access public
36 * @since 1.0
37 * @return void
38 */
39 public function print_script() {
40 $nonce = wp_create_nonce( 'wpnotice_dismiss_notice_' . $this->id );
41 $_id = '#wpnotice-' . esc_attr( $this->app->app ) . '-' . esc_attr( $this->id );
42 ?>
43 <script>
44 window.addEventListener( 'load', function() {
45 var dismissBtn = document.querySelector( '<?php echo $_id ?> .notice-dismiss' );
46 var extraDismissBtn = document.querySelectorAll( '<?php echo $_id ?> .dismiss-btn' );
47
48 function wpNoticeDismissFunc( event ) {
49 event.preventDefault();
50
51 var httpRequest = new XMLHttpRequest(),
52 postData = '',
53 dismiss = event.target.dataset?.hasOwnProperty('dismiss') && event.target.dataset.dismiss || false,
54 later = event.target.dataset?.hasOwnProperty('later') && event.target.dataset.later || false;
55
56 if( dismiss || later ) {
57 jQuery(event.target.offsetParent).slideUp(200);
58 }
59
60 // Data has to be formatted as a string here.
61 postData += 'id=<?php echo esc_attr( rawurlencode( $this->id ) ); ?>';
62 postData += '&action=<?php echo esc_attr( $this->hook ); ?>';
63 if( dismiss ) {
64 postData += '&dismiss=' + dismiss;
65 }
66 if( later ) {
67 postData += '&later=' + later;
68 }
69
70 postData += '&nonce=<?php echo esc_html( $nonce ); ?>';
71
72 httpRequest.open( 'POST', '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>' );
73 httpRequest.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
74 httpRequest.send( postData );
75 }
76
77 // Add an event listener to the dismiss button.
78 dismissBtn && dismissBtn.addEventListener( 'click', wpNoticeDismissFunc);
79 if( extraDismissBtn.length > 0 ) {
80 extraDismissBtn.forEach( btn => btn.addEventListener( 'click', wpNoticeDismissFunc))
81 }
82 });
83 </script>
84 <?php
85 }
86
87
88 /**
89 * Run check to see if we need to dismiss the notice.
90 * If all tests are successful then call the dismiss_notice() method.
91 *
92 * @access public
93 * @since 1.0
94 * @return void
95 */
96 public function ajax_maybe_dismiss_notice() {
97 // Sanity check: Early exit if we're not on a wptrt_dismiss_notice action.
98 if ( ! isset( $_POST['action'] ) || $this->hook !== $_POST['action'] ) {
99 return;
100 }
101
102 // Sanity check: Early exit if the ID of the notice is not the one from this object.
103 if ( ! isset( $_POST['id'] ) || $this->id !== $_POST['id'] ) {
104 return;
105 }
106
107 // Security check: Make sure nonce is OK.
108 check_ajax_referer( 'wpnotice_dismiss_notice_' . $this->id, 'nonce', true );
109
110 if( isset( $_POST['later'] ) ) {
111 $_recurrence = intval( $this->recurrence ) || 15;
112 $_queue = $this->app->storage()->get();
113 $_queue[ $this->id ]['start'] = $this->strtotime( "+$_recurrence days" );
114 $_queue[ $this->id ]['expire'] = $this->strtotime( "+". ($_recurrence + 3) ." days" );
115 $this->app->storage()->save( $_queue );
116 return;
117 }
118
119 // If we got this far, we need to dismiss the notice.
120 $this->dismiss_notice();
121 }
122
123 /**
124 * Actually dismisses the notice.
125 *
126 * @access private
127 * @since 1.0
128 * @return void
129 */
130 public function dismiss_notice() {
131 if ( 'user' === $this->scope ) {
132 return $this->app->storage()->save_meta( $this->id );
133 }
134
135 $_key = $this->app->app . '_' . $this->id . '_notice_dismissed';
136 return $this->app->storage()->save( $_key );
137 }
138
139 /**
140 * Check if is dismissed or not
141 * @return boolean
142 */
143 public function is_dismissed(){
144 if ( 'user' === $this->scope ) {
145 return $this->app->storage()->get_meta( $this->id );
146 }
147
148 $_key = $this->app->app . '_' . $this->id . '_notice_dismissed';
149 return $this->app->storage()->get( $_key );
150 }
151 }