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

156 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 * 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, 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 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 // 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 }
109
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 );
113
114 }
115
116 /**
117 * Saves Term settings to the Term.
118 *
119 * @since 1.9.6
120 *
121 * @param string $meta Settings.
122 */
123 public function save( $meta ) {
124
125 return update_term_meta( $this->term_id, self::TERM_META_KEY, $meta );
126
127 }
128
129 /**
130 * The default settings, used to populate the Term's Settings when a Term
131 * has no Settings.
132 *
133 * @since 1.9.6
134 *
135 * @return string
136 */
137 public function get_default_settings() {
138
139 $defaults = '';
140
141 /**
142 * The default settings, used to populate the Term's Settings when a Term
143 * has no Settings.
144 *
145 * @since 1.9.6
146 *
147 * @param string $defaults Default Form
148 */
149 $defaults = apply_filters( 'convertkit_term_get_default_settings', $defaults );
150
151 return $defaults;
152
153 }
154
155 }
156