PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.0
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.0
1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 1.8.0 All 210 releases
charitable / includes / shortcodes / class-charitable-email-shortcode.php

class-charitable-email-shortcode.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.0, at includes/shortcodes/class-charitable-email-shortcode.php

143 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Email shortcode class.
4 *
5 * @package Charitable/Shortcodes/Email
6 * @author David Bisset
7 * @copyright Copyright (c) 2023, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.5.0
10 * @version 1.5.0
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 if ( ! class_exists( 'Charitable_Email_Shortcode' ) ) :
19
20 /**
21 * Charitable_Email_Shortcode class.
22 *
23 * @since 1.5.0
24 */
25 class Charitable_Email_Shortcode {
26
27 /**
28 * Static object instance.
29 *
30 * @since 1.5.0
31 *
32 * @var Charitable_Email_Shortcode
33 */
34 private static $instance;
35
36 /**
37 * The `Charitable_Email_Fields` instance.
38 *
39 * @since 1.5.0
40 *
41 * @var Charitable_Email_Fields
42 */
43 private $fields;
44
45 /**
46 * Set up class instance.
47 *
48 * @since 1.5.0
49 *
50 * @param Charitable_Email_Fields $fields The Charitable_Email_Fields instance.
51 */
52 private function __construct( Charitable_Email_Fields $fields ) {
53 $this->fields = $fields;
54 }
55
56 /**
57 * Set up the class instance.
58 *
59 * @since 1.5.0
60 *
61 * @param Charitable_Email $email The email object.
62 * @return void
63 */
64 public static function init( Charitable_Email $email ) {
65 $fields = new Charitable_Email_Fields( $email, false );
66 self::$instance = new self( $fields );
67 }
68
69 /**
70 * Set up the class instance, with preview set to true.
71 *
72 * @since 1.5.0
73 *
74 * @param Charitable_Email $email The email object.
75 * @return void
76 */
77 public static function init_preview( Charitable_Email $email ) {
78 $fields = new Charitable_Email_Fields( $email, true );
79 self::$instance = new self( $fields );
80 }
81
82 /**
83 * Flush the class instance.
84 *
85 * @since 1.5.0
86 *
87 * @return void
88 */
89 public static function flush() {
90 self::$instance = null;
91 }
92
93 /**
94 * The callback method for the campaigns shortcode.
95 *
96 * This receives the user-defined attributes and passes the logic off to the class.
97 *
98 * @since 1.5.0
99 *
100 * @param array $atts User-defined shortcode attributes.
101 * @return string
102 */
103 public static function display( $atts ) {
104 if ( ! isset( self::$instance ) ) {
105 charitable_get_deprecated()->doing_it_wrong(
106 __METHOD__,
107 __( '[charitable_email] cannot be called until a class instance has been created.', 'charitable' ),
108 '1.5.0'
109 );
110 return;
111 }
112
113 $defaults = array(
114 'show' => '',
115 'preview' => self::$instance->fields->is_preview(),
116 );
117
118 $args = apply_filters( 'charitable_email_shortcode_args', wp_parse_args( $atts, $defaults ), $atts, $defaults );
119
120 if ( ! isset( $args['show'] ) ) {
121 return '';
122 }
123
124 return self::$instance->get( $args['show'], $args );
125 }
126
127 /**
128 * Return the value for a particular variable.
129 *
130 * @since 1.5.0
131 *
132 * @param string $field The field.
133 * @param array $args Mixed arguments.
134 * @return string
135 */
136 public function get( $field, $args ) {
137 $value = apply_filters( 'charitable_email_shortcode_get_value', $this->fields->get_field_value( $field, $args ) );
138 return $value;
139 }
140 }
141
142 endif;
143