PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 4.2.0
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v4.2.0
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
controls-helper.php 4 years ago elementor-data-map.php 4 years ago global-helper.php 3 years ago helper.php 3 years ago notice.php 3 years ago shipping-calculation.php 3 years ago
notice.php
187 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
41 // Valid inputs?
42 if ( ! empty( $id ) ) {
43
44 if ( 'user' === $meta ) {
45 update_user_meta( get_current_user_id(), $id, true );
46 } else {
47 set_transient( $id, true, $time );
48 }
49
50 wp_send_json_success();
51 }
52
53 wp_send_json_error();
54 }
55
56 /**
57 * Enqueue Scripts.
58 *
59 * @since 1.0.0
60 * @return void
61 */
62 public function enqueue_scripts() {
63 echo "
64 <script>
65 jQuery(document).ready(function ($) {
66 $( '.shopengine-notice.is-dismissible' ).on( 'click', '.notice-dismiss', function() {
67 _this = $( this ).parents( '.shopengine-active-notice' );
68 var id = _this.attr( 'id' ) || '';
69 var time = _this.attr( 'dismissible-time' ) || '';
70 var meta = _this.attr( 'dismissible-meta' ) || '';
71
72 $.ajax({
73 url: ajaxurl,
74 type: 'POST',
75 data: {
76 action : 'shopengine-notices',
77 id : id,
78 meta : meta,
79 time : time,
80 shopengine_nonce: ".esc_html(wp_create_nonce( 'shopengine_nonce' ))."
81 },
82 });
83
84 });
85
86 });
87 </script>
88 ";
89 }
90
91 /**
92 * Show Notices
93 *
94 * @since 1.0.0
95 * @return void
96 */
97 public static function push($notice) {
98
99 $defaults = [
100 'id' => '',
101 'type' => 'info',
102 'show_if' => true,
103 'message' => '',
104 'class' => 'shopengine-active-notice',
105 'dismissible' => false,
106 'btn' => [],
107 'dismissible-meta' => 'user',
108 'dismissible-time' => WEEK_IN_SECONDS,
109 'data' => '',
110 ];
111
112 $notice = wp_parse_args( $notice, $defaults );
113
114 $classes = [ 'shopengine-notice', 'notice' ];
115
116 $classes[] = $notice['class'];
117 if ( isset( $notice['type'] ) ) {
118 $classes[] = 'notice-' . $notice['type'];
119 }
120
121 // Is notice dismissible?
122 if ( true === $notice['dismissible'] ) {
123 $classes[] = 'is-dismissible';
124
125 // Dismissable time.
126 $notice['data'] = ' dismissible-time=' . esc_attr( $notice['dismissible-time'] ) . ' ';
127 }
128
129 // Notice ID.
130 $notice_id = 'shopengine-sites-notice-id-' . $notice['id'];
131 $notice['id'] = $notice_id;
132 if ( ! isset( $notice['id'] ) ) {
133 $notice_id = 'shopengine-sites-notice-id-' . $notice['id'];
134 $notice['id'] = $notice_id;
135 } else {
136 $notice_id = $notice['id'];
137 }
138
139 $notice['classes'] = implode( ' ', $classes );
140
141 // User meta.
142 $notice['data'] .= ' dismissible-meta=' . esc_attr( $notice['dismissible-meta'] ) . ' ';
143 if ( 'user' === $notice['dismissible-meta'] ) {
144 $expired = get_user_meta( get_current_user_id(), $notice_id, true );
145 } elseif ( 'transient' === $notice['dismissible-meta'] ) {
146 $expired = get_transient( $notice_id );
147 }
148
149 // Notice visible after transient expire.
150 if ( isset( $notice['show_if'] ) ) {
151 if ( true === $notice['show_if'] ) {
152
153 // Is transient expired?
154 if ( false === $expired || empty( $expired ) ) {
155 self::markup($notice);
156 }
157 }
158 } else {
159 self::markup($notice);
160 }
161 }
162
163 /**
164 * Markup Notice.
165 *
166 * @since 1.0.0
167 * @param array $notice Notice markup.
168 * @return void
169 */
170 public static function markup( $notice = [] ) {
171 ?>
172 <div id="<?php echo esc_attr( $notice['id'] ); ?>" class="<?php echo esc_attr( $notice['classes'] ); ?>" <?php shopengine_content_render(Helper::render($notice['data'])); ?>>
173 <p>
174 <?php echo wp_kses($notice['message'], Helper::get_kses_array()); ?>
175 </p>
176
177 <?php if(!empty($notice['btn'])):?>
178 <p>
179 <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>
180 </p>
181 <?php endif; ?>
182 </div>
183 <?php
184 }
185 }
186
187 new Notice();