PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.3.4
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.3.4
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 / functions.php

functions.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 2.3.4, at includes/functions.php

548 lines 11.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ConvertKit general plugin functions.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Runs the activation and update routines when the plugin is activated.
11 *
12 * @since 1.9.7.4
13 *
14 * @param bool $network_wide Is network wide activation.
15 */
16 function convertkit_plugin_activate( $network_wide ) {
17
18 // Initialise Plugin.
19 $convertkit = WP_ConvertKit();
20
21 // Check if we are on a multisite install, activating network wide, or a single install.
22 if ( ! is_multisite() || ! $network_wide ) {
23 // Single Site activation.
24 $convertkit->get_class( 'setup' )->activate();
25
26 // Set a transient for 30 seconds to redirect to the setup screen on activation.
27 set_transient( 'convertkit-setup', true, 30 );
28 } else {
29 // Multisite network wide activation.
30 $sites = get_sites(
31 array(
32 'number' => 0,
33 )
34 );
35 foreach ( $sites as $site ) {
36 switch_to_blog( (int) $site->blog_id );
37 $convertkit->get_class( 'setup' )->activate();
38 restore_current_blog();
39 }
40 }
41
42 }
43
44 /**
45 * Runs the activation and update routines when the plugin is activated
46 * on a WordPress multisite setup.
47 *
48 * @since 1.9.7.4
49 *
50 * @param WP_Site|int $site_or_blog_id WP_Site or Blog ID.
51 */
52 function convertkit_plugin_activate_new_site( $site_or_blog_id ) {
53
54 // Check if $site_or_blog_id is a WP_Site or a blog ID.
55 if ( is_a( $site_or_blog_id, 'WP_Site' ) ) {
56 $site_or_blog_id = $site_or_blog_id->blog_id;
57 }
58
59 // Initialise Plugin.
60 $convertkit = WP_ConvertKit();
61
62 // Run installation routine.
63 switch_to_blog( $site_or_blog_id );
64 $convertkit->get_class( 'setup' )->activate();
65 restore_current_blog();
66
67 }
68
69 /**
70 * Runs the deactivation routine when the plugin is deactivated.
71 *
72 * @since 1.9.7.4
73 *
74 * @param bool $network_wide Is network wide deactivation.
75 */
76 function convertkit_plugin_deactivate( $network_wide ) {
77
78 // Initialise Plugin.
79 $convertkit = WP_ConvertKit();
80
81 // Check if we are on a multisite install, activating network wide, or a single install.
82 if ( ! is_multisite() || ! $network_wide ) {
83 // Single Site activation.
84 $convertkit->get_class( 'setup' )->deactivate();
85 } else {
86 // Multisite network wide activation.
87 $sites = get_sites(
88 array(
89 'number' => 0,
90 )
91 );
92 foreach ( $sites as $site ) {
93 switch_to_blog( (int) $site->blog_id );
94 $convertkit->get_class( 'setup' )->deactivate();
95 restore_current_blog();
96 }
97 }
98
99 }
100
101 /**
102 * Helper method to get supported Post Types.
103 *
104 * @since 1.9.6
105 *
106 * @return array Post Types
107 */
108 function convertkit_get_supported_post_types() {
109
110 $post_types = array(
111 'page',
112 'post',
113 );
114
115 /**
116 * Defines the Post Types that support ConvertKit Forms.
117 *
118 * @since 1.9.6
119 *
120 * @param array $post_types Post Types
121 */
122 $post_types = apply_filters( 'convertkit_get_supported_post_types', $post_types );
123
124 return $post_types;
125
126 }
127
128 /**
129 * Helper method to get supported Post Types for Restricted Content (Member's Content)
130 *
131 * @since 2.1.0
132 *
133 * @return array Post Types
134 */
135 function convertkit_get_supported_restrict_content_post_types() {
136
137 $post_types = array(
138 'page',
139 'post',
140 );
141
142 /**
143 * Defines the Post Types that support Restricted Content / Members Content functionality.
144 *
145 * @since 2.0.0
146 *
147 * @param array $post_types Post Types
148 */
149 $post_types = apply_filters( 'convertkit_get_supported_restrict_content_post_types', $post_types );
150
151 return $post_types;
152
153 }
154
155 /**
156 * Helper method to get registered Shortcodes.
157 *
158 * @since 1.9.6.5
159 *
160 * @return array Shortcodes
161 */
162 function convertkit_get_shortcodes() {
163
164 $shortcodes = array();
165
166 /**
167 * Registers shortcodes for the ConvertKit Plugin.
168 *
169 * @since 1.9.6.5
170 *
171 * @param array $shortcodes Shortcodes
172 */
173 $shortcodes = apply_filters( 'convertkit_shortcodes', $shortcodes );
174
175 return $shortcodes;
176
177 }
178
179 /**
180 * Helper method to get registered Blocks.
181 *
182 * @since 1.9.6
183 *
184 * @return array Blocks
185 */
186 function convertkit_get_blocks() {
187
188 $blocks = array();
189
190 /**
191 * Registers blocks for the ConvertKit Plugin.
192 *
193 * @since 1.9.6
194 *
195 * @param array $blocks Blocks
196 */
197 $blocks = apply_filters( 'convertkit_blocks', $blocks );
198
199 return $blocks;
200
201 }
202
203 /**
204 * Helper method to get registered Block formatters for Gutenberg.
205 *
206 * @since 2.2.0
207 *
208 * @return array Block formatters
209 */
210 function convertkit_get_block_formatters() {
211
212 $block_formatters = array();
213
214 /**
215 * Registers block formatters in Gutenberg for the ConvertKit Plugin.
216 *
217 * @since 2.2.0
218 *
219 * @param array $block_formatters Block formatters.
220 */
221 $block_formatters = apply_filters( 'convertkit_get_block_formatters', $block_formatters );
222
223 return $block_formatters;
224
225 }
226
227 /**
228 * Helper method to get registered pre-publish actions.
229 *
230 * @since 2.4.0
231 *
232 * @return array Pre-publish actions
233 */
234 function convertkit_get_pre_publish_actions() {
235
236 $pre_publish_actions = array();
237
238 /**
239 * Registers pre-publish actions for the ConvertKit Plugin.
240 *
241 * @since 2.4.0
242 *
243 * @param array $pre_publish_panels Pre-publish actions.
244 */
245 $pre_publish_actions = apply_filters( 'convertkit_get_pre_publish_actions', $pre_publish_actions );
246
247 return $pre_publish_actions;
248
249 }
250
251 /**
252 * Helper method to return the Plugin Settings Link
253 *
254 * @since 1.9.6
255 *
256 * @param array $query_args Optional Query Args.
257 * @return string Settings Link
258 */
259 function convertkit_get_settings_link( $query_args = array() ) {
260
261 $query_args = array_merge(
262 $query_args,
263 array(
264 'page' => '_wp_convertkit_settings',
265 )
266 );
267
268 return add_query_arg( $query_args, admin_url( 'options-general.php' ) );
269
270 }
271
272 /**
273 * Helper method to return the Plugin Settings Link
274 *
275 * @since 2.2.4
276 *
277 * @param array $query_args Optional Query Args.
278 * @return string Settings Link
279 */
280 function convertkit_get_setup_wizard_plugin_link( $query_args = array() ) {
281
282 $query_args = array_merge(
283 $query_args,
284 array(
285 'page' => 'convertkit-setup',
286 )
287 );
288
289 return add_query_arg( $query_args, admin_url( 'options.php' ) );
290
291 }
292
293 /**
294 * Helper method to return the URL the user needs to visit to register a ConvertKit account.
295 *
296 * @since 1.9.8.4
297 *
298 * @return string ConvertKit Registration URL.
299 */
300 function convertkit_get_registration_url() {
301
302 return add_query_arg(
303 array(
304 'utm_source' => 'wordpress',
305 'utm_term' => get_locale(),
306 'utm_content' => 'convertkit',
307 ),
308 'https://app.convertkit.com/users/signup'
309 );
310
311 }
312
313 /**
314 * Helper method to return the URL the user needs to visit to sign in to their ConvertKit account.
315 *
316 * @since 1.9.6.1
317 *
318 * @return string ConvertKit Login URL.
319 */
320 function convertkit_get_sign_in_url() {
321
322 return add_query_arg(
323 array(
324 'utm_source' => 'wordpress',
325 'utm_term' => get_locale(),
326 'utm_content' => 'convertkit',
327 ),
328 'https://app.convertkit.com/'
329 );
330
331 }
332
333 /**
334 * Helper method to return the URL the user needs to visit to manage thier billing.
335 *
336 * @since 2.2.7
337 *
338 * @return string ConvertKit Billing URL.
339 */
340 function convertkit_get_billing_url() {
341
342 return add_query_arg(
343 array(
344 'utm_source' => 'wordpress',
345 'utm_term' => get_locale(),
346 'utm_content' => 'convertkit',
347 ),
348 'https://app.convertkit.com/account_settings/billing/'
349 );
350
351 }
352
353 /**
354 * Helper method to return the URL the user needs to visit on the ConvertKit app to obtain their API Key and Secret.
355 *
356 * @since 1.9.6.1
357 *
358 * @return string ConvertKit App URL.
359 */
360 function convertkit_get_api_key_url() {
361
362 return add_query_arg(
363 array(
364 'utm_source' => 'wordpress',
365 'utm_term' => get_locale(),
366 'utm_content' => 'convertkit',
367 ),
368 'https://app.convertkit.com/account_settings/advanced_settings/'
369 );
370
371 }
372
373 /**
374 * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Form or Landing Page.
375 *
376 * @since 2.2.3
377 *
378 * @return string ConvertKit App URL
379 */
380 function convertkit_get_new_form_url() {
381
382 return add_query_arg(
383 array(
384 'utm_source' => 'wordpress',
385 'utm_term' => get_locale(),
386 'utm_content' => 'convertkit',
387 ),
388 'https://app.convertkit.com/forms/new/'
389 );
390
391 }
392
393 /**
394 * Helper method to return the URL the user needs to visit to edit ConvertKit forms.
395 *
396 * @since 2.2.3
397 *
398 * @return string ConvertKit Form Editor URL.
399 */
400 function convertkit_get_form_editor_url() {
401
402 return add_query_arg(
403 array(
404 'utm_source' => 'wordpress',
405 'utm_term' => get_locale(),
406 'utm_content' => 'convertkit',
407 ),
408 'https://app.convertkit.com/forms'
409 );
410
411 }
412
413 /**
414 * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Tag.
415 *
416 * @since 2.3.3
417 *
418 * @return string ConvertKit App URL.
419 */
420 function convertkit_get_new_tag_url() {
421
422 return add_query_arg(
423 array(
424 'utm_source' => 'wordpress',
425 'utm_term' => get_locale(),
426 'utm_content' => 'convertkit',
427 ),
428 'https://app.convertkit.com/subscribers/'
429 );
430
431 }
432
433 /**
434 * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Broadcast.
435 *
436 * @since 2.2.6
437 *
438 * @return string ConvertKit App URL.
439 */
440 function convertkit_get_new_broadcast_url() {
441
442 return add_query_arg(
443 array(
444 'utm_source' => 'wordpress',
445 'utm_term' => get_locale(),
446 'utm_content' => 'convertkit',
447 ),
448 'https://app.convertkit.com/campaigns/'
449 );
450
451 }
452
453 /**
454 * Helper method to return the URL the user needs to visit on the ConvertKit app to edit a draft Broadcast.
455 *
456 * @since 2.4.0
457 *
458 * @param int $broadcast_id ConvertKit Broadcast ID.
459 * @return string ConvertKit App URL.
460 */
461 function convertkit_get_edit_broadcast_url( $broadcast_id ) {
462
463 return add_query_arg(
464 array(
465 'utm_source' => 'wordpress',
466 'utm_term' => get_locale(),
467 'utm_content' => 'convertkit',
468 ),
469 sprintf(
470 'https://app.convertkit.com/campaigns/%s/draft',
471 $broadcast_id
472 )
473 );
474
475 }
476
477 /**
478 * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Product.
479 *
480 * @since 2.2.3
481 *
482 * @return string ConvertKit App URL.
483 */
484 function convertkit_get_new_product_url() {
485
486 return add_query_arg(
487 array(
488 'utm_source' => 'wordpress',
489 'utm_term' => get_locale(),
490 'utm_content' => 'convertkit',
491 ),
492 'https://app.convertkit.com/products/new/'
493 );
494
495 }
496
497 /**
498 * Helper method to enqueue Select2 scripts for use within the ConvertKit Plugin.
499 *
500 * @since 1.9.6.4
501 */
502 function convertkit_select2_enqueue_scripts() {
503
504 wp_enqueue_script( 'convertkit-select2', 'https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, false );
505 wp_enqueue_script( 'convertkit-admin-select2', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/select2.js', array( 'convertkit-select2' ), CONVERTKIT_PLUGIN_VERSION, false );
506
507 }
508
509 /**
510 * Helper method to enqueue Select2 stylesheets for use within the ConvertKit Plugin.
511 *
512 * @since 1.9.6.4
513 */
514 function convertkit_select2_enqueue_styles() {
515
516 wp_enqueue_style( 'convertkit-select2', 'https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css', array(), CONVERTKIT_PLUGIN_VERSION );
517 wp_enqueue_style( 'convertkit-admin-select2', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/select2.css', array(), CONVERTKIT_PLUGIN_VERSION );
518
519 }
520
521 /**
522 * Return the contents of the given local file.
523 *
524 * @since 2.2.2
525 *
526 * @param string $local_file Local file, including path.
527 * @return string File contents.
528 */
529 function convertkit_get_file_contents( $local_file ) {
530
531 // Bail if the file doesn't exist.
532 if ( ! file_exists( $local_file ) ) {
533 return '';
534 }
535
536 // Read file.
537 $contents = file_get_contents( $local_file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
538
539 // Return an empty string if the contents of the file could not be read.
540 if ( ! $contents ) {
541 return '';
542 }
543
544 // Return file's contents.
545 return $contents;
546
547 }
548