From 88f4fa46dc7285a564a5effaf705c2d92ac0bf3e Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Wed, 17 May 2023 07:58:24 -0400 Subject: [PATCH 1/3] Fix incorrect word use --- includes/internal/emails/class-recreate-emails-tool.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/internal/emails/class-recreate-emails-tool.php b/includes/internal/emails/class-recreate-emails-tool.php index f0b164346a..17d7e42876 100644 --- a/includes/internal/emails/class-recreate-emails-tool.php +++ b/includes/internal/emails/class-recreate-emails-tool.php @@ -78,7 +78,7 @@ public function get_id() { * @return string */ public function get_name() { - return __( 'Recreate Emails', 'sensei-lms' ); + return __( 'Re-create Emails', 'sensei-lms' ); } /** @@ -88,7 +88,7 @@ public function get_name() { */ public function get_description() { return __( - 'Recreate all emails. Existing customizations will be lost.', + 'Re-create all emails. Existing customizations will be lost.', 'sensei-lms' ); } @@ -101,7 +101,7 @@ public function process() { $result = $this->seeder->create_all( true ); $message = $result - ? __( 'Emails were recreated successfully.', 'sensei-lms' ) + ? __( 'Emails were re-created successfully.', 'sensei-lms' ) : __( 'There were errors while recreating emails.', 'sensei-lms' ); $this->tools->add_user_message( $message, ! $result ); } From 7cb9b6b95c2796e4b766ebdfd20cc91370e92092 Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Wed, 17 May 2023 07:59:33 -0400 Subject: [PATCH 2/3] Missed one --- includes/internal/emails/class-recreate-emails-tool.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/internal/emails/class-recreate-emails-tool.php b/includes/internal/emails/class-recreate-emails-tool.php index 17d7e42876..b2c213449e 100644 --- a/includes/internal/emails/class-recreate-emails-tool.php +++ b/includes/internal/emails/class-recreate-emails-tool.php @@ -102,7 +102,7 @@ public function process() { $message = $result ? __( 'Emails were re-created successfully.', 'sensei-lms' ) - : __( 'There were errors while recreating emails.', 'sensei-lms' ); + : __( 'There were errors while re-creating emails.', 'sensei-lms' ); $this->tools->add_user_message( $message, ! $result ); } From 7b74fb5d57a07b477606bd8186ebfc06f4e9ab29 Mon Sep 17 00:00:00 2001 From: Donna Peplinskie Date: Fri, 19 May 2023 15:06:40 -0400 Subject: [PATCH 3/3] Preserve email status when emails are re-created --- .../internal/emails/class-email-seeder.php | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/includes/internal/emails/class-email-seeder.php b/includes/internal/emails/class-email-seeder.php index 8a3c9a7d1f..a934df37f4 100644 --- a/includes/internal/emails/class-email-seeder.php +++ b/includes/internal/emails/class-email-seeder.php @@ -9,6 +9,7 @@ use Sensei\Internal\Emails\Email_Seeder_Data; use Sensei\Internal\Emails\Email_Repository; +use WP_Query; if ( ! defined( 'ABSPATH' ) ) { exit; @@ -93,6 +94,24 @@ public function create_email( string $identifier, bool $force = false ): bool { return false; } + // Preserve existing email status when re-creating. + $query = new WP_Query( + [ + 'post_type' => Email_Post_Type::POST_TYPE, + 'post_status' => 'any', + 'meta_key' => '_sensei_email_identifier', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key + 'meta_value' => $identifier, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value + ] + ); + + if ( ! empty( $query->posts ) ) { + if ( 'publish' === $query->posts[0]->post_status ) { + $disabled = false; + } else { + $disabled = true; + } + } + $this->email_repository->delete( $identifier ); } @@ -117,9 +136,11 @@ public function create_email( string $identifier, bool $force = false ): bool { } $description = $email_data['description'] ?? ''; + $is_pro = $email_data['is_pro'] ?? false; - $is_pro = $email_data['is_pro'] ?? false; - $disabled = $email_data['disabled'] ?? false; + if ( ! isset( $disabled ) ) { + $disabled = $email_data['disabled'] ?? false; + } $email_id = $this->email_repository->create( $identifier, $types, $subject, $description, $content, $is_pro, $disabled );