'1', 'e' => rawurlencode( $email ), 's' => self::sign( $email ) ), home_url( '/' ) ); } public static function header_value( $email ) { $parts = array( '<' . esc_url_raw( self::url( $email ) ) . '>' ); $admin = sanitize_email( (string) get_option( 'admin_email' ) ); if ( is_email( $admin ) ) { $parts[] = ''; } return implode( ', ', $parts ); } public static function append_footer( $html, $email, $kind = 'marketing' ) { $html = (string) $html; if ( '' === trim( (string) $email ) ) { return $html; } $u = esc_url( self::url( $email ) ); $site = (string) get_bloginfo( 'name' ); $why = ( 'transactional' === $kind ) ? sprintf( __( 'You are receiving this email about your order or request at %s.', 'ai-eshop-optimizer' ), $site ) : sprintf( __( 'You are receiving this because you opted in to marketing from %s.', 'ai-eshop-optimizer' ), $site ); $from = self::sender_address(); $tone = class_exists( 'AIEO_Email_Frame' ) ? (string) ( AIEO_Email_Frame::colours()['footer_text'] ?? '' ) : ''; $colour = '' !== $tone ? 'color:' . $tone . ';' : ''; $footer = '
' . esc_html( $why ) . ( '' !== $from ? '
' . esc_html( sprintf( __( 'Sent by %1$s, %2$s.', 'ai-eshop-optimizer' ), $site, $from ) ) : '' ) . '
' . esc_html__( 'Unsubscribe from these emails', 'ai-eshop-optimizer' ) . '' . '
'; if ( false !== stripos( $html, '' ) ) { return preg_replace( '/<\/body>/i', $footer . '', $html, 1 ); } return $html . $footer; } public static function sender_address() { $where = explode( ':', (string) get_option( 'woocommerce_default_country', '' ), 2 ); $parts = array( 'address_1' => trim( (string) get_option( 'woocommerce_store_address', '' ) ), 'address_2' => trim( (string) get_option( 'woocommerce_store_address_2', '' ) ), 'city' => trim( (string) get_option( 'woocommerce_store_city', '' ) ), 'postcode' => trim( (string) get_option( 'woocommerce_store_postcode', '' ) ), 'country' => (string) $where[0], ); if ( '' === $parts['address_1'] && '' === $parts['city'] ) { return ''; } $line = ''; if ( function_exists( 'WC' ) && WC() && isset( WC()->countries ) && is_object( WC()->countries ) ) { $named = static function () { return true; }; add_filter( 'woocommerce_formatted_address_force_country_display', $named ); $line = (string) WC()->countries->get_formatted_address( $parts, ', ' ); remove_filter( 'woocommerce_formatted_address_force_country_display', $named ); $line = trim( (string) preg_replace( '/\s+/u', ' ', wp_strip_all_tags( $line ) ), " ,\t\n\r" ); } if ( '' === $line ) { $line = implode( ', ', array_filter( array( $parts['address_1'], $parts['address_2'], trim( $parts['postcode'] . ' ' . $parts['city'] ), $parts['country'] ) ) ); } return trim( (string) apply_filters( 'aieo_email_sender_address', $line, $parts ) ); } public static function maybe_handle() { if ( ! isset( $_GET[ self::QP ] ) ) { return; } $email = isset( $_GET['e'] ) ? strtolower( trim( rawurldecode( wp_unslash( $_GET['e'] ) ) ) ) : ''; $sig = isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : ''; $ok = ( '' !== $email && is_email( $email ) && hash_equals( self::sign( $email ), $sig ) ); if ( $ok && class_exists( 'AIEO_AW_Decommission' ) ) { AIEO_AW_Decommission::add_suppression( $email, 'email_unsubscribe' ); do_action( 'aieo_email_unsubscribed', $email ); } if ( 'POST' === ( isset( $_SERVER['REQUEST_METHOD'] ) ? strtoupper( (string) $_SERVER['REQUEST_METHOD'] ) : 'GET' ) ) { status_header( $ok ? 200 : 400 ); exit; } self::confirmation_page( $ok ); } private static function confirmation_page( $ok ) { nocache_headers(); status_header( 200 ); $site = esc_html( get_bloginfo( 'name' ) ); $msg = $ok ? esc_html__( 'You have been unsubscribed. You will no longer receive marketing emails from us.', 'ai-eshop-optimizer' ) : esc_html__( 'This unsubscribe link is invalid or has expired.', 'ai-eshop-optimizer' ); echo '' . '' . esc_html__( 'Unsubscribe', 'ai-eshop-optimizer' ) . '' . '' . '
' . '

' . $site . '

' . '

' . $msg . '

'; exit; } }