PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.5.7
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.5.7
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 2.5.7, at includes/class-convertkit-term.php

175 lines 2.8 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 * Returns the form position setting for the Term
105 * on the Term archive.
106 *
107 * @since 2.4.9.1
108 *
109 * @return string
110 */
111 public function get_form_position() {
112
113 return $this->settings['form_position'];
114
115 }
116
117 /**
118 * Whether the Term has a ConvertKit Form Position defined
119 * for the Term archive.
120 *
121 * @since 2.4.9.1
122 *
123 * @return bool
124 */
125 public function has_form_position() {
126
127 return ( $this->settings['form_position'] !== '' );
128
129 }
130
131 /**
132 * Saves Term settings to the Term.
133 *
134 * @since 1.9.6
135 *
136 * @param array $meta Settings.
137 * @return bool Term Meta was updated
138 */
139 public function save( $meta ) {
140
141 return update_term_meta( $this->term_id, self::TERM_META_KEY, $meta );
142
143 }
144
145 /**
146 * The default settings, used to populate the Term's Settings when a Term
147 * has no Settings.
148 *
149 * @since 1.9.6
150 *
151 * @return array
152 */
153 public function get_default_settings() {
154
155 $defaults = array(
156 'form' => '',
157 'form_position' => '',
158 );
159
160 /**
161 * The default settings, used to populate the Term's Settings when a Term
162 * has no Settings.
163 *
164 * @since 1.9.6
165 *
166 * @param array $defaults Default Form
167 */
168 $defaults = apply_filters( 'convertkit_term_get_default_settings', $defaults );
169
170 return $defaults;
171
172 }
173
174 }
175