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

169 lines 2.6 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 = 'ck_default_form';
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|string
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, 'ck_default_form', 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 string
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;
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 > 0 );
100
101 }
102
103 /**
104 * Whether the Term is set to use the Plugin's Default Form Setting.
105 *
106 * @since 1.9.6
107 *
108 * @return bool
109 */
110 public function uses_default_form() {
111
112 return ( $this->settings === '-1' );
113
114 }
115
116 /**
117 * Whether the Term is set to use NO Form.
118 *
119 * @since 1.9.6
120 *
121 * @return bool
122 */
123 public function uses_no_form() {
124
125 return ( $this->settings === '0' );
126
127 }
128
129 /**
130 * Saves Term settings to the Term.
131 *
132 * @since 1.9.6
133 *
134 * @param string $meta Settings.
135 */
136 public function save( $meta ) {
137
138 return update_term_meta( $this->term_id, self::TERM_META_KEY, $meta );
139
140 }
141
142 /**
143 * The default settings, used to populate the Term's Settings when a Term
144 * has no Settings.
145 *
146 * @since 1.9.6
147 *
148 * @return string
149 */
150 public function get_default_settings() {
151
152 $defaults = '';
153
154 /**
155 * The default settings, used to populate the Term's Settings when a Term
156 * has no Settings.
157 *
158 * @since 1.9.6
159 *
160 * @param string $defaults Default Form
161 */
162 $defaults = apply_filters( 'convertkit_term_get_default_settings', $defaults );
163
164 return $defaults;
165
166 }
167
168 }
169