PluginProbe
YayMail – WooCommerce Email Customizer / 4.3.3
YayMail – WooCommerce Email Customizer v4.3.3
4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 All 57 releases
← All changes | src/Ajax.php +57 -230 4.4.6 → 4.3.3 View file →
@@ -7,11 +7,9 @@
7 7 use YayMail\Models\TemplateModel;
8 8 use YayMail\Models\RevisionModel;
9 9 use YayMail\Migrations\MainMigration;
10 10 use YayMail\Utils\Helpers;
11 -use YayMail\Utils\Logger;
12 -use YayMail\Models\PatternTemplateModel;
13 -use YayMail\Utils\TemplateHelpers;
11 +use YayMail\Migrations\AbstractMigration;
14 12
15 13 /**
16 14 * I18n Logic
17 15 *
@@ -38,59 +36,10 @@
38 36 add_action( 'wp_ajax_yaymail_dismiss_multi_select_notice', [ $this, 'dismiss_multi_select_notice' ] );
39 37 add_action( 'wp_ajax_yaymail_export_state', [ $this, 'export_state' ] );
40 38 add_action( 'wp_ajax_yaymail_import_state', [ $this, 'import_state' ] );
41 39 add_action( 'wp_ajax_yaymail_dismiss_new_element_notification', [ $this, 'dismiss_new_element_notification' ] );
42 - add_action( 'wp_ajax_yaymail_log_client_error', [ $this, 'log_client_error' ] );
43 40 }
44 41
45 - /**
46 - * Records a runtime error reported by the admin SPA (see apps/customizer/src/utils/client-error-reporter.ts).
47 - *
48 - * Goes to the WooCommerce log (WooCommerce > Status > Logs, source "yaymail-client") so support can ask the
49 - * customer to copy it from wp-admin; falls back to the yaymail-logs file when WooCommerce is absent.
50 - */
51 - public function log_client_error() {
52 - $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
53 - if ( ! wp_verify_nonce( $nonce, 'yaymail_frontend_nonce' ) || ! current_user_can( 'manage_woocommerce' ) ) {
54 - return wp_send_json_error( [ 'mess' => __( 'Verify nonce failed', 'yaymail' ) ], 403 );
55 - }
56 -
57 - // A render loop in one browser must not be able to fill the log.
58 - $rate_key = 'yaymail_client_error_rate_' . get_current_user_id();
59 - $count = (int) get_transient( $rate_key );
60 - if ( $count >= 20 ) {
61 - return wp_send_json_success( [ 'logged' => false ] );
62 - }
63 - set_transient( $rate_key, $count + 1, MINUTE_IN_SECONDS );
64 -
65 - $text = function ( $key, $max = 8000 ) {
66 - $value = isset( $_POST[ $key ] ) ? sanitize_textarea_field( wp_unslash( $_POST[ $key ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
67 - return mb_substr( $value, 0, $max );
68 - };
69 -
70 - $lines = [
71 - 'CLIENT ERROR [' . $text( 'source', 20 ) . ']: ' . $text( 'message', 1000 ),
72 - 'Version: ' . $text( 'version', 20 ) . ' | Platform: ' . $text( 'platform', 40 ) . ' | Template: ' . $text( 'template', 200 ),
73 - 'URL: ' . $text( 'url', 2000 ),
74 - 'User agent: ' . $text( 'user_agent', 500 ),
75 - ];
76 - foreach ( [ 'hint' => 'Hint', 'stack' => 'Stack', 'component_stack' => 'Component stack' ] as $key => $label ) {
77 - $value = $text( $key );
78 - if ( '' !== $value ) {
79 - $lines[] = $label . ':' . PHP_EOL . $value;
80 - }
81 - }
82 - $message = implode( PHP_EOL, $lines );
83 -
84 - if ( function_exists( 'wc_get_logger' ) ) {
85 - wc_get_logger()->error( $message, [ 'source' => 'yaymail-client' ] );
86 - } else {
87 - ( new Logger() )->log( $message );
88 - }
89 -
90 - wp_send_json_success( [ 'logged' => true ] );
91 - }
92 -
93 42 public function import_state() {
94 43 $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
95 44 if ( ! wp_verify_nonce( $nonce, 'yaymail_frontend_nonce' ) ) {
96 45 return wp_send_json_error( [ 'mess' => __( 'Verify nonce failed', 'yaymail' ) ] );
@@ -112,12 +61,9 @@
112 61
113 62 $state_data = null;
114 63 for ( $i = 0; $i < $zip->numFiles; $i++ ) {
115 64 $filename = $zip->getNameIndex( $i );
116 - // Matches both "yaymail_backup.json" (YayMail) and "yaymagic_email_builder_backup.json"
117 - // (Email Builder) -- the zip always holds exactly this one entry, named per
118 - // getBrandName() in backup/index.tsx.
119 - if ( 1 === preg_match( '/_backup\.json$/', (string) $filename ) ) {
65 + if ( $filename === 'yaymail_backup.json' ) {
120 66 $state_data = $zip->getFromIndex( $i );
121 67 break;
122 68 }
123 69 }
@@ -124,9 +70,9 @@
124 70
125 71 $zip->close();
126 72
127 73 if ( ! $state_data ) {
128 - return wp_send_json_error( [ 'mess' => __( 'Cannot find the backup JSON file in the ZIP file.', 'yaymail' ) ] );
74 + return wp_send_json_error( [ 'mess' => __( 'Cannot find yaymail_backup.json in the ZIP file.', 'yaymail' ) ] );
129 75 }
130 76
131 77 $imported_data = json_decode( $state_data );
132 78 if ( json_last_error() !== JSON_ERROR_NONE ) {
@@ -140,53 +86,12 @@
140 86 $migration_model = \YayMail\Models\MigrationModel::get_instance();
141 87
142 88 $source_version = $imported_data->version;
143 89
144 - $imported_posts = array_values(
145 - array_filter(
146 - $imported_data->posts,
147 - function( $post ) {
148 - return isset( $post->post_type ) && 'yaymail_template' === $post->post_type;
149 - }
150 - )
151 - );
152 -
153 - $imported_postmeta = array_values(
154 - array_filter(
155 - $imported_data->postmeta,
156 - function( $postmeta ) use ( $imported_posts ) {
157 - if ( empty( $imported_posts ) ) {
158 - return false;
159 - }
160 - if ( ! isset( $postmeta->post_id ) || ! isset( $postmeta->meta_key ) ) {
161 - return false;
162 - }
163 - if ( strpos( (string) $postmeta->meta_key, 'yaymail' ) === false ) {
164 - return false;
165 - }
166 - foreach ( $imported_posts as $post ) {
167 - if ( isset( $post->ID ) && (int) $post->ID === (int) $postmeta->post_id ) {
168 - return true;
169 - }
170 - }
171 - return false;
172 - }
173 - )
174 - );
175 -
176 - $imported_options = array_values(
177 - array_filter(
178 - $imported_data->options,
179 - function( $option ) {
180 - return isset( $option->option_name ) && strpos( (string) $option->option_name, 'yaymail' ) !== false;
181 - }
182 - )
183 - );
184 -
185 90 $backup_data = [
186 - 'posts' => $imported_posts,
187 - 'postmeta' => $imported_postmeta,
188 - 'options' => $imported_options,
91 + 'posts' => $imported_data->posts,
92 + 'postmeta' => $imported_data->postmeta,
93 + 'options' => $imported_data->options,
189 94 'created_date' => $imported_data->created_date ?? current_datetime()->format( 'Y-m-d H:i:s' ),
190 95 'name' => '_yaymail_import_backup_' . $source_version,
191 96 'version' => $source_version,
192 97 ];
@@ -250,23 +155,10 @@
250 155 $yaymail_options = $wpdb->get_results( $query_options ); // phpcs:ignore
251 156 $backup_data['options'] = $yaymail_options;
252 157
253 158 $backup_data['created_date'] = current_datetime()->format( 'Y-m-d H:i:s' );
159 + $backup_data['version'] = get_option( 'yaymail_version_backup' );
254 160
255 - // Fall back through running version / YAYWP_VERSION / '1.0' when the
256 - // backup option hasn't been set yet (e.g. init_modules() hasn't
257 - // recorded it), otherwise a falsy 'version' gets baked into the
258 - // exported ZIP and MigrationModel::reset() rejects it on import with
259 - // "Back up does not exist".
260 - $version_backup = get_option( 'yaymail_version_backup' );
261 - if ( ! empty( $version_backup ) ) {
262 - $backup_data['version'] = $version_backup;
263 - } elseif ( ! empty( yaymail_version() ) ) {
264 - $backup_data['version'] = yaymail_version();
265 - } else {
266 - $backup_data['version'] = defined( 'YAYWP_VERSION' ) ? YAYWP_VERSION : '1.0';
267 - }
268 -
269 161 $backup_data = apply_filters( 'yaymail_backup_state_data', $backup_data );
270 162
271 163 wp_send_json_success(
272 164 [
@@ -271,18 +163,16 @@
271 163 wp_send_json_success(
272 164 [
273 165 'message' => 'success',
274 166 'data' => $backup_data,
275 - 'file_name' => $this->export_file_name_prefix() . '_export_backup_' . gmdate( 'm-d-Y' ),
167 + 'file_name' => 'yaymail_export_backup_' . gmdate( 'm-d-Y' ),
276 168 ]
277 169 );
278 170
279 171 } catch ( \Error $error ) {
280 172 yaymail_get_logger( $error );
281 - wp_send_json_error( [ 'mess' => $error->getMessage() ] );
282 173 } catch ( \Exception $exception ) {
283 174 yaymail_get_logger( $exception );
284 - wp_send_json_error( [ 'mess' => $exception->getMessage() ] );
285 175 }//end try
286 176 }
287 177
288 178 public function sanitize( $array ) {
@@ -289,20 +179,8 @@
289 179
290 180 return wp_kses_post_deep( $array );
291 181 }
292 182
293 - /**
294 - * File name prefix for exported/backup downloads, matching the frontend's
295 - * brand name per platform (constants/theme.ts WP_COLORS vs the free "yaymail"
296 - * default). Reads the "platform" the frontend sends alongside these AJAX
297 - * requests (see common/ajax's getPlatform() calls) since these admin-ajax.php
298 - * requests don't reliably expose the calling screen via get_current_screen().
299 - */
300 - private function export_file_name_prefix() {
301 - $platform = isset( $_POST['platform'] ) ? sanitize_text_field( wp_unslash( $_POST['platform'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing
302 - return 'yaymagic-email-builder' === $platform ? 'yaymagic_email_builder' : 'yaymail';
303 - }
304 -
305 183 public function process_plugin_installer( $slug ) {
306 184 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
307 185 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
308 186 require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php';
@@ -378,12 +256,10 @@
378 256 );
379 257
380 258 } catch ( \Error $error ) {
381 259 yaymail_get_logger( $error );
382 - wp_send_json_error( [ 'mess' => $error->getMessage() ] );
383 260 } catch ( \Exception $exception ) {
384 261 yaymail_get_logger( $exception );
385 - wp_send_json_error( [ 'mess' => $exception->getMessage() ] );
386 262 }//end try
387 263 }
388 264
389 265 public function send_test_mail() {
@@ -394,15 +270,14 @@
394 270 try {
395 271 $template_name = isset( $_POST['template_name'] ) ? sanitize_text_field( wp_unslash( $_POST['template_name'] ) ) : '';
396 272 $order_id = isset( $_POST['order_id'] ) ? sanitize_text_field( wp_unslash( $_POST['order_id'] ) ) : 'sample_order';
397 273 $email = isset( $_POST['email'] ) ? sanitize_text_field( $_POST['email'] ) : '';
398 - $is_wc_email = strpos( $template_name, 'wp-core-' ) !== 0;
399 274
400 275 if ( empty( $template_name ) ) {
401 276 return wp_send_json_error( [ 'mess' => __( 'Can\'t find template', 'yaymail' ) ] );
402 277 }
403 278
404 - if ( empty( $order_id ) && $is_wc_email ) {
279 + if ( empty( $order_id ) ) {
405 280 return wp_send_json_error( [ 'mess' => __( 'Can\'t find order', 'yaymail' ) ] );
406 281 }
407 282
408 283 if ( empty( $email ) ) {
@@ -408,10 +283,9 @@
408 283 if ( empty( $email ) ) {
409 284 return wp_send_json_error( [ 'mess' => __( 'Can\'t find email', 'yaymail' ) ] );
410 285 }
411 286
412 - $variant = yaymail_sanitize_template_variant( isset( $_POST['variant'] ) ? sanitize_text_field( wp_unslash( $_POST['variant'] ) ) : '' );
413 - $template = new YayMailTemplate( $template_name, '', $variant );
287 + $template = new YayMailTemplate( $template_name );
414 288
415 289 $render_data = [];
416 290
417 291 if ( empty( $order_id ) || ( 'sample_order' === $order_id ) ) {
@@ -426,25 +300,13 @@
426 300 update_option( 'yaymail_default_email_test', $email );
427 301
428 302 $html = $template->get_content( $render_data );
429 303
430 - $headers = "Content-Type: text/html\r\n";
431 - $subject = __( 'Email Test', 'yaymail' );
304 + $headers = "Content-Type: text/html\r\n";
305 + $class_wc_email = \WC_Emails::instance();
306 + $subject = __( 'Email Test', 'yaymail' );
307 + $send_mail = $class_wc_email->send( $email, $subject, $html, $headers, [] );
432 308
433 - if ( $is_wc_email ) {
434 - $class_wc_email = \WC_Emails::instance();
435 - $send_mail = $class_wc_email->send( $email, $subject, $html, $headers, [] );
436 - } else {
437 - // $html is already the fully-rendered wp-core-mail template output.
438 - // Without this marker, WpMail::custom_wp_mail_body() (hooked on the
439 - // 'wp_mail' filter, meant to wrap *raw* WP core messages like a
440 - // password-reset email) can't tell it apart from unrendered content
441 - // and wraps it in the template a second time -- the same marker
442 - // AddonWpMailController::woocommerce_mail_content() uses for real
443 - // WooCommerce sends.
444 - $html = '<!-- yaymail:wp-has-template-email-content -->' . $html;
445 - $send_mail = wp_mail( $email, $subject, $html, $headers, [] );
446 - }
447 309 if ( ! $send_mail ) {
448 310 return wp_send_json_error( [ 'mess' => __( 'Can\'t send email', 'yaymail' ) ] );
449 311 }
450 312
@@ -455,12 +317,10 @@
455 317 ]
456 318 );
457 319 } catch ( \Error $error ) {
458 320 yaymail_get_logger( $error );
459 - wp_send_json_error( [ 'mess' => $error->getMessage() ] );
460 321 } catch ( \Exception $exception ) {
461 322 yaymail_get_logger( $exception );
462 - wp_send_json_error( [ 'mess' => $exception->getMessage() ] );
463 323 }//end try
464 324 }
465 325
466 326 public function preview_mail() {
@@ -468,10 +328,10 @@
468 328 if ( ! wp_verify_nonce( $nonce, 'yaymail_frontend_nonce' ) ) {
469 329 return wp_send_json_error( [ 'mess' => __( 'Verify nonce failed', 'yaymail' ) ] );
470 330 }
471 331 try {
472 - $order_id = ! empty( $_POST['order_id'] ) ? sanitize_text_field( wp_unslash( $_POST['order_id'] ) ) : 'sample_order';
473 - $template_data = isset( $_POST['template_data'] ) ? $this->sanitize( json_decode( wp_unslash( $_POST['template_data'] ), true ) ) : []; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
332 + $order_id = isset( $_POST['order_id'] ) ? sanitize_text_field( wp_unslash( $_POST['order_id'] ) ) : 'sample_order';
333 + $template_data = isset( $_POST['template_data'] ) ? $this->sanitize( wp_unslash( $_POST['template_data'] ) ) : []; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
474 334 $unsaved_settings = isset( $_POST['unsaved_settings'] ) ? $this->sanitize( wp_unslash( $_POST['unsaved_settings'] ) ) : []; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
475 335
476 336 if ( empty( $template_data ) ) {
477 337 return wp_send_json_error( [ 'mess' => __( 'Can\'t find template', 'yaymail' ) ] );
@@ -506,25 +366,23 @@
506 366 // check if email template on preview and send test mail
507 367
508 368 $html = $template->get_content( $render_data );
509 369
510 - if ( strpos( $template->get_name(), 'wp-core-' ) !== 0 ) {
511 - // TODO: render with passing settings
512 - $current_email = null;
513 - $subject = 'Sample Subject';
514 - $emails = wc()->mailer()->emails;
515 - foreach ( $emails as $email ) {
516 - if ( $email->id === $template_data['name'] ) {
517 - $current_email = $email;
518 - if ( method_exists( $current_email, 'set_object' ) ) {
519 - if ( ! empty( $render_data['order'] ) && is_a( $render_data['order'], '\WC_Order' ) ) {
520 - $current_email->set_object( $render_data['order'] );
521 - } else {
522 - $current_email->set_object( Helpers::get_dummy_order() );
523 - }
370 + // TODO: render with passing settings
371 + $current_email = null;
372 + $subject = 'Sample Subject';
373 + $emails = wc()->mailer()->emails;
374 + foreach ( $emails as $email ) {
375 + if ( $email->id === $template_data['name'] ) {
376 + $current_email = $email;
377 + if ( method_exists( $current_email, 'set_object' ) ) {
378 + if ( ! empty( $render_data['order'] ) && is_a( $render_data['order'], '\WC_Order' ) ) {
379 + $current_email->set_object( $render_data['order'] );
380 + } else {
381 + $current_email->set_object( Helpers::get_dummy_order() );
524 382 }
525 - break;
526 383 }
384 + break;
527 385 }
528 386 }
529 387
530 388 if ( ! empty( $current_email ) ) {
@@ -540,12 +398,10 @@
540 398 ]
541 399 );
542 400 } catch ( \Error $error ) {
543 401 yaymail_get_logger( $error );
544 - wp_send_json_error( [ 'mess' => $error->getMessage() ] );
545 402 } catch ( \Exception $exception ) {
546 403 yaymail_get_logger( $exception );
547 - wp_send_json_error( [ 'mess' => $exception->getMessage() ] );
548 404 }//end try
549 405 }
550 406
551 407 public function preview_mail_for_woo() {
@@ -556,13 +412,12 @@
556 412 try {
557 413 $template_name = isset( $_POST['template_name'] ) ? sanitize_text_field( wp_unslash( $_POST['template_name'] ) ) : '';
558 414 $search_order_id = isset( $_POST['search_order_id'] ) ? sanitize_text_field( wp_unslash( $_POST['search_order_id'] ) ) : null;
559 415 $email_address = isset( $_POST['email_address'] ) ? sanitize_text_field( wp_unslash( $_POST['email_address'] ) ) : '';
560 - $variant = yaymail_sanitize_template_variant( isset( $_POST['variant'] ) ? sanitize_text_field( wp_unslash( $_POST['variant'] ) ) : '' );
561 416
562 - $email_preview_output = PreviewEmail\PreviewEmailWoo::email_preview_output( $search_order_id, $template_name, $email_address, $variant );
417 + $email_preview_output = PreviewEmail\PreviewEmailWoo::email_preview_output( $search_order_id, $template_name, $email_address );
563 418
564 - $email_preview_output = apply_filters( 'yaymail_preview_email', $email_preview_output, $search_order_id, $template_name, $email_address, $variant );
419 + $email_preview_output = apply_filters( 'yaymail_preview_email', $email_preview_output, $search_order_id, $template_name, $email_address );
565 420
566 421 $send_mail = false;
567 422
568 423 if ( ! empty( $email_address ) && ! empty( $email_preview_output['html'] ) ) {
@@ -584,12 +439,10 @@
584 439 ]
585 440 );
586 441 } catch ( \Error $error ) {
587 442 yaymail_get_logger( $error );
588 - wp_send_json_error( [ 'mess' => $error->getMessage() ] );
589 443 } catch ( \Exception $exception ) {
590 444 yaymail_get_logger( $exception );
591 - wp_send_json_error( [ 'mess' => $exception->getMessage() ] );
592 445 }//end try
593 446 }
594 447
595 448 public function export_templates() {
@@ -609,13 +462,8 @@
609 462 'key' => YayMailTemplate::META_KEYS['name'],
610 463 'value' => $templates,
611 464 'compare' => 'IN',
612 465 ],
613 - // Export the default design only; import keys on name and would collapse variants onto it.
614 - [
615 - 'key' => YayMailTemplate::META_KEYS['variant'],
616 - 'compare' => 'NOT EXISTS',
617 - ],
618 466 ],
619 467 ];
620 468 $export_data = [];
621 469 $query = new \WP_Query( $default );
@@ -628,29 +476,24 @@
628 476 $text_link_color = get_post_meta( $post->ID, YayMailTemplate::META_KEYS['text_link_color'], true );
629 477 $background_color = get_post_meta( $post->ID, YayMailTemplate::META_KEYS['background_color'], true );
630 478 $content_background_color = get_post_meta( $post->ID, YayMailTemplate::META_KEYS['content_background_color'], true );
631 479 $content_text_color = get_post_meta( $post->ID, YayMailTemplate::META_KEYS['content_text_color'], true );
632 - $title_color = get_post_meta( $post->ID, YayMailTemplate::META_KEYS['title_color'], true );
633 480 $file_name = "{$template_name}.json";
634 - // Every WP-core template (e.g. wp-core-mail) is saved with a
635 - // non-empty language meta (the site locale), unlike WooCommerce
636 - // templates -- gating on "no language" here used to silently
637 - // drop every WP-core template from the export with no error.
638 - // find_by_name() below only ever looks templates up by name, so
639 - // there's no separate per-language row to disambiguate against.
640 - $export_data[] = [
641 - 'file_name' => $file_name,
642 - 'templates_data' => [
643 - 'template' => $template_name,
644 - 'elements' => $elements,
645 - 'language' => $language,
646 - 'text_link_color' => $text_link_color,
647 - 'background_color' => $background_color,
648 - 'content_background_color' => $content_background_color,
649 - 'content_text_color' => $content_text_color,
650 - 'title_color' => $title_color,
651 - ],
652 - ];
481 + if ( empty( $language ) ) {
482 + $export_data[] = [
483 + 'file_name' => $file_name,
484 + 'templates_data' => [
485 + 'template' => $template_name,
486 + 'elements' => $elements,
487 + 'language' => '',
488 + 'text_link_color' => $text_link_color,
489 + 'background_color' => $background_color,
490 + 'content_background_color' => $content_background_color,
491 + 'content_text_color' => $content_text_color,
492 + 'title_color' => $title_color,
493 + ],
494 + ];
495 + }
653 496 }//end foreach
654 497 }//end if
655 498 wp_reset_postdata();
656 499 wp_send_json_success(
@@ -656,17 +499,15 @@
656 499 wp_send_json_success(
657 500 [
658 501 'message' => __( 'Export successfully', 'yaymail' ),
659 502 'data' => $export_data,
660 - 'file_name' => $this->export_file_name_prefix() . '_customizer_templates_' . gmdate( 'm-d-Y' ),
503 + 'file_name' => 'yaymail_customizer_templates_' . gmdate( 'm-d-Y' ),
661 504 ]
662 505 );
663 506 } catch ( \Error $error ) {
664 507 yaymail_get_logger( $error );
665 - wp_send_json_error( [ 'mess' => $error->getMessage() ] );
666 508 } catch ( \Exception $exception ) {
667 509 yaymail_get_logger( $exception );
668 - wp_send_json_error( [ 'mess' => $exception->getMessage() ] );
669 510 }//end try
670 511 }
671 512
672 513 public function import_templates() {
@@ -686,12 +527,10 @@
686 527 wp_send_json_error( [ 'message' => __( 'Can\'t find import files.', 'yaymail' ) ] );
687 528 }
688 529 } catch ( \Error $error ) {
689 530 yaymail_get_logger( $error );
690 - wp_send_json_error( [ 'mess' => $error->getMessage() ] );
691 531 } catch ( \Exception $exception ) {
692 532 yaymail_get_logger( $exception );
693 - wp_send_json_error( [ 'mess' => $exception->getMessage() ] );
694 533 }
695 534 }
696 535
697 536 public function process_import( $files ) {
@@ -749,15 +588,13 @@
749 588 return $updated_templates;
750 589 }
751 590
752 591 public function processing_import_update_data( $data, $is_legacy = false ) {
753 - $template_name = $data['template'] ?? null;
754 - $elements = $data['elements'] ?? null;
755 - $text_link_color = $data['text_link_color'] ?? null;
756 - $background_color = $data['background_color'] ?? null;
757 - $title_color = $data['title_color'] ?? null;
758 - $content_background_color = $data['content_background_color'] ?? null;
759 - $content_text_color = $data['content_text_color'] ?? null;
592 + $template_name = $data['template'] ?? null;
593 + $elements = $data['elements'] ?? null;
594 + $text_link_color = $data['text_link_color'] ?? null;
595 + $background_color = $data['background_color'] ?? null;
596 + $title_color = $data['title_color'] ?? null;
760 597
761 598 if ( empty( $template_name ) ) {
762 599 return null;
763 600 }
@@ -840,12 +677,10 @@
840 677 ]
841 678 );
842 679 } catch ( \Error $error ) {
843 680 yaymail_get_logger( $error );
844 - wp_send_json_error( [ 'mess' => $error->getMessage() ] );
845 681 } catch ( \Exception $exception ) {
846 682 yaymail_get_logger( $exception );
847 - wp_send_json_error( [ 'mess' => $exception->getMessage() ] );
848 683 }//end try
849 684 }
850 685
851 686 /**
@@ -859,11 +694,10 @@
859 694 try {
860 695 $setting_model = SettingModel::get_instance();
861 696 $settings_data = $setting_model->find_all();
862 697
863 - $template_name = isset( $_POST['data']['template_name'] ) ? sanitize_text_field( wp_unslash( $_POST['data']['template_name'] ) ) : 'new_order';
864 - $order_id = isset( $_POST['data']['order_id'] ) ? sanitize_text_field( wp_unslash( $_POST['data']['order_id'] ) ) : 'sample_order';
865 - $variant = yaymail_sanitize_template_variant( isset( $_POST['data']['variant'] ) ? sanitize_text_field( wp_unslash( $_POST['data']['variant'] ) ) : '' );
698 + $template_name = isset( $_POST['data']['template_name'] ) ? sanitize_text_field( $_POST['data']['template_name'] ) : 'new_order';
699 + $order_id = isset( $_POST['data']['order_id'] ) ? sanitize_text_field( $_POST['data']['order_id'] ) : 'sample_order';
866 700
867 701 $template_model = TemplateModel::get_instance();
868 702
869 703 $shortcodes_data = $template_model->get_shortcodes_by_template_name_and_order_id( $template_name, $order_id );
@@ -869,14 +703,14 @@
869 703 $shortcodes_data = $template_model->get_shortcodes_by_template_name_and_order_id( $template_name, $order_id );
870 704
871 705 $templates_data = apply_filters( 'yaymail_get_all_templates', $template_model->find_all() );
872 706
873 - $selected_template_data = $template_model->find_by_name( $template_name, '', $variant );
707 + $selected_template_data = $template_model->find_by_name( $template_name );
874 708
875 709 $elements_data = TemplateModel::get_elements_for_template( $template_name );
876 710
877 711 $revision_model = RevisionModel::get_instance();
878 - $revisions_data = $revision_model->get_by_template( $template_name, $variant );
712 + $revisions_data = $revision_model->get_by_template( $template_name );
879 713
880 714 wp_send_json_success(
881 715 [
882 716 'settings_data' => $settings_data,
@@ -915,12 +749,10 @@
915 749 );
916 750
917 751 } catch ( \Error $error ) {
918 752 yaymail_get_logger( $error );
919 - wp_send_json_error( [ 'mess' => $error->getMessage() ] );
920 753 } catch ( \Exception $exception ) {
921 754 yaymail_get_logger( $exception );
922 - wp_send_json_error( [ 'mess' => $exception->getMessage() ] );
923 755 }
924 756 }
925 757
926 758 public function change_ghf_tour() {
@@ -939,12 +771,10 @@
939 771 ]
940 772 );
941 773 } catch ( \Error $error ) {
942 774 yaymail_get_logger( $error );
943 - wp_send_json_error( [ 'mess' => $error->getMessage() ] );
944 775 } catch ( \Exception $exception ) {
945 776 yaymail_get_logger( $exception );
946 - wp_send_json_error( [ 'mess' => $exception->getMessage() ] );
947 777 }
948 778 }
949 779
950 780 public function dismiss_multi_select_notice() {
@@ -962,12 +792,10 @@
962 792 ]
963 793 );
964 794 } catch ( \Error $error ) {
965 795 yaymail_get_logger( $error );
966 - wp_send_json_error( [ 'mess' => $error->getMessage() ] );
967 796 } catch ( \Exception $exception ) {
968 797 yaymail_get_logger( $exception );
969 - wp_send_json_error( [ 'mess' => $exception->getMessage() ] );
970 798 }
971 799 }
972 800
973 801 public function dismiss_new_element_notification() {
@@ -992,8 +820,7 @@
992 820 } catch ( \Error $error ) {
993 821 wp_send_json_error( [ 'mess' => $error->getMessage() ] );
994 822 } catch ( \Exception $exception ) {
995 823 yaymail_get_logger( $exception );
996 - wp_send_json_error( [ 'mess' => $exception->getMessage() ] );
997 824 }
998 825 }
999 -}
826 +}