PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.12
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.12
1.8.13.1 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 All 212 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.7.0.12, at includes/emails/fields/class-charitable-email-fields-user.php

123 lines 2.9 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) 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.5.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 * Set up class instance.
38 *
39 * @since 1.5.0
40 *
41 * @param Charitable_Email $email The email object.
42 * @param boolean $preview Whether this is an email preview.
43 */
44 public function __construct( Charitable_Email $email, $preview ) {
45 $this->email = $email;
46 $this->preview = $preview;
47 $this->user = $email->get( 'user' );
48 $this->fields = $this->init_fields();
49 }
50
51 /**
52 * Get the fields that apply to the current email.
53 *
54 * @since 1.5.0
55 *
56 * @return array
57 */
58 public function init_fields() {
59 $fields = array(
60 'user_login' => array(
61 'description' => __( 'The user login', 'charitable' ),
62 'preview' => 'adam123',
63 ),
64 'first_name' => array(
65 'description' => __( 'The user\'s first name', 'charitable' ),
66 'preview' => 'Adam',
67 ),
68 'last_name' => array(
69 'description' => __( 'The user\'s last name', 'charitable' ),
70 'preview' => 'Jones',
71 ),
72 'display_name' => array(
73 'description' => __( 'The user\'s display name', 'charitable' ),
74 'preview' => 'Adam Jones',
75 ),
76 );
77
78 if ( $this->has_valid_user() ) {
79 $fields = array_merge_recursive( $fields, array(
80 'user_login' => array( 'value' => $this->user->user_login ),
81 'first_name' => array( 'value' => $this->user->first_name ),
82 'last_name' => array( 'value' => $this->user->last_name ),
83 'display_name' => array( 'value' => $this->user->display_name ),
84 ) );
85 }
86
87 /**
88 * Filter the user email fields.
89 *
90 * @since 1.5.0
91 *
92 * @param array $fields The default set of fields.
93 * @param Charitable_User $user Instance of `WP_User`.
94 * @param Charitable_Email $email Instance of `Charitable_Email`.
95 */
96 return apply_filters( 'charitable_email_user_fields', $fields, $this->user, $this->email );
97 }
98
99 /**
100 * Return fields.
101 *
102 * @since 1.5.0
103 *
104 * @return array
105 */
106 public function get_fields() {
107 return $this->fields;
108 }
109
110 /**
111 * Checks whether the email has a valid `WP_User` object set.
112 *
113 * @since 1.5.0
114 *
115 * @return boolean
116 */
117 public function has_valid_user() {
118 return is_a( $this->user, 'WP_User' );
119 }
120 }
121
122 endif;
123