Plugin Directory

Changeset 2785694


Ignore:
Timestamp:
09/16/2022 03:31:30 AM (4 years ago)
Author:
wiloke
Message:

Resolved some small issues in email template

Location:
email-creatior/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • email-creatior/trunk/README.md

    r2779503 r2785694  
    66Tested up to: 6.0.1
    77Requires PHP: 7.4
    8 Stable tag: 1.0.8
     8Stable tag: 1.0.9
    99License: GPLv2 or later
    1010
  • email-creatior/trunk/emailcreator.php

    r2779503 r2785694  
    55 * Author: wiloke
    66 * Author URI: https://wiloke.com/
    7  * Version: 1.0.8
     7 * Version: 1.0.9
    88 * Domain Path: /languages
    99 * Requires PHP: 7.4
     
    1717
    1818
    19 define('WILOKE_EMAIL_CREATOR_VERSION', defined('WP_DEBUG') && WP_DEBUG ? uniqid() : '1.0.8');
     19define('WILOKE_EMAIL_CREATOR_VERSION', defined('WP_DEBUG') && WP_DEBUG ? uniqid() : '1.0.9');
    2020define('WILOKE_EMAIL_CREATOR_HOOK_PREFIX', ' wiloke-email-creator/');
    2121define('WILOKE_EMAIL_CREATOR_PREFIX', 'wilETP_');
  • email-creatior/trunk/src/Email/Controllers/EmailController.php

    r2779511 r2785694  
    299299    }
    300300
    301     public function actionSendEmail($email, $subject, $body, $aHeader
     301    public function actionSendEmail(
     302        $email, $subject, $body, $aHeader
    302303    = [
    303304        'Content-Type: text/html; charset=UTF-8'
    304     ])
    305     {
    306         return wp_mail(sanitize_email($email), $subject, $body, $aHeader);
     305    ]
     306    )
     307    {
     308        return wp_mail(
     309            sanitize_email($email),
     310            wp_kses(html_entity_decode(wp_unslash($subject)), [
     311                "img" => [
     312                    "src"        => true,
     313                    "alt"        => true,
     314                    "class"      => true,
     315                    "aria-label" => true,
     316                    "loading"    => true
     317                ]
     318            ]),
     319            $body,
     320            $aHeader
     321        );
    307322    }
    308323}
  • email-creatior/trunk/src/Email/Controllers/ReplaceEmailController.php

    r2779503 r2785694  
    226226    }
    227227
     228    private function replaceEmailSubjectCommon($postID, array $aVariables, $oldSubject)
     229    {
     230        $emailSubject = get_post_meta($postID, AutoPrefix::namePrefix('emailSubject'), true);
     231        if (empty($emailSubject)) {
     232            return $oldSubject;
     233        }
     234
     235        return str_replace(array_keys($aVariables), array_values($aVariables), $emailSubject);
     236    }
     237
    228238    public function replaceSubjectNewOrder($subject, $oOrder)
    229239    {
     
    231241        $aKeyEmailType = $this->handleListKeyEmailTypeUsedUser();
    232242        if ($postID = (int)array_search('new_order', $aKeyEmailType)) {
    233             $emailSubject = get_post_meta($postID, AutoPrefix::namePrefix('emailSubject'), true);
    234             $subject = str_replace(array_keys($aVariables), array_values($aVariables), $emailSubject);
     243            return $this->replaceEmailSubjectCommon($postID, $aVariables, $subject);
    235244        }
    236245
     
    243252        $aKeyEmailType = $this->handleListKeyEmailTypeUsedUser();
    244253        if ($postID = (int)array_search('cancelled_order', $aKeyEmailType)) {
    245             $emailSubject = get_post_meta($postID, AutoPrefix::namePrefix('emailSubject'), true);
    246             $subject = str_replace(array_keys($aVariables), array_values($aVariables), $emailSubject);
     254            return $this->replaceEmailSubjectCommon($postID, $aVariables, $subject);
    247255        }
    248256        return $subject;
     
    254262        $aKeyEmailType = $this->handleListKeyEmailTypeUsedUser();
    255263        if ($postID = (int)array_search('failed_order', $aKeyEmailType)) {
    256             $emailSubject = get_post_meta($postID, AutoPrefix::namePrefix('emailSubject'), true);
    257             $subject = str_replace(array_keys($aVariables), array_values($aVariables), $emailSubject);
     264            return $this->replaceEmailSubjectCommon($postID, $aVariables, $subject);
    258265        }
    259266        return $subject;
     
    265272        $aKeyEmailType = $this->handleListKeyEmailTypeUsedUser();
    266273        if ($postID = (int)array_search('customer_on_hold_order', $aKeyEmailType)) {
    267             $emailSubject = get_post_meta($postID, AutoPrefix::namePrefix('emailSubject'), true);
    268             $subject = str_replace(array_keys($aVariables), array_values($aVariables), $emailSubject);
     274            return $this->replaceEmailSubjectCommon($postID, $aVariables, $subject);
    269275        }
    270276        return $subject;
     
    276282        $aKeyEmailType = $this->handleListKeyEmailTypeUsedUser();
    277283        if ($postID = (int)array_search('customer_processing_order', $aKeyEmailType)) {
    278             $emailSubject = get_post_meta($postID, AutoPrefix::namePrefix('emailSubject'), true);
    279             $subject = str_replace(array_keys($aVariables), array_values($aVariables), $emailSubject);
     284            return $this->replaceEmailSubjectCommon($postID, $aVariables, $subject);
    280285        }
    281286        return $subject;
     
    287292        $aKeyEmailType = $this->handleListKeyEmailTypeUsedUser();
    288293        if ($postID = (int)array_search('customer_completed_order', $aKeyEmailType)) {
    289             $emailSubject = get_post_meta($postID, AutoPrefix::namePrefix('emailSubject'), true);
    290             $subject = str_replace(array_keys($aVariables), array_values($aVariables), $emailSubject);
     294            return $this->replaceEmailSubjectCommon($postID, $aVariables, $subject);
    291295        }
    292296        return $subject;
     
    298302        $aKeyEmailType = $this->handleListKeyEmailTypeUsedUser();
    299303        if ($postID = (int)array_search('customer_refunded_order', $aKeyEmailType)) {
    300             $emailSubject = get_post_meta($postID, AutoPrefix::namePrefix('emailSubject'), true);
    301             $subject = str_replace(array_keys($aVariables), array_values($aVariables), $emailSubject);
     304            return $this->replaceEmailSubjectCommon($postID, $aVariables, $subject);
    302305        }
    303306        return $subject;
     
    309312        $aKeyEmailType = $this->handleListKeyEmailTypeUsedUser();
    310313        if ($postID = (int)array_search('customer_invoice', $aKeyEmailType)) {
    311             $emailSubject = get_post_meta($postID, AutoPrefix::namePrefix('emailSubject'), true);
    312             $subject = str_replace(array_keys($aVariables), array_values($aVariables), $emailSubject);
     314            return $this->replaceEmailSubjectCommon($postID, $aVariables, $subject);
    313315        }
    314316        return $subject;
     
    320322        $aKeyEmailType = $this->handleListKeyEmailTypeUsedUser();
    321323        if ($postID = (int)array_search('customer_note', $aKeyEmailType)) {
    322             $emailSubject = get_post_meta($postID, AutoPrefix::namePrefix('emailSubject'), true);
    323             $subject = str_replace(array_keys($aVariables), array_values($aVariables), $emailSubject);
     324            return $this->replaceEmailSubjectCommon($postID, $aVariables, $subject);
    324325        }
    325326
     
    332333        $aKeyEmailType = $this->handleListKeyEmailTypeUsedUser();
    333334        if ($postID = (int)array_search('customer_reset_password', $aKeyEmailType)) {
    334             $emailSubject = get_post_meta($postID, AutoPrefix::namePrefix('emailSubject'), true);
    335             $subject = str_replace(array_keys($aVariables), array_values($aVariables), $emailSubject);
     335            return $this->replaceEmailSubjectCommon($postID, $aVariables, $subject);
    336336        }
    337337        return $subject;
     
    344344
    345345        if ($postID = (int)array_search('customer_new_account', $aKeyEmailType)) {
    346             $emailSubject = get_post_meta($postID, AutoPrefix::namePrefix('emailSubject'), true);
    347             $subject = str_replace(array_keys($aVariables), array_values($aVariables), $emailSubject);
     346            return $this->replaceEmailSubjectCommon($postID, $aVariables, $subject);
    348347        }
    349348
  • email-creatior/trunk/src/Shared/GetFieldPlaceholderSubjectEmail.php

    r2774630 r2785694  
    33namespace WilokeEmailCreator\Shared;
    44
     5use WC_Order;
    56use WilokeEmailCreator\Illuminate\Prefix\AutoPrefix;
    67use WP_User;
     
    3334                    return $aArgs;
    3435                }
    35                 $aOrderData = $aArgs->get_data();
     36
     37                /**
     38                 * @var WC_Order $oWCOrder
     39                 */
     40                $oWCOrder = $aArgs;
     41                $aOrderData = $oWCOrder->get_data();
     42
     43//              if (isset($aOrderData['id']) && !empty($aOrderData['id'])) {
     44//                  $orderNumber = $aOrderData['id'];
     45//                  if (!is_wp_error($oWCOrder)) {
     46//                      $paymentMethod = $oWCOrder->get_payment_method();
     47//                  } else {
     48//                      $paymentMethod = $aOrderData['payment_method'];
     49//                  }
     50//              } else {
     51//                  $orderNumber = 0;
     52//                  $paymentMethod = $aOrderData['payment_method'];
     53//              }
     54
    3655                $aVariable = [
    37                     '{order_date}'         => $aArgs->get_date_created()->date(wc_date_format()),
     56                    '{order_date}'         => $oWCOrder->get_date_created()->date_i18n(wc_date_format()),
    3857                    '{last_name}'          => $aOrderData['billing']['last_name'],
    3958                    '{billing_name}'       => $aOrderData['billing']['first_name'] . ' ' .
    4059                        $aOrderData['billing']['last_name'],
    41                     '{billing_phone}'      => $aOrderData['billing']['phone'],
    42                     '{billing_email}'      => $aOrderData['billing']['email'],
    43                     '{customer_note}'      => $aOrderData['customer_note'] ?? '',
     60                    '{billing_phone}'      => $oWCOrder->get_billing_phone(),
     61                    '{billing_email}'      => $oWCOrder->get_billing_email(),
     62                    '{customer_note}'      => $oWCOrder->get_customer_note(),
    4463                    '{coupon_expire_date}' => date($date_format, current_time('U') + MONTH_IN_SECONDS),
    45                     '{first_name}'         => $aOrderData['billing']['first_name'],
    46                     '{order_discount}'     => wc_price((float)$aOrderData['discount_total']),
    47                     '{order_number}'       => $aOrderData['id'] ?? 0,
     64                    '{first_name}'         => $oWCOrder->get_billing_first_name(),
     65                    '{order_discount}'     => $oWCOrder->get_discount_total(),
     66                    '{order_number}'       => $oWCOrder->get_id(),
    4867                    '{order_received_url}' => add_query_arg('key', $aOrderData['order_key'],
    4968                        wc_get_endpoint_url('order-received',
    5069                            $aOrderData['id'],
    5170                            wc_get_checkout_url())),
    52                     '{order_shipping}'     => wc_price((float)$aOrderData['shipping_total']),
     71                    '{order_shipping}'     => $oWCOrder->get_shipping_total(),
    5372                    '{order_subtotal}'     => wc_price((float)$aOrderData['total'] +
    5473                        (int)$aOrderData['discount_total']),
    55                     '{order_total}'        => wc_price((float)$aOrderData['total']),
    56                     '{order_tax}'          => wc_price((float)$aOrderData['total_tax']),
    57                     '{payment_url}'        => wc_get_endpoint_url('order-pay', $aOrderData['id'],
    58                             wc_get_checkout_url()) .
    59                         '?pay_for_order=true&key=' . $aOrderData['order_key'],
    60                     '{payment_method}'     => $aOrderData['payment_method'],
    61                     '{billing_address1}'   => $aOrderData['billing']['address_1'] ?? '',
    62                     '{billing_address2}'   => $aOrderData['billing']['address_2'] ?? '',
    63                     '{shipping_address1}'  => $aOrderData['shipping']['address_1'] ?? '',
    64                     '{shipping_address2}'  => $aOrderData['shipping']['address_2'] ?? '',
    65                     '{shipping_phone}'     => $aOrderData['shipping']['phone'] ?? '',
    66                     '{shipping_email}'     => $aOrderData['shipping']['email'] ?? '',
    67                     '{shipping_name}'      => $aOrderData['shipping']['first_name'] . ' ' .
    68                         $aOrderData['shipping']['last_name'],
     74                    '{order_total}'        => $oWCOrder->get_total(),
     75                    '{order_tax}'          => $oWCOrder->get_total_tax(),
     76                    '{payment_url}'        => add_query_arg(
     77                        [
     78                            'pay_for_order' => true,
     79                            'key'           => $aOrderData['order_key']
     80                        ],
     81                        wc_get_endpoint_url(
     82                            'order-pay',
     83                            $aOrderData['id'],
     84                            wc_get_checkout_url()
     85                        )
     86                    ),
     87                    '{payment_method}'     => $oWCOrder->get_payment_method_title(),
     88                    '{billing_address1}'   => $oWCOrder->get_billing_address_1(),
     89                    '{billing_address2}'   => $oWCOrder->get_billing_address_2(),
     90                    '{shipping_address1}'  => $oWCOrder->get_shipping_address_1() ?? $oWCOrder->get_billing_address_1(),
     91                    '{shipping_company}'   => $oWCOrder->get_shipping_company(),
     92                    '{shipping_address2}'  => $oWCOrder->get_shipping_address_2() ?? $oWCOrder->get_billing_address_2(),
     93                    '{shipping_phone}'     => $oWCOrder->get_shipping_phone() ?? $oWCOrder->get_billing_phone(),
     94                    '{shipping_email}'     => $aOrderData['shipping']['email'] ?? $oWCOrder->get_billing_email(),
     95                    '{shipping_name}'      => $oWCOrder->get_formatted_shipping_full_name(),
    6996                ];
    7097            }
     98
    7199            return wp_parse_args($aVariable, [
    72100                '{admin_email}'           => get_bloginfo('admin_email'),
     
    116144                '{shipping_email}'        => 'loni.alsayed@example.com',
    117145                '{shipping_name}'         => 'Loni Alsayed',
     146                '{shipping_company}'      => ''
    118147            ]);
    119148        }
     149
    120150        return [
    121151            'order'   => [
Note: See TracChangeset for help on using the changeset viewer.