PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.3.0
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.3.0
3.4.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 All 195 releases
← All changes | includes/class-convertkit-term.php +72 -22 2.2.83.3.0 View file →
@@ -17,9 +17,9 @@
17 17 * Holds the Term Meta Key that stores ConvertKit settings on a per-Taxonomy Term basis
18 18 *
19 19 * @var string
20 20 */
21 - const TERM_META_KEY = 'ck_default_form';
21 + const TERM_META_KEY = '_wp_convertkit_term_meta';
22 22
23 23 /**
24 24 * Holds the Term ID
25 25 *
@@ -31,9 +31,9 @@
31 31
32 32 /**
33 33 * Holds the Term's Settings
34 34 *
35 - * @var bool|string
35 + * @var bool|array
36 36 */
37 37 private $settings = false;
38 38
39 39 /**
@@ -65,9 +65,9 @@
65 65 * Returns settings for the Term.
66 66 *
67 67 * @since 1.9.6
68 68 *
69 - * @return string
69 + * @return array
70 70 */
71 71 public function get() {
72 72
73 73 return $this->settings;
@@ -82,9 +82,9 @@
82 82 * @return string
83 83 */
84 84 public function get_form() {
85 85
86 - return $this->settings;
86 + return $this->settings['form'];
87 87
88 88 }
89 89
90 90 /**
@@ -95,36 +95,83 @@
95 95 * @return bool
96 96 */
97 97 public function has_form() {
98 98
99 - // Backward compat. for Terms created/edited prior to 1.9.6, where
100 - // 'default' was used instead of zero to denote the Post / Post Type
101 - // setting should be used for determining the Form to display.
102 - // Using a comparison operator on 'default' will return different results in:
103 - // PHP < 8.0: 'default' > 0 is false
104 - // PHP 8.0+: 'default' > 0 is true
105 - // See https://www.php.net/manual/en/language.operators.comparison.php.
106 - if ( $this->settings === 'default' ) {
107 - return false;
108 - }
99 + return ( $this->settings['form'] > 0 );
109 100
110 - // If the setting is greater than zero, it's a specific Form ID that
111 - // should be used for Posts assigned to this Category.
112 - return ( $this->settings > 0 );
101 + }
113 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 114 }
115 115
116 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 + /**
117 158 * Saves Term settings to the Term.
118 159 *
119 160 * @since 1.9.6
120 161 *
121 - * @param string $meta Settings.
162 + * @param array $meta Settings.
163 + * @return bool Term Meta was updated
122 164 */
123 165 public function save( $meta ) {
124 166
125 - return update_term_meta( $this->term_id, self::TERM_META_KEY, $meta );
167 + $result = update_term_meta( $this->term_id, self::TERM_META_KEY, array_merge( $this->get(), $meta ) );
126 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 +
127 174 }
128 175
129 176 /**
130 177 * The default settings, used to populate the Term's Settings when a Term
@@ -131,13 +178,16 @@
131 178 * has no Settings.
132 179 *
133 180 * @since 1.9.6
134 181 *
135 - * @return string
182 + * @return array
136 183 */
137 184 public function get_default_settings() {
138 185
139 - $defaults = '';
186 + $defaults = array(
187 + 'form' => '',
188 + 'form_position' => '',
189 + );
140 190
141 191 /**
142 192 * The default settings, used to populate the Term's Settings when a Term
143 193 * has no Settings.
@@ -143,9 +193,9 @@
143 193 * has no Settings.
144 194 *
145 195 * @since 1.9.6
146 196 *
147 - * @param string $defaults Default Form
197 + * @param array $defaults Default Form
148 198 */
149 199 $defaults = apply_filters( 'convertkit_term_get_default_settings', $defaults );
150 200
151 201 return $defaults;