PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
1.8.13 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 All 211 releases
charitable / includes / emails / fields / class-charitable-email-fields-user.php

class-charitable-email-fields-user.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.13, at includes/emails/fields/class-charitable-email-fields-user.php

153 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 Fields Donation class.
4 *
5 * @package Charitable/Classes/Charitable_Email_Fields_User
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.8.0
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 if ( ! class_exists( 'Charitable_Email_Fields_User' ) ) :
19
20 /**
21 * Charitable_Email_Fields class.
22 *
23 * @since 1.5.0
24 */
25 class Charitable_Email_Fields_User implements Charitable_Email_Fields_Interface {
26
27 /**
28 * The WP_User object.
29 *
30 * @since 1.5.0
31 *
32 * @var WP_User
33 */
34 private $user;
35
36 /**
37 * Email.
38 *
39 * @since 1.8.0
40 *
41 * @var string
42 */
43 public $email;
44
45 /**
46 * Preview.
47 *
48 * @since 1.8.0
49 *
50 * @var string
51 */
52 public $preview;
53
54 /**
55 * Fields.
56 *
57 * @since 1.8.0
58 *
59 * @var mixed
60 */
61 public $fields;
62
63 /**
64 * Set up class instance.
65 *
66 * @since 1.5.0
67 *
68 * @param Charitable_Email $email The email object.
69 * @param boolean $preview Whether this is an email preview.
70 */
71 public function __construct( Charitable_Email $email, $preview ) {
72 $this->email = $email;
73 $this->preview = $preview;
74 $this->user = $email->get( 'user' );
75 $this->fields = $this->init_fields();
76 }
77
78 /**
79 * Get the fields that apply to the current email.
80 *
81 * @since 1.5.0
82 *
83 * @return array
84 */
85 public function init_fields() {
86 $fields = array(
87 'user_login' => array(
88 'description' => __( 'The user login', 'charitable' ),
89 'preview' => 'adam123',
90 ),
91 'first_name' => array(
92 'description' => __( 'The user\'s first name', 'charitable' ),
93 'preview' => 'Adam',
94 ),
95 'last_name' => array(
96 'description' => __( 'The user\'s last name', 'charitable' ),
97 'preview' => 'Jones',
98 ),
99 'display_name' => array(
100 'description' => __( 'The user\'s display name', 'charitable' ),
101 'preview' => 'Adam Jones',
102 ),
103 );
104
105 if ( $this->has_valid_user() ) {
106 $fields = array_merge_recursive(
107 $fields,
108 array(
109 'user_login' => array( 'value' => $this->user->user_login ),
110 'first_name' => array( 'value' => $this->user->first_name ),
111 'last_name' => array( 'value' => $this->user->last_name ),
112 'display_name' => array( 'value' => $this->user->display_name ),
113 )
114 );
115 }
116
117 /**
118 * Filter the user email fields.
119 *
120 * @since 1.5.0
121 *
122 * @param array $fields The default set of fields.
123 * @param Charitable_User $user Instance of `WP_User`.
124 * @param Charitable_Email $email Instance of `Charitable_Email`.
125 */
126 return apply_filters( 'charitable_email_user_fields', $fields, $this->user, $this->email );
127 }
128
129 /**
130 * Return fields.
131 *
132 * @since 1.5.0
133 *
134 * @return array
135 */
136 public function get_fields() {
137 return $this->fields;
138 }
139
140 /**
141 * Checks whether the email has a valid `WP_User` object set.
142 *
143 * @since 1.5.0
144 *
145 * @return boolean
146 */
147 public function has_valid_user() {
148 return is_a( $this->user, 'WP_User' );
149 }
150 }
151
152 endif;
153