PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 4.5.1
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v4.5.1
4.9.1 4.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 4.1.1 4.2.0 4.2.1 4.3.0 4.3.1 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 trunk 0.1.2-beta 0.1.3-beta 0.1.4-beta 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.9.0
shopengine / utils / notice.php
shopengine / utils Last commit date
banner 2 years ago notice 2 years ago pro-awareness 2 years ago stories 2 years ago controls-helper.php 4 years ago elementor-data-map.php 4 years ago global-helper.php 3 years ago helper.php 2 years ago notice.php 2 years ago shipping-calculation.php 3 years ago util.php 2 years ago
notice.php
200 lines
1 <?php
2 namespace ShopEngine\Utils;
3
4 if ( ! defined( 'ABSPATH' ) ) die( 'Forbidden' );
5
6 /**
7 * shopengine-builder notice class.
8 * Handles dynamically notices for lazy developers.
9 *
10 * @since 1.0.0
11 */
12 class Notice {
13
14 /**
15 * Constructor
16 *
17 * @since 1.0.0
18 */
19 public function __construct() {
20 add_action( 'admin_footer', [ $this, 'enqueue_scripts' ], 9999);
21 add_action( 'wp_ajax_shopengine-notices', [ $this, 'dismiss' ] );
22 }
23
24
25 /**
26 * Dismiss Notice.
27 *
28 * @since 1.0.0
29 * @return void
30 */
31 public function dismiss() {
32
33 if(empty($_POST['shopengine_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['shopengine_nonce'])), 'shopengine_nonce')) {
34 wp_send_json_error();
35 }
36
37 $id = ( isset( $_POST['id'] ) ) ? sanitize_key($_POST['id']) : '';
38 $time = ( isset( $_POST['time'] ) ) ? sanitize_text_field(wp_unslash($_POST['time'])) : '';
39 $meta = ( isset( $_POST['meta'] ) ) ? sanitize_key($_POST['meta']) : '';
40 $is_required = ( isset( $_POST['is_required'] ) ) ? sanitize_key($_POST['is_required']) : 0;
41
42 if($is_required == 1){
43 return;
44 }
45
46 // Valid inputs?
47 if ( ! empty( $id ) ) {
48
49 if ( 'user' === $meta ) {
50 update_user_meta( get_current_user_id(), $id, true );
51 } else {
52 set_transient( $id, true, $time );
53 }
54
55 wp_send_json_success();
56 }
57
58 wp_send_json_error();
59 }
60
61 /**
62 * Enqueue Scripts.
63 *
64 * @since 1.0.0
65 * @return void
66 */
67 public function enqueue_scripts() {
68 echo "
69 <script>
70 jQuery(document).ready(function ($) {
71 $( '.shopengine-notice.is-dismissible' ).on( 'click', '.notice-dismiss', function() {
72 _this = $( this ).parents( '.shopengine-active-notice' );
73 var id = _this.attr( 'id' ) || '';
74 var time = _this.attr( 'dismissible-time' ) || '';
75 var meta = _this.attr( 'dismissible-meta' ) || '';
76 let is_required = _this.attr( 'is-required' ) || 0;
77
78 $.ajax({
79 url: ajaxurl,
80 type: 'POST',
81 data: {
82 action : 'shopengine-notices',
83 id : id,
84 meta : meta,
85 time : time,
86 is_required: is_required,
87 shopengine_nonce: '".esc_html(wp_create_nonce( 'shopengine_nonce' ))."'
88 },
89 });
90
91 });
92
93 });
94 </script>
95 ";
96 }
97
98 /**
99 * Show Notices
100 *
101 * @since 1.0.0
102 * @return void
103 */
104 public static function push($notice) {
105
106 $defaults = [
107 'id' => '',
108 'type' => 'info',
109 'show_if' => true,
110 'message' => '',
111 'class' => 'shopengine-active-notice',
112 'dismissible' => false,
113 'btn' => [],
114 'dismissible-meta' => 'user',
115 'is_required' => false,
116 'dismissible-time' => WEEK_IN_SECONDS,
117 'data' => '',
118 ];
119
120 $notice = wp_parse_args( $notice, $defaults );
121
122 $classes = [ 'shopengine-notice', 'notice' ];
123
124 $classes[] = $notice['class'];
125 if ( isset( $notice['type'] ) ) {
126 $classes[] = 'notice-' . $notice['type'];
127 }
128
129 // Is notice dismissible?
130 if ( true === $notice['dismissible'] ) {
131 $classes[] = 'is-dismissible';
132
133 // Dismissable time.
134 $notice['data'] = ' dismissible-time=' . esc_attr( $notice['dismissible-time'] ) . ' ';
135 }
136
137 // Notice ID.
138 $notice_id = 'shopengine-sites-notice-id-' . $notice['id'];
139 $notice['id'] = $notice_id;
140 if ( ! isset( $notice['id'] ) ) {
141 $notice_id = 'shopengine-sites-notice-id-' . $notice['id'];
142 $notice['id'] = $notice_id;
143 } else {
144 $notice_id = $notice['id'];
145 }
146
147 $notice['classes'] = implode( ' ', $classes );
148
149 // User meta.
150 $notice['data'] .= ' dismissible-meta=' . esc_attr( $notice['dismissible-meta'] ) . ' ';
151 if ( 'user' === $notice['dismissible-meta'] ) {
152 $expired = get_user_meta( get_current_user_id(), $notice_id, true );
153 } elseif ( 'transient' === $notice['dismissible-meta'] ) {
154 $expired = get_transient( $notice_id );
155 }
156
157 // Is required plugin?
158 if ( isset( $notice['is_required'] ) && true === $notice['is_required'] ) {
159 $notice['data'] .= "' is-required=1";
160 }
161
162 // Notice visible after transient expire.
163 if ( isset( $notice['show_if'] ) ) {
164 if ( true === $notice['show_if'] ) {
165
166 // Is transient expired?
167 if ( false === $expired || empty( $expired ) ) {
168 self::markup($notice);
169 }
170 }
171 } else {
172 self::markup($notice);
173 }
174 }
175
176 /**
177 * Markup Notice.
178 *
179 * @since 1.0.0
180 * @param array $notice Notice markup.
181 * @return void
182 */
183 public static function markup( $notice = [] ) {
184 ?>
185 <div id="<?php echo esc_attr( $notice['id'] ); ?>" class="<?php echo esc_attr( $notice['classes'] ); ?>" <?php shopengine_content_render(Helper::render($notice['data'])); ?>>
186 <p>
187 <?php echo wp_kses($notice['message'], Helper::get_kses_array()); ?>
188 </p>
189
190 <?php if(!empty($notice['btn'])):?>
191 <p>
192 <a title="<?php esc_html_e('Notification','shopengine')?>" href="<?php echo esc_url($notice['btn']['url']); ?>" class="button-primary"><?php echo esc_html($notice['btn']['label']); ?></a>
193 </p>
194 <?php endif; ?>
195 </div>
196 <?php
197 }
198 }
199
200 new Notice();