PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.3.2
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.3.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 / plugin-sidebars / class-convertkit-plugin-sidebar-post-settings.php

class-convertkit-plugin-sidebar-post-settings.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.3.2, at includes/plugin-sidebars/class-convertkit-plugin-sidebar-post-settings.php

252 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit Plugin Sidebar Post Settings class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * ConvertKit Plugin Sidebar Post Settings definition for Gutenberg.
11 *
12 * @package ConvertKit
13 * @author ConvertKit
14 */
15 class ConvertKit_Plugin_Sidebar_Post_Settings extends ConvertKit_Plugin_Sidebar {
16
17 /**
18 * Constructor
19 *
20 * @since 3.3.0
21 */
22 public function __construct() {
23
24 // Register this as a plugin sidebar in the ConvertKit Plugin.
25 add_filter( 'convertkit_plugin_sidebars', array( $this, 'register' ) );
26
27 }
28
29 /**
30 * Returns this plugin sidebar's programmatic name, excluding the convertkit- prefix.
31 *
32 * @since 3.3.0
33 *
34 * @return string
35 */
36 public function get_name() {
37
38 return 'post-settings';
39
40 }
41
42 /**
43 * Returns this plugin sidebar's meta key.
44 *
45 * @since 3.3.0
46 *
47 * @return string
48 */
49 public function get_meta_key() {
50
51 return '_wp_convertkit_post_meta';
52
53 }
54
55 /**
56 * Returns this plugin sidebar's title.
57 *
58 * @since 3.3.0
59 */
60 public function get_title() {
61
62 return __( 'Kit', 'convertkit' );
63
64 }
65
66 /**
67 * Returns this plugin sidebar's icon.
68 *
69 * @since 3.3.0
70 */
71 public function get_icon() {
72
73 return 'resources/backend/images/kit-logo.svg';
74
75 }
76
77 /**
78 * Returns this plugin sidebar's attributes
79 *
80 * @since 3.3.0
81 *
82 * @return array
83 */
84 public function get_attributes() {
85
86 return array(
87 'form' => array(
88 'type' => 'string',
89 'default' => $this->get_default_value( 'form' ),
90 ),
91 'landing_page' => array(
92 'type' => 'string',
93 'default' => $this->get_default_value( 'landing_page' ),
94 ),
95 'tag' => array(
96 'type' => 'string',
97 'default' => $this->get_default_value( 'tag' ),
98 ),
99 'restrict_content' => array(
100 'type' => 'string',
101 'default' => $this->get_default_value( 'restrict_content' ),
102 ),
103 );
104
105 }
106
107 /**
108 * Returns this plugin sidebar's Fields
109 *
110 * @since 3.3.0
111 *
112 * @return bool|array
113 */
114 public function get_fields() {
115
116 // Load resource classes.
117 $convertkit_forms = new ConvertKit_Resource_Forms( 'post_settings' );
118 $convertkit_landing_pages = new ConvertKit_Resource_Landing_Pages( 'post_settings' );
119 $convertkit_tags = new ConvertKit_Resource_Tags( 'post_settings' );
120 $convertkit_products = new ConvertKit_Resource_Products( 'post_settings' );
121
122 // Get Forms.
123 $forms = array(
124 '-1' => esc_html__( 'Default', 'convertkit' ),
125 '0' => esc_html__( 'None', 'convertkit' ),
126 );
127 if ( $convertkit_forms->exist() ) {
128 foreach ( $convertkit_forms->get() as $form ) {
129 // Legacy forms don't include a `format` key, so define them as inline.
130 $forms[ absint( $form['id'] ) ] = sprintf(
131 '%s [%s]',
132 sanitize_text_field( $form['name'] ),
133 ( ! empty( $form['format'] ) ? sanitize_text_field( $form['format'] ) : 'inline' )
134 );
135 }
136 }
137
138 // Get Landing Pages.
139 $landing_pages = array(
140 '0' => esc_html__( 'None', 'convertkit' ),
141 );
142 if ( $convertkit_landing_pages->exist() ) {
143 foreach ( $convertkit_landing_pages->get() as $landing_page ) {
144 $landing_pages[ absint( $landing_page['id'] ) ] = sanitize_text_field( $landing_page['name'] );
145 }
146 }
147
148 // Get Tags.
149 $tags = array(
150 '0' => esc_html__( 'None', 'convertkit' ),
151 );
152 if ( $convertkit_tags->exist() ) {
153 foreach ( $convertkit_tags->get() as $tag ) {
154 $tags[ absint( $tag['id'] ) ] = sanitize_text_field( $tag['name'] );
155 }
156 }
157
158 // Get Products.
159 $restrict_content = array(
160 '0' => esc_html__( 'Do not restrict content to member-only', 'convertkit' ),
161 );
162 if ( $convertkit_forms->exist() ) {
163 $restrict_content['forms'] = array(
164 'label' => esc_html__( 'Forms', 'convertkit' ),
165 'values' => array(),
166 );
167 foreach ( $convertkit_forms->get() as $form ) {
168 // Legacy forms don't include a `format` key, so define them as inline.
169 $restrict_content['forms']['values'][ 'form_' . absint( $form['id'] ) ] = sprintf(
170 '%s [%s]',
171 sanitize_text_field( $form['name'] ),
172 ( ! empty( $form['format'] ) ? sanitize_text_field( $form['format'] ) : 'inline' )
173 );
174 }
175 }
176 if ( $convertkit_tags->exist() ) {
177 $restrict_content['tags'] = array(
178 'label' => esc_html__( 'Tags', 'convertkit' ),
179 'values' => array(),
180 );
181 foreach ( $convertkit_tags->get() as $tag ) {
182 $restrict_content['tags']['values'][ 'tag_' . absint( $tag['id'] ) ] = sanitize_text_field( $tag['name'] );
183 }
184 }
185 if ( $convertkit_products->exist() ) {
186 $restrict_content['products'] = array(
187 'label' => esc_html__( 'Products', 'convertkit' ),
188 'values' => array(),
189 );
190 foreach ( $convertkit_products->get() as $product ) {
191 $restrict_content['products']['values'][ 'product_' . $product['id'] ] = sanitize_text_field( $product['name'] );
192 }
193 }
194
195 return array(
196 'form' => array(
197 'label' => __( 'Form', 'convertkit' ),
198 'type' => 'select',
199 'description' => array(
200 __( 'Default', 'convertkit' ) . ': ' . __( 'Uses the form specified on the settings page.', 'convertkit' ),
201 __( 'None', 'convertkit' ) . ': ' . __( 'do not display a form.', 'convertkit' ),
202 __( 'Any other option will display that form after the main content.', 'convertkit' ),
203 ),
204 'values' => $forms,
205 'resource_type' => 'forms',
206 ),
207 'landing_page' => array(
208 'label' => __( 'Landing Page', 'convertkit' ),
209 'type' => 'select',
210 'description' => __( 'Select a landing page to make it appear in place of this page.', 'convertkit' ),
211 'values' => $landing_pages,
212 'post_type' => 'page',
213 'resource_type' => 'landing_pages',
214 ),
215 'tag' => array(
216 'label' => __( 'Tag', 'convertkit' ),
217 'type' => 'select',
218 'description' => __( 'Select a tag to apply to visitors of this page who are subscribed. A visitor is deemed to be subscribed if they have clicked a link in an email to this site which includes their subscriber ID, or have entered their email address in a Kit Form on this site.', 'convertkit' ),
219 'values' => $tags,
220 'resource_type' => 'tags',
221 ),
222 'restrict_content' => array(
223 'label' => __( 'Restrict Content', 'convertkit' ),
224 'type' => 'select',
225 'description' => __( 'Select the Kit form, tag or product that the visitor must be subscribed to, permitting them access to view this member-only content.', 'convertkit' ),
226 'values' => $restrict_content,
227 'resource_type' => 'restrict_content',
228 ),
229 );
230
231 }
232
233 /**
234 * Returns this block's Default Values
235 *
236 * @since 3.3.0
237 *
238 * @return array
239 */
240 public function get_default_values() {
241
242 return array(
243 'form' => '-1',
244 'landing_page' => '0',
245 'tag' => '0',
246 'restrict_content' => '0',
247 );
248
249 }
250
251 }
252