PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / trunk
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages vtrunk
3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 All 194 releases
convertkit / includes / class-convertkit-term.php

class-convertkit-term.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages trunk, at includes/class-convertkit-term.php

206 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit Term class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Class to read ConvertKit Settings for the given Taxonomy Term.
11 *
12 * @since 1.9.6
13 */
14 class ConvertKit_Term {
15
16 /**
17 * Holds the Term Meta Key that stores ConvertKit settings on a per-Taxonomy Term basis
18 *
19 * @var string
20 */
21 const TERM_META_KEY = '_wp_convertkit_term_meta';
22
23 /**
24 * Holds the Term ID
25 *
26 * @since 1.9.6
27 *
28 * @var int
29 */
30 public $term_id = 0;
31
32 /**
33 * Holds the Term's Settings
34 *
35 * @var bool|array
36 */
37 private $settings = false;
38
39 /**
40 * Constructor. Populates the settings based on the given Term ID.
41 *
42 * @since 1.9.6
43 *
44 * @param int $term_id Term ID.
45 */
46 public function __construct( $term_id ) {
47
48 // Assign Term's ID to the object.
49 $this->term_id = $term_id;
50
51 // Get Term Meta.
52 $meta = get_term_meta( $term_id, self::TERM_META_KEY, true );
53
54 if ( ! $meta ) {
55 // Fallback to default settings.
56 $meta = $this->get_default_settings();
57 }
58
59 // Assign Term's Settings to the object.
60 $this->settings = $meta;
61
62 }
63
64 /**
65 * Returns settings for the Term.
66 *
67 * @since 1.9.6
68 *
69 * @return array
70 */
71 public function get() {
72
73 return $this->settings;
74
75 }
76
77 /**
78 * Returns the form setting for the Term.
79 *
80 * @since 1.9.6
81 *
82 * @return string
83 */
84 public function get_form() {
85
86 return $this->settings['form'];
87
88 }
89
90 /**
91 * Whether the Term has a ConvertKit Form defined.
92 *
93 * @since 1.9.6
94 *
95 * @return bool
96 */
97 public function has_form() {
98
99 return ( $this->settings['form'] > 0 );
100
101 }
102
103 /**
104 * Whether the Term is set to use the Plugin's Default Form Setting.
105 *
106 * @since 2.6.6
107 *
108 * @return bool
109 */
110 public function uses_default_form() {
111
112 return ( $this->settings['form'] === -1 );
113
114 }
115
116 /**
117 * Whether the Post's Form setting is set to 'None'
118 *
119 * @since 2.6.6
120 *
121 * @return bool
122 */
123 public function uses_no_form() {
124
125 return ( $this->settings['form'] === 0 );
126
127 }
128
129 /**
130 * Returns the form position setting for the Term
131 * on the Term archive.
132 *
133 * @since 2.4.9.1
134 *
135 * @return string
136 */
137 public function get_form_position() {
138
139 return $this->settings['form_position'];
140
141 }
142
143 /**
144 * Whether the Term has a ConvertKit Form Position defined
145 * for the Term archive.
146 *
147 * @since 2.4.9.1
148 *
149 * @return bool
150 */
151 public function has_form_position() {
152
153 return ( $this->settings['form_position'] !== '' );
154
155 }
156
157 /**
158 * Saves Term settings to the Term.
159 *
160 * @since 1.9.6
161 *
162 * @param array $meta Settings.
163 * @return bool Term Meta was updated
164 */
165 public function save( $meta ) {
166
167 $result = update_term_meta( $this->term_id, self::TERM_META_KEY, array_merge( $this->get(), $meta ) );
168
169 // Reload meta in class, to reflect changes.
170 $this->settings = get_term_meta( $this->term_id, self::TERM_META_KEY, true );
171
172 return $result;
173
174 }
175
176 /**
177 * The default settings, used to populate the Term's Settings when a Term
178 * has no Settings.
179 *
180 * @since 1.9.6
181 *
182 * @return array
183 */
184 public function get_default_settings() {
185
186 $defaults = array(
187 'form' => '',
188 'form_position' => '',
189 );
190
191 /**
192 * The default settings, used to populate the Term's Settings when a Term
193 * has no Settings.
194 *
195 * @since 1.9.6
196 *
197 * @param array $defaults Default Form
198 */
199 $defaults = apply_filters( 'convertkit_term_get_default_settings', $defaults );
200
201 return $defaults;
202
203 }
204
205 }
206