PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.17.4
Shortcodes and extra features for Phlox theme v2.17.4
2.17.21 2.17.20 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.6 1.0.9 1.1.0 1.3.0 1.3.1 1.3.10 1.3.14 1.3.2 1.3.3 1.3.6 1.4.0 1.4.1 1.4.2 1.5.0 1.5.2 1.6.0 1.6.2 1.6.4 1.7.0 1.7.2 2.10.0 2.10.1 2.10.3 2.10.5 2.10.7 2.10.8 2.10.9 2.11.0 2.11.1 2.11.2 2.12.0 2.14.0 2.15.0 2.15.2 2.15.4 2.15.5 2.15.6 2.15.7 2.15.8 2.15.9 2.16.0 2.16.1 2.16.2 2.16.3 2.16.4 2.17.0 2.17.1 2.17.12 2.17.13 2.17.14 2.17.15 2.17.16 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.8 2.17.9 2.4.12 2.4.13 2.4.14 2.4.16 2.4.18 2.4.19 2.4.9 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.17 2.5.19 2.5.2 2.5.20 2.5.3 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.10 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.19 2.6.2 2.6.20 2.6.4 2.6.5 2.6.7 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.9 2.9.0 2.9.12 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.19 2.9.2 2.9.20 2.9.21 2.9.22 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8
auxin-elements / admin / includes / admin-ajax.php
auxin-elements / admin / includes Last commit date
classes 1 year ago compatibility 1 year ago metaboxes 1 year ago admin-ajax.php 2 years ago admin-hooks.php 1 year ago admin-the-functions.php 1 year ago index.php 2 years ago
admin-ajax.php
474 lines
1 <?php
2
3 function auxin_ajax_send_feedback(){
4
5 // skip if the form data is not receiced
6 if( empty( $_POST['form'] ) ){
7 wp_send_json_error( __( 'Data cannot be delivered, please try again.', 'auxin-elements' ) );
8 }
9
10
11 // extract the form data
12 $rate = ( ! empty( $_POST['form']['theme_rate'] ) || $_POST['form']['theme_rate'] === '0' ) ? sanitize_text_field( $_POST['form']['theme_rate'] ) : '';
13 $feedback = ! empty( $_POST['form']['feedback'] ) ? sanitize_text_field( $_POST['form']['feedback'] ) : '';
14 $email = ! empty( $_POST['form']['email'] ) ? sanitize_email( $_POST['form']['email'] ) : '';
15 $nonce = ! empty( $_POST['form']['_wpnonce'] ) ? sanitize_text_field( $_POST['form']['_wpnonce'] ) : '';
16
17 if( ! wp_verify_nonce( $nonce, 'phlox_feedback' ) ){
18 wp_send_json_error( __( 'Authorization failed!', 'auxin-elements' ) );
19 }
20
21 if( $rate || $rate === '0' ){
22
23 global $wp_version;
24
25 $passed_diff_time = auxin_get_passed_installed_time();
26 $installed_days = isset( $passed_diff_time->days ) ? $passed_diff_time->days : 1;
27
28 $args = array(
29 'user-agent' => 'WordPress/'.$wp_version.'; '. get_home_url(),
30 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 5),
31 'body' => array(
32 'cat' => 'rating',
33 'action' => 'submit',
34 'item-slug' => 'phlox',
35 'rate' => $rate,
36 'client_key' => get_theme_mod( 'client_key', ''),
37 'item_version'=> THEME_VERSION,
38 'theme_slug' => THEME_ID,
39 'feedback' => $feedback,
40 'is_active' => function_exists('auxin_is_activated') && auxin_is_activated(),
41 'installed_days' => $installed_days
42 )
43 );
44 // send the rating through the api
45 $request = wp_remote_post( 'https://api.averta.net/envato/items/', $args );
46 update_option( 'auxin_show_rate_scale_notice', 0 );
47 set_theme_mod( 'rate_scale_notice_remind_later_date', 0 );
48 // if ( ! is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ) {}
49
50 // store the user rating on the website
51 auxin_update_option( 'user_rating', $rate );
52
53 // send the feedback via email
54 $message = 'Rate: '. $rate . "\r\n" . 'Email: <' . $email . ">\r\n\r\n" . $feedback;
55 wp_mail( 'feedbacks@averta.net', 'Feedback from phlox dashboard:', $message );
56
57 wp_send_json_success( __( 'Sent Successfully. Thanks for your feedback!', 'auxin-elements' ) );
58
59 } else{
60 wp_send_json_error( __( 'An error occurred. Feedback could not be delivered, please try again.', 'auxin-elements' ) );
61 }
62
63 }
64
65 add_action( 'wp_ajax_send_feedback', 'auxin_ajax_send_feedback' );
66
67 /**
68 * Hide Feedback notice
69 */
70 function auxin_remove_feedback_notice() {
71 // skip if the form data is not receiced
72 if( empty( $_POST['form'] ) ){
73 wp_send_json_error( __( 'Data cannot be delivered, please try again.', 'auxin-elements' ) );
74 }
75
76 $nonce = ! empty( $_POST['form']['_wpnonce'] ) ? sanitize_text_field( $_POST['form']['_wpnonce'] ) : '';
77
78 if( ! wp_verify_nonce( $nonce, 'phlox_feedback' ) ){
79 wp_send_json_error( __( 'Authorization failed!', 'auxin-elements' ) );
80 }
81
82 update_option( 'auxin_show_rate_scale_notice', 0 );
83 set_theme_mod( 'rate_scale_notice_remind_later_date', 0 );
84
85 wp_send_json_success();
86 }
87
88 add_action( 'wp_ajax_aux-remove-feedback-notice', 'auxin_remove_feedback_notice' );
89
90
91 /**
92 * Remind feedback
93 */
94 function auxin_ajax_remind_feedback() {
95 // skip if the form data is not receiced
96 if( empty( $_POST['form'] ) ){
97 wp_send_json_error( __( 'Data cannot be delivered, please try again.', 'auxin-elements' ) );
98 }
99
100 $nonce = ! empty( $_POST['form']['_wpnonce'] ) ? sanitize_text_field( $_POST['form']['_wpnonce'] ) : '';
101
102 if( ! wp_verify_nonce( $nonce, 'phlox_feedback' ) ){
103 wp_send_json_error( __( 'Authorization failed!', 'auxin-elements' ) );
104 }
105
106 // reset feedback notice viewer
107 update_option( 'auxin_show_rate_scale_notice', 0 );
108 set_theme_mod( 'rate_scale_notice_remind_later_date', time() + DAY_IN_SECONDS * 3 );
109
110 wp_send_json_success();
111 }
112
113 add_action( 'wp_ajax_remind_feedback', 'auxin_ajax_remind_feedback' );
114
115
116
117 function auxin_ajax_isotope_filter_group(){
118 // Check nonce
119 if ( ! isset( $_POST['group'] ) ||! isset( $_POST['key'] ) || ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'aux-iso-group' ) ) {
120 wp_send_json_error( __( 'Token Error.', 'auxin-elements' ) );
121 }
122
123 if( false !== update_option( 'aux_isotope_group_' . auxin_sanitize_input( $_POST['key'] ) , auxin_sanitize_input( $_POST['group'] ) ) ) {
124 wp_send_json_success( __( 'It\'s Done.', 'auxin-elements' ) );
125 }
126
127 wp_send_json_error( __( 'An error occurred.', 'auxin-elements' ) );
128 }
129 add_action( 'wp_ajax_aux_isotope_group', 'auxin_ajax_isotope_filter_group' );
130
131
132 function auxin_ajax_filter_get_content() {
133
134 // Check nonce
135 if ( ! isset( $_POST['n'] ) || ! wp_verify_nonce( $_POST['n'], 'aux_ajax_filter_request' ) ) {
136 wp_send_json_error( 'Nonce check failed!', 403 );
137 }
138
139 $num = sanitize_text_field( $_POST['num'] );
140 $post_type = 'product';
141 $tax = sanitize_text_field( $_POST['taxonomy'] );
142 $term = sanitize_text_field( $_POST['term'] );
143 $image_class = 'aux-img-dynamic-dropshadow';
144 $width = sanitize_text_field( $_POST['width'] );
145 $height = sanitize_text_field( $_POST['height'] );
146 $order = sanitize_text_field( $_POST['order'] );
147 $orderby = sanitize_text_field( $_POST['orderby'] );
148 $size = array( 'width' => $width, 'height' => $height );
149
150 /*
151 * The WordPress Query class.
152 *
153 * @link http://codex.wordpress.org/Function_Reference/WP_Query
154 */
155 $args = array(
156 // Type & Status Parameters
157 'post_type' => $post_type,
158 'post_status' => 'publish',
159 // Pagination Parameters
160 'posts_per_page' => $num,
161 'nopaging' => false,
162 'order' => $order,
163 'orderby' => $orderby,
164 );
165
166 if ( 'all' !== $term ) {
167 // Taxonomy Parameters
168 $args['tax_query'] = array(
169 array(
170 'taxonomy' => $tax,
171 'field' => 'slug',
172 'terms' => $term,
173 'include_children' => true,
174 'operator' => 'IN',
175 )
176 );
177 }
178
179 $posts = get_posts( $args );
180
181 foreach ( $posts as $post ) {
182
183 $image_id = get_post_thumbnail_id( $post );
184 $product = wc_get_product( $post->ID );
185
186 $post->thumb = auxin_get_the_responsive_attachment(
187 $image_id,
188 array(
189 'quality' => 100,
190 'upscale' => true,
191 'crop' => true,
192 'add_hw' => true, // whether add width and height attr or not
193 'attr' => array(
194 'class' => 'auxshp-product-image auxshp-attachment ' . $image_class,
195 'data-original-width' => $width,
196 'data-original-height' => $height,
197 'data-original-src' => wp_get_attachment_image_src( $image_id, 'full' )[0]
198 ),
199 'size' => $size,
200 'image_sizes' => 'auto',
201 'srcset_sizes' => 'auto',
202 'original_src' => true
203 )
204 );
205
206 $post->price = $product->get_price_html();
207 $post->meta = wc_get_product_category_list( $product->get_id(), ', ', '<em class="auxshp-meta-terms">', '</em>' );
208 $post->badge = $product->is_on_sale() ? true : false;
209
210 $isAjaxEnabled = class_exists( 'AUXSHP' ) ? auxin_is_true( auxin_get_option( 'product_index_ajax_add_to_cart', '1' ) ) : auxin_is_true( get_option( 'woocommerce_enable_ajax_add_to_cart' ) );
211 if( $isAjaxEnabled ) {
212 $class = 'button aux-ajax-add-to-cart add_to_cart_button';
213 }
214
215 $post->cart = apply_filters( 'woocommerce_loop_add_to_cart_link',
216 sprintf( '<a rel="nofollow" href="%s" data-quantity="1" data-product_id="%s" data-product_sku="%s" data-verify_nonce="%s" class="%s"><i class="aux-ico auxicon-handbag"></i><span>%s</span></a>',
217 esc_url( $product->add_to_cart_url() ),
218 esc_attr( $product->get_id() ),
219 esc_attr( $product->get_sku() ),
220 esc_attr( wp_create_nonce( 'aux_add_to_cart-' . $product->get_id() ) ),
221 esc_attr( isset( $class ) ? $class : 'button add_to_cart_button' ),
222 esc_html( $product->add_to_cart_text() )
223 ),
224 $product );
225 }
226
227 wp_send_json_success( $posts );
228
229 }
230
231 add_action( 'wp_ajax_filter_get_content', 'auxin_ajax_filter_get_content' );
232 add_action( 'wp_ajax_noprive_filter_get_content', 'auxin_ajax_filter_get_content' );
233
234 /**
235 * wordpress ajax for dismissed notice
236 *
237 * @return json
238 */
239 function auxin_dismissed_notice(){
240 // Store it in the options table
241 if ( ! isset( $_POST['id'] ) || ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], '_notice_nonce' ) ) {
242 wp_send_json_error( __( 'Token Error.', 'auxin-elements' ) );
243 } else {
244 auxin_set_transient( sanitize_text_field( 'auxin-notice-' . $_POST['id'] ), 1, sanitize_text_field( $_POST['expiration'] ) );
245 wp_send_json_success( __( 'It\'s OK.', 'auxin-elements' ) );
246 }
247 }
248 add_action( 'wp_ajax_auxin_dismissed_notice', 'auxin_dismissed_notice' );
249
250 /**
251 * WordPress ajax to display activation form
252 *
253 * @return html
254 */
255 function auxin_display_actvation_form(){
256 if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'aux-activation-form' ) ) {
257 // This nonce is not valid.
258 wp_die( esc_html__( 'Security Token Error!', 'auxin-elements' ) );
259 }
260 ob_start();
261 ?>
262 <div class="aux-license-popup">
263 <button class="featherlight-close-icon featherlight-close" aria-label="Close"></button>
264 <img class="aux-popup-image" src="<?php echo esc_url( AUXELS_ADMIN_URL . '/assets/images/welcome/activation.svg' ); ?>" />
265 <h2 class="aux-popup-title"><?php esc_html_e( 'License Activation', 'auxin-elements' ); ?></h2>
266 <p class="aux-popup-desc"><?php esc_html_e( 'Please activate your license to get automatic updates, premium support, and unlimited access to the template library and demo importer.', 'auxin-elements' ); printf('&nbsp;<a href="https://help.market.envato.com/hc/en-us/articles/202822600-Where-Is-My-Purchase-Code-" target="_blank">%s</a>', esc_html( 'how to find purchase code?', 'auxin-elements' ) ); ?></p>
267 <form class="auxin-form auxin-check-purchase" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post">
268 <div class="form-group">
269 <label class="form-label" for="aux-usermail"><?php esc_html_e( 'E-mail address', 'auxin-elements' ); ?></label>
270 <input class="form-control" type="text" name="usermail" value="<?php echo esc_attr( get_option('admin_email') ); ?>" required>
271 </div>
272
273 <div class="form-group">
274 <label class="form-label" for="aux-purchase"><?php esc_html_e( 'Purchase code', 'auxin-elements' ); ?></label>
275 <input class="form-control" type="text" name="purchase" required>
276 </div>
277
278 <?php wp_nonce_field( 'auxin-purchase-activation', 'security' ); ?>
279 <input type="hidden" name="action" value="auxin_purchase_activation">
280 <div class="button-group">
281 <button type="submit" class="aux-button aux-primary aux-medium aux-activate-license" value="submit">
282 <span><?php esc_html_e( 'Activate', 'auxin-elements' ); ?></span>
283 </button>
284 </div>
285 </form>
286 </div>
287 <?php
288 wp_die( ob_get_clean() );
289 }
290 add_action( 'wp_ajax_auxin_display_actvation_form', 'auxin_display_actvation_form' );
291
292 /**
293 * wordpress ajax for auxin purchase activation
294 *
295 * @return json
296 */
297 function auxin_purchase_activation(){
298
299 if ( ! isset( $_POST['usermail'] ) || ! isset( $_POST['purchase'] ) || ! isset( $_POST['security'] ) || ! wp_verify_nonce( $_POST['security'], 'auxin-purchase-activation' ) ) {
300 wp_send_json_error( array(
301 'message' => __( 'Token Error.', 'auxin-elements' ),
302 'buttonText' => __( 'Retry', 'auxin-elements' ),
303 ) );
304 }
305
306 $usermail = sanitize_email( $_POST['usermail'] );
307 $purchase_code = auxin_sanitize_input( $_POST['purchase'] );
308 $action = 'activate';
309
310 $result = Auxin_License_Activation::get_instance()->license_action( $usermail, $purchase_code, $action );
311
312 if( isset( $result['success'] ) && $result['success'] ){
313 $result['buttonText'] = __( 'Close', 'auxin-elements' );
314 wp_send_json_success( $result );
315 }
316
317 $result['buttonText'] = __( 'Retry', 'auxin-elements' );
318 wp_send_json_error( $result );
319
320 }
321 add_action( 'wp_ajax_auxin_purchase_activation', 'auxin_purchase_activation' );
322
323 /**
324 * wordpress ajax for auxin upgrader
325 *
326 * @return json
327 */
328 function auxin_ajax_upgrader(){
329 // Check ajax nonce field
330 check_ajax_referer( 'auxin-start-upgrading', 'nonce' );
331
332 if ( ! isset( $_POST['key'] ) || ! isset( $_POST['type'] ) ) {
333 wp_send_json_error( array(
334 'slug' => '',
335 'errorCode' => 'no_token_specified',
336 'errorMessage' => __( 'Token Error.', 'auxin-elements' )
337 ) );
338 }
339
340 $handler = new Auxin_Upgrader_Ajax_Handlers;
341 $handler->run( sanitize_text_field( $_POST['key'] ), sanitize_text_field( $_POST['type'] ) );
342 }
343 add_action( 'wp_ajax_auxin_start_upgrading', 'auxin_ajax_upgrader' );
344
345
346 /**
347 * wordpress ajax for auxin customizer export
348 *
349 * @return json
350 */
351 function auxin_customizer_export(){
352
353 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'auxin-export-control' ) ) {
354 wp_send_json_error( __( 'Token Error.', 'auxin-elements' ) );
355 }
356
357 // Get theme options
358 $theme_options = auxin_options();
359
360 // Get theme mods
361 $theme_mods = get_theme_mods();
362 $filters = array( 0, 'nav_menu_locations', 'custom_css_post_id', 'last_checked_version' );
363 foreach ( $filters as $filter ) {
364 if ( isset( $theme_mods[ $filter ] ) ) {
365 unset( $theme_mods[ $filter ] );
366 }
367 }
368
369 if( empty( $theme_options ) && empty( $theme_mods ) ){
370 wp_send_json_error( __( 'No data found!', 'auxin-elements' ) );
371 }
372
373 $b64_content = base64_encode( wp_json_encode( array(
374 'theme_options' => $theme_options,
375 'theme_mods' => $theme_mods
376 ) ) );
377
378 wp_send_json_success( array(
379 'content' => $b64_content,
380 'fileName' => THEME_ID . '_export_' . current_time('timestamp') . '.txt'
381 ) );
382
383 }
384 add_action( 'wp_ajax_auxin_customizer_export', 'auxin_customizer_export' );
385
386
387 /**
388 * wordpress ajax for auxin customizer import
389 *
390 * @return json
391 */
392 function auxin_customizer_import(){
393 // Check security
394 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'auxin-import-control' ) ) {
395 wp_send_json_error( __( 'Token Error.', 'auxin-elements' ) );
396 }
397
398 // Check input file
399 if ( ! isset( $_FILES['file'] ) || 0 < $_FILES['file']['error'] ) {
400 wp_send_json_error( __( 'Please upload a valid file.', 'auxin-elements' ) );
401 }
402
403 // Get and decode file content
404 global $wp_filesystem;
405 if ( empty($wp_filesystem) ) {
406 require_once( ABSPATH . '/wp-admin/includes/file.php' );
407 WP_Filesystem();
408 }
409 $json_content = $wp_filesystem->get_contents( $_FILES['file']['tmp_name'] );
410 $array_content = json_decode( base64_decode( $json_content ), true );
411 $array_content = auxin_sanitize_input( $array_content );
412
413 // Check array empty
414 if ( empty( $array_content ) || ! is_array( $array_content ) ) {
415 wp_send_json_error( __( 'Invalid or Empty Data.', 'auxin-elements' ) );
416 }
417
418 if( isset( $array_content['theme_options'] ) ){
419 // Get image options names
420 $get_options = auxin_get_defined_options();
421 $custom_images = array();
422 foreach ( $get_options['fields'] as $key => $value ) {
423 if ( ! array_search( 'image', $value ) ) {
424 continue;
425 }
426 $custom_images[] = $value['id'];
427 }
428 // Update options
429 foreach ( $array_content['theme_options'] as $auxin_key => $auxin_value ) {
430 if ( in_array( $auxin_key, $custom_images ) && ! empty( $auxin_value ) ) {
431 continue;
432 }
433 // Update exclusive auxin options
434 auxin_update_option( $auxin_key , $auxin_value );
435 }
436 }
437
438 if( isset( $array_content['theme_mods'] ) ){
439 foreach ( $array_content['theme_mods'] as $theme_mods_key => $theme_mods_value ) {
440 // Start theme mods loop:
441 if( $theme_mods_key === 'custom_logo' ) {
442 continue;
443 }
444 // Update theme mods
445 set_theme_mod( $theme_mods_key , $theme_mods_value );
446 }
447 }
448
449 // force to flush dynamic asset files
450 delete_transient( 'auxin_' . AUXELS_SLUG . '_version' );
451
452 wp_send_json_success( __( 'Successfully Imported.', 'auxin-elements' ) );
453
454 }
455 add_action( 'wp_ajax_auxin_customizer_import', 'auxin_customizer_import' );
456
457
458 /**
459 * Ajax handler for auxin_template_library control to import template
460 *
461 * @return json
462 */
463 function auxin_template_control_importer() {
464 $template_type = sanitize_text_field( $_POST['template_type'] );
465 if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'customizer-template-library-' . $template_type ) ) {
466 wp_send_json_error([
467 'message' => __( 'Sorry. You don\'t have sufficient permission to import a template!', 'auxin-elements')
468 ]);
469 }
470
471 wp_send_json( auxin_template_importer( sanitize_text_field( $_POST['id'] ), $template_type, 'update_menu' ) );
472 }
473 add_action( 'wp_ajax_auxin_template_control_importer', 'auxin_template_control_importer' );
474