unction add_email_improvements_modal_to_url() { // Check if we're on the WooCommerce Home page. if ( ! isset( $_GET['page'] ) || 'wc-admin' !== $_GET['page'] || isset( $_GET['path'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return; } $dismissed_modal = get_option( 'woocommerce_admin_dismissed_email_improvements_modal' ); if ( 'yes' !== $dismissed_modal && self::is_email_improvements_enabled_for_existing_stores() ) { update_option( 'woocommerce_admin_dismissed_email_improvements_modal', 'yes' ); wp_safe_redirect( add_query_arg( 'emailImprovementsModal', 'enabled' ) ); exit; } $dismissed_modal = get_option( 'woocommerce_admin_dismissed_try_email_improvements_modal' ); if ( 'yes' !== $dismissed_modal && self::should_notify_merchant_about_email_improvements() ) { update_option( 'woocommerce_admin_dismissed_try_email_improvements_modal', 'yes' ); wp_safe_redirect( add_query_arg( 'emailImprovementsModal', 'try' ) ); exit; } } /** * Get all core emails. * * @return array Core emails. */ public static function get_core_emails() { return array_filter( self::get_emails(), function ( $email ) { return strpos( get_class( $email ), 'WC_Email_' ) === 0 && is_string( $email->template_html ); } ); } /** * Get all core email template overrides. * * @param array $template_overrides All template overrides. * @return array Core email template overrides. */ public static function get_core_email_overrides( $template_overrides ) { $core_emails = self::get_core_emails(); $core_email_templates = array_map( function ( $email ) { return basename( $email->template_html ); }, $core_emails ); $all_email_templates = array_merge( $core_email_templates, self::EMAIL_TEMPLATE_PARTS ); return array_intersect( $all_email_templates, $template_overrides ); } /** * Get all enabled email IDs. * * @return array Enabled email IDs. */ public static function get_enabled_emails() { $enabled_emails = array_filter( self::get_emails(), function ( $email ) { return $email->is_enabled() && ! $email->is_manual(); } ); return array_values( array_map( fn( $email ) => get_class( $email ), $enabled_emails ) ); } /** * Get all disabled email IDs. * * @return array Enabled email IDs. */ public static function get_disabled_emails() { $disabled_emails = array_filter( self::get_emails(), function ( $email ) { return ! $email->is_enabled() && ! $email->is_manual(); } ); return array_values( array_map( fn( $email ) => get_class( $email ), $disabled_emails ) ); } /** * Get all enabled or manual emails with Cc or Bcc. * * @return array Enabled or manual emails with Cc or Bcc. */ public static function get_enabled_or_manual_emails_with_cc_or_bcc() { $enabled_or_manual_emails = array_filter( self::get_emails(), function ( $email ) { return $email->is_enabled() || $email->is_manual(); } ); $email_ids_with_cc = array(); $email_ids_with_bcc = array(); foreach ( $enabled_or_manual_emails as $email ) { if ( $email->get_cc_recipient() ) { $email_ids_with_cc[] = get_class( $email ); } if ( $email->get_bcc_recipient() ) { $email_ids_with_bcc[] = get_class( $email ); } } return array( 'ccs' => $email_ids_with_cc, 'bccs' => $email_ids_with_bcc, ); } /** * A helper method to filter out non-WC_Email objects. * * @return \WC_Email[] All WC_Email objects. */ private static function get_emails() { $emails = WC()->mailer()->get_emails(); return array_filter( $emails, fn( $email ) => is_object( $email ) && $email instanceof \WC_Email ); } }