| 1 |
<?php |
| 2 |
/** |
| 3 |
* Email preview endpoint. |
| 4 |
* |
| 5 |
* @package Charitable/Classes/Charitable_Email_Preview_Endpoint |
| 6 |
* @author David Bisset |
| 7 |
* @copyright Copyright (c) 2022, WP Charitable LLC |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 1.5.0 |
| 10 |
* @version 1.6.55 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
if ( ! class_exists( 'Charitable_Email_Preview_Endpoint' ) ) : |
| 18 |
|
| 19 |
/** |
| 20 |
* Charitable_Email_Preview_Endpoint |
| 21 |
* |
| 22 |
* @since 1.5.0 |
| 23 |
*/ |
| 24 |
class Charitable_Email_Preview_Endpoint extends Charitable_Endpoint { |
| 25 |
|
| 26 |
/** Endpoint ID. */ |
| 27 |
const ID = 'email_preview'; |
| 28 |
|
| 29 |
/** |
| 30 |
* Return the endpoint ID. |
| 31 |
* |
| 32 |
* @since 1.5.0 |
| 33 |
* |
| 34 |
* @return string |
| 35 |
*/ |
| 36 |
public static function get_endpoint_id() { |
| 37 |
return self::ID; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Return the endpoint URL. |
| 42 |
* |
| 43 |
* @since 1.5.0 |
| 44 |
* |
| 45 |
* @param array $args Mixed arguments. |
| 46 |
* @return string |
| 47 |
*/ |
| 48 |
public function get_page_url( $args = array() ) { |
| 49 |
if ( ! array_key_exists( 'email_id', $args ) ) { |
| 50 |
charitable_get_deprecated()->doing_it_wrong( |
| 51 |
__METHOD__, |
| 52 |
__( 'Missing email_id in args for email preview endpoint URL.', 'charitable' ), |
| 53 |
'1.5.0' |
| 54 |
); |
| 55 |
|
| 56 |
return ''; |
| 57 |
} |
| 58 |
|
| 59 |
return esc_url_raw( |
| 60 |
add_query_arg( |
| 61 |
array( |
| 62 |
'charitable_action' => 'preview_email', |
| 63 |
'email_id' => $args['email_id'], |
| 64 |
), |
| 65 |
home_url() |
| 66 |
) |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Return whether we are currently viewing the endpoint. |
| 72 |
* |
| 73 |
* @since 1.5.0 |
| 74 |
* |
| 75 |
* @param array $args Mixed arguments. |
| 76 |
* @return boolean |
| 77 |
*/ |
| 78 |
public function is_page( $args = array() ) { |
| 79 |
return array_key_exists( 'charitable_action', $_GET ) && 'preview_email' == $_GET['charitable_action']; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Return the template to display for this endpoint. |
| 84 |
* |
| 85 |
* @since 1.5.0 |
| 86 |
* @since 1.6.55 Now returns an array. |
| 87 |
* |
| 88 |
* @param string $template The default template. |
| 89 |
* @return array |
| 90 |
*/ |
| 91 |
public function get_template( $template ) { |
| 92 |
do_action( 'charitable_email_preview' ); |
| 93 |
|
| 94 |
return array( 'emails/preview.php' ); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
endif; |
| 99 |
|