| 1 |
<?php |
| 2 |
|
| 3 |
namespace YayMail\Helper; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
class Helper { |
| 7 |
|
| 8 |
|
| 9 |
public static function checkNonce() { |
| 10 |
$nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : ''; |
| 11 |
if ( ! wp_verify_nonce( $nonce, 'email-nonce' ) ) { |
| 12 |
wp_send_json_error( array( 'mess' => 'Nonce is invalid' ) ); |
| 13 |
} |
| 14 |
} |
| 15 |
|
| 16 |
public static function sanitize_array( $var ) { |
| 17 |
if ( is_array( $var ) ) { |
| 18 |
return array_map( 'self::sanitize_array', $var ); |
| 19 |
} else { |
| 20 |
return is_scalar( $var ) ? wp_kses_allowed_html( $var ) : $var; |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
public static function unsanitize_array( $var ) { |
| 25 |
if ( is_array( $var ) ) { |
| 26 |
return array_map( 'self::unsanitize_array', $var ); |
| 27 |
} else { |
| 28 |
return html_entity_decode( $var, ENT_QUOTES, 'UTF-8' ); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
// Fix bugs for only Customer Invoice (core code of Woocommerce) |
| 33 |
public static function getCustomerInvoiceSubject( $objEmail ) { |
| 34 |
if ( $objEmail->object && $objEmail->object->has_status( array( 'completed', 'processing' ) ) ) { |
| 35 |
$subject = $objEmail->get_option( 'subject_paid', $objEmail->get_default_subject( true ) ); |
| 36 |
return apply_filters( 'woocommerce_email_subject_customer_invoice_paid', $objEmail->format_string( $subject ), $objEmail->object, $objEmail ); |
| 37 |
} |
| 38 |
|
| 39 |
$subject = $objEmail->get_option( 'subject', $objEmail->get_default_subject() ); |
| 40 |
return apply_filters( 'woocommerce_email_subject_customer_invoice', $objEmail->format_string( $subject ), $objEmail->object, $objEmail ); |
| 41 |
} |
| 42 |
|
| 43 |
// Check Key Exist |
| 44 |
public static function checkKeyExist( $array, $key, $valueDefault ) { |
| 45 |
if ( isset( $array->$key ) ) { |
| 46 |
return $key; |
| 47 |
} else { |
| 48 |
return $valueDefault; |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|