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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Internal / Admin / EmailImprovements / EmailImprovements.php
woocommerce / src / Internal / Admin / EmailImprovements Last commit date
EmailImprovements.php 1 year ago
EmailImprovements.php
266 lines
1 <?php
2 /**
3 * Helper class to gradually enable email improvements to existing merchants.
4 *
5 * @since 9.9.0
6 */
7
8 declare( strict_types=1 );
9
10 namespace Automattic\WooCommerce\Internal\Admin\EmailImprovements;
11
12 use Automattic\WooCommerce\Utilities\FeaturesUtil;
13 use WC_Tracker;
14
15 defined( 'ABSPATH' ) || exit;
16
17 /**
18 * EmailImprovements Class.
19 */
20 class EmailImprovements {
21
22 /**
23 * Non-exhaustive list of email customizers.
24 *
25 * @var string[]
26 */
27 private const EMAIL_CUSTOMIZERS = array(
28 'aco-email-customizer-and-designer-for-woocommerce.php',
29 'decorator.php',
30 'email-customizer-for-woocommerce.php',
31 'email-customizer-pro.php',
32 'kadence-woocommerce-email-designer.php',
33 'mailpoet.php',
34 'wp-html-mail.php',
35 'yaymail.php',
36 );
37
38 private const EMAIL_TEMPLATE_PARTS = array(
39 'email-addresses.php',
40 'email-customer-details.php',
41 'email-downloads.php',
42 'email-footer.php',
43 'email-header.php',
44 'email-mobile-messaging.php',
45 'email-order-details.php',
46 'email-order-items.php',
47 'email-styles.php',
48 );
49
50 /**
51 * Hook into WordPress.
52 */
53 public function __construct() {
54 add_action( 'admin_init', array( __CLASS__, 'add_email_improvements_modal_to_url' ) );
55 }
56
57 /**
58 * Check if any core emails are being overridden by a template override.
59 *
60 * @return bool True if core emails are being overridden, false otherwise.
61 */
62 public static function has_email_templates_overridden() {
63 $all_template_overrides = WC_Tracker::get_all_template_overrides();
64 $core_email_overrides = self::get_core_email_overrides( $all_template_overrides );
65 return count( $core_email_overrides ) > 0;
66 }
67
68 /**
69 * Check if any of the email customizers is enabled.
70 *
71 * @return bool True if any of the email customizers is enabled, false otherwise.
72 */
73 public static function is_email_customizer_enabled() {
74 $all_plugins = WC_Tracker::get_all_plugins();
75 $active_plugins = $all_plugins['active_plugins'];
76 $plugin_slugs = array_map(
77 function ( $plugin_path ) {
78 $parts = explode( '/', $plugin_path );
79 return end( $parts );
80 },
81 array_keys( $active_plugins )
82 );
83 return count( array_intersect( self::EMAIL_CUSTOMIZERS, $plugin_slugs ) ) > 0;
84 }
85
86 /**
87 * Check if email improvements are enabled for existing stores.
88 *
89 * @return bool True if email improvements are enabled for existing stores, false otherwise.
90 */
91 public static function is_email_improvements_enabled_for_existing_stores() {
92 $is_feature_enabled = FeaturesUtil::feature_is_enabled( 'email_improvements' );
93 $is_enabled_for_existing_stores = 'yes' === get_option( 'woocommerce_email_improvements_existing_store_enabled' );
94 return $is_feature_enabled && $is_enabled_for_existing_stores;
95 }
96
97 /**
98 * Check if email improvements should be enabled for existing stores.
99 * - The feature is not already enabled.
100 * - The feature was not manually disabled.
101 * - The email templates are not overridden.
102 * - The email customizer is not enabled.
103 *
104 * @return bool True if email improvements should be enabled for existing stores, false otherwise.
105 */
106 public static function should_enable_email_improvements_for_existing_stores() {
107 if ( FeaturesUtil::feature_is_enabled( 'email_improvements' ) ) {
108 return false;
109 }
110 $manually_disabled_before = get_option( 'woocommerce_email_improvements_last_disabled_at' );
111 if ( $manually_disabled_before ) {
112 return false;
113 }
114 if ( self::has_email_templates_overridden() ) {
115 return false;
116 }
117
118 if ( self::is_email_customizer_enabled() ) {
119 return false;
120 }
121 // Temporarily paused roll-out to gather more feedback.
122 return false;
123 }
124
125 /**
126 * Check if we should notice the merchant about email improvements.
127 *
128 * @return bool True if we should notice the merchant about email improvements, false otherwise.
129 */
130 public static function should_notify_merchant_about_email_improvements() {
131 return ! FeaturesUtil::feature_is_enabled( 'email_improvements' );
132 }
133
134 /**
135 * Add email improvements modal parameter to the URL when loading the WooCommerce Home page.
136 *
137 * @return void
138 */
139 public static function add_email_improvements_modal_to_url() {
140 // Check if we're on the WooCommerce Home page.
141 if ( ! isset( $_GET['page'] ) || 'wc-admin' !== $_GET['page'] || isset( $_GET['path'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
142 return;
143 }
144
145 $dismissed_modal = get_option( 'woocommerce_admin_dismissed_email_improvements_modal' );
146 if ( 'yes' !== $dismissed_modal && self::is_email_improvements_enabled_for_existing_stores() ) {
147 update_option( 'woocommerce_admin_dismissed_email_improvements_modal', 'yes' );
148 wp_safe_redirect( add_query_arg( 'emailImprovementsModal', 'enabled' ) );
149 exit;
150 }
151
152 $dismissed_modal = get_option( 'woocommerce_admin_dismissed_try_email_improvements_modal' );
153 if ( 'yes' !== $dismissed_modal && self::should_notify_merchant_about_email_improvements() ) {
154 update_option( 'woocommerce_admin_dismissed_try_email_improvements_modal', 'yes' );
155 wp_safe_redirect( add_query_arg( 'emailImprovementsModal', 'try' ) );
156 exit;
157 }
158 }
159
160 /**
161 * Get all core emails.
162 *
163 * @return array Core emails.
164 */
165 public static function get_core_emails() {
166 return array_filter(
167 self::get_emails(),
168 function ( $email ) {
169 return strpos( get_class( $email ), 'WC_Email_' ) === 0 && is_string( $email->template_html );
170 }
171 );
172 }
173
174 /**
175 * Get all core email template overrides.
176 *
177 * @param array $template_overrides All template overrides.
178 * @return array Core email template overrides.
179 */
180 public static function get_core_email_overrides( $template_overrides ) {
181 $core_emails = self::get_core_emails();
182 $core_email_templates = array_map(
183 function ( $email ) {
184 return basename( $email->template_html );
185 },
186 $core_emails
187 );
188 $all_email_templates = array_merge( $core_email_templates, self::EMAIL_TEMPLATE_PARTS );
189 return array_intersect( $all_email_templates, $template_overrides );
190 }
191
192 /**
193 * Get all enabled email IDs.
194 *
195 * @return array Enabled email IDs.
196 */
197 public static function get_enabled_emails() {
198 $enabled_emails = array_filter(
199 self::get_emails(),
200 function ( $email ) {
201 return $email->is_enabled() && ! $email->is_manual();
202 }
203 );
204 return array_values( array_map( fn( $email ) => get_class( $email ), $enabled_emails ) );
205 }
206
207 /**
208 * Get all disabled email IDs.
209 *
210 * @return array Enabled email IDs.
211 */
212 public static function get_disabled_emails() {
213 $disabled_emails = array_filter(
214 self::get_emails(),
215 function ( $email ) {
216 return ! $email->is_enabled() && ! $email->is_manual();
217 }
218 );
219 return array_values( array_map( fn( $email ) => get_class( $email ), $disabled_emails ) );
220 }
221
222 /**
223 * Get all enabled or manual emails with Cc or Bcc.
224 *
225 * @return array Enabled or manual emails with Cc or Bcc.
226 */
227 public static function get_enabled_or_manual_emails_with_cc_or_bcc() {
228 $enabled_or_manual_emails = array_filter(
229 self::get_emails(),
230 function ( $email ) {
231 return $email->is_enabled() || $email->is_manual();
232 }
233 );
234
235 $email_ids_with_cc = array();
236 $email_ids_with_bcc = array();
237
238 foreach ( $enabled_or_manual_emails as $email ) {
239 if ( $email->get_cc_recipient() ) {
240 $email_ids_with_cc[] = get_class( $email );
241 }
242 if ( $email->get_bcc_recipient() ) {
243 $email_ids_with_bcc[] = get_class( $email );
244 }
245 }
246
247 return array(
248 'ccs' => $email_ids_with_cc,
249 'bccs' => $email_ids_with_bcc,
250 );
251 }
252
253 /**
254 * A helper method to filter out non-WC_Email objects.
255 *
256 * @return \WC_Email[] All WC_Email objects.
257 */
258 private static function get_emails() {
259 $emails = WC()->mailer()->get_emails();
260 return array_filter(
261 $emails,
262 fn( $email ) => is_object( $email ) && $email instanceof \WC_Email
263 );
264 }
265 }
266