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

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

569 lines 12.8 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 // Define supported Post Types.
111 $post_types = array(
112 'page',
113 'post',
114 );
115
116 // If public Custom Post Types can be fetched, include them now.
117 if ( function_exists( 'get_post_types' ) ) {
118 // Get public Custom Post Types.
119 $custom_post_types = get_post_types(
120 array(
121 'public' => true,
122
123 // Don't include WordPress' built in Post Types, such as attachment, revisino and nav_menu_item.
124 '_builtin' => false,
125 )
126 );
127
128 // Sanity check an array was returned.
129 if ( is_array( $custom_post_types ) ) {
130 $post_types = array_merge(
131 $post_types,
132 array_keys( $custom_post_types )
133 );
134 }
135 }
136
137 /**
138 * Defines the Post Types that support ConvertKit Forms.
139 *
140 * @since 1.9.6
141 *
142 * @param array $post_types Post Types
143 */
144 $post_types = apply_filters( 'convertkit_get_supported_post_types', $post_types );
145
146 return $post_types;
147
148 }
149
150 /**
151 * Helper method to get supported Post Types for Restricted Content (Member's Content)
152 *
153 * @since 2.1.0
154 *
155 * @deprecated 2.4.3 No longer used by internal code and not recommended. Use `convertkit_get_supported_post_types` instead.
156 *
157 * @return array Post Types
158 */
159 function convertkit_get_supported_restrict_content_post_types() {
160
161 return convertkit_get_supported_post_types();
162
163 }
164
165 /**
166 * Helper method to get registered Shortcodes.
167 *
168 * @since 1.9.6.5
169 *
170 * @return array Shortcodes
171 */
172 function convertkit_get_shortcodes() {
173
174 $shortcodes = array();
175
176 /**
177 * Registers shortcodes for the ConvertKit Plugin.
178 *
179 * @since 1.9.6.5
180 *
181 * @param array $shortcodes Shortcodes
182 */
183 $shortcodes = apply_filters( 'convertkit_shortcodes', $shortcodes );
184
185 return $shortcodes;
186
187 }
188
189 /**
190 * Helper method to get registered Blocks.
191 *
192 * @since 1.9.6
193 *
194 * @return array Blocks
195 */
196 function convertkit_get_blocks() {
197
198 $blocks = array();
199
200 /**
201 * Registers blocks for the ConvertKit Plugin.
202 *
203 * @since 1.9.6
204 *
205 * @param array $blocks Blocks
206 */
207 $blocks = apply_filters( 'convertkit_blocks', $blocks );
208
209 return $blocks;
210
211 }
212
213 /**
214 * Helper method to get registered Block formatters for Gutenberg.
215 *
216 * @since 2.2.0
217 *
218 * @return array Block formatters
219 */
220 function convertkit_get_block_formatters() {
221
222 $block_formatters = array();
223
224 /**
225 * Registers block formatters in Gutenberg for the ConvertKit Plugin.
226 *
227 * @since 2.2.0
228 *
229 * @param array $block_formatters Block formatters.
230 */
231 $block_formatters = apply_filters( 'convertkit_get_block_formatters', $block_formatters );
232
233 return $block_formatters;
234
235 }
236
237 /**
238 * Helper method to get registered pre-publish actions.
239 *
240 * @since 2.4.0
241 *
242 * @return array Pre-publish actions
243 */
244 function convertkit_get_pre_publish_actions() {
245
246 $pre_publish_actions = array();
247
248 /**
249 * Registers pre-publish actions for the ConvertKit Plugin.
250 *
251 * @since 2.4.0
252 *
253 * @param array $pre_publish_panels Pre-publish actions.
254 */
255 $pre_publish_actions = apply_filters( 'convertkit_get_pre_publish_actions', $pre_publish_actions );
256
257 return $pre_publish_actions;
258
259 }
260
261 /**
262 * Helper method to return the Plugin Settings Link
263 *
264 * @since 1.9.6
265 *
266 * @param array $query_args Optional Query Args.
267 * @return string Settings Link
268 */
269 function convertkit_get_settings_link( $query_args = array() ) {
270
271 $query_args = array_merge(
272 $query_args,
273 array(
274 'page' => '_wp_convertkit_settings',
275 )
276 );
277
278 return add_query_arg( $query_args, admin_url( 'options-general.php' ) );
279
280 }
281
282 /**
283 * Helper method to return the Plugin Settings Link
284 *
285 * @since 2.2.4
286 *
287 * @param array $query_args Optional Query Args.
288 * @return string Settings Link
289 */
290 function convertkit_get_setup_wizard_plugin_link( $query_args = array() ) {
291
292 $query_args = array_merge(
293 $query_args,
294 array(
295 'page' => 'convertkit-setup',
296 )
297 );
298
299 return add_query_arg( $query_args, admin_url( 'options.php' ) );
300
301 }
302
303 /**
304 * Helper method to return the URL the user needs to visit to register a ConvertKit account.
305 *
306 * @since 1.9.8.4
307 *
308 * @return string ConvertKit Registration URL.
309 */
310 function convertkit_get_registration_url() {
311
312 return add_query_arg(
313 array(
314 'utm_source' => 'wordpress',
315 'utm_term' => get_locale(),
316 'utm_content' => 'convertkit',
317 ),
318 'https://app.convertkit.com/users/signup'
319 );
320
321 }
322
323 /**
324 * Helper method to return the URL the user needs to visit to sign in to their ConvertKit account.
325 *
326 * @since 1.9.6.1
327 *
328 * @return string ConvertKit Login URL.
329 */
330 function convertkit_get_sign_in_url() {
331
332 return add_query_arg(
333 array(
334 'utm_source' => 'wordpress',
335 'utm_term' => get_locale(),
336 'utm_content' => 'convertkit',
337 ),
338 'https://app.convertkit.com/'
339 );
340
341 }
342
343 /**
344 * Helper method to return the URL the user needs to visit to manage thier billing.
345 *
346 * @since 2.2.7
347 *
348 * @return string ConvertKit Billing URL.
349 */
350 function convertkit_get_billing_url() {
351
352 return add_query_arg(
353 array(
354 'utm_source' => 'wordpress',
355 'utm_term' => get_locale(),
356 'utm_content' => 'convertkit',
357 ),
358 'https://app.convertkit.com/account_settings/billing/'
359 );
360
361 }
362
363 /**
364 * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Form or Landing Page.
365 *
366 * @since 2.2.3
367 *
368 * @return string ConvertKit App URL
369 */
370 function convertkit_get_new_form_url() {
371
372 return add_query_arg(
373 array(
374 'utm_source' => 'wordpress',
375 'utm_term' => get_locale(),
376 'utm_content' => 'convertkit',
377 ),
378 'https://app.convertkit.com/forms/new/'
379 );
380
381 }
382
383 /**
384 * Helper method to return the URL the user needs to visit to edit ConvertKit forms.
385 *
386 * @since 2.2.3
387 *
388 * @return string ConvertKit Form Editor URL.
389 */
390 function convertkit_get_form_editor_url() {
391
392 return add_query_arg(
393 array(
394 'utm_source' => 'wordpress',
395 'utm_term' => get_locale(),
396 'utm_content' => 'convertkit',
397 ),
398 'https://app.convertkit.com/forms'
399 );
400
401 }
402
403 /**
404 * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Tag.
405 *
406 * @since 2.3.3
407 *
408 * @return string ConvertKit App URL.
409 */
410 function convertkit_get_new_tag_url() {
411
412 return add_query_arg(
413 array(
414 'utm_source' => 'wordpress',
415 'utm_term' => get_locale(),
416 'utm_content' => 'convertkit',
417 ),
418 'https://app.convertkit.com/subscribers/'
419 );
420
421 }
422
423 /**
424 * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Broadcast.
425 *
426 * @since 2.2.6
427 *
428 * @return string ConvertKit App URL.
429 */
430 function convertkit_get_new_broadcast_url() {
431
432 return add_query_arg(
433 array(
434 'utm_source' => 'wordpress',
435 'utm_term' => get_locale(),
436 'utm_content' => 'convertkit',
437 ),
438 'https://app.convertkit.com/campaigns/'
439 );
440
441 }
442
443 /**
444 * Helper method to return the URL the user needs to visit on the ConvertKit app to edit a draft Broadcast.
445 *
446 * @since 2.4.0
447 *
448 * @param int $broadcast_id ConvertKit Broadcast ID.
449 * @return string ConvertKit App URL.
450 */
451 function convertkit_get_edit_broadcast_url( $broadcast_id ) {
452
453 return add_query_arg(
454 array(
455 'utm_source' => 'wordpress',
456 'utm_term' => get_locale(),
457 'utm_content' => 'convertkit',
458 ),
459 sprintf(
460 'https://app.convertkit.com/campaigns/%s/draft',
461 $broadcast_id
462 )
463 );
464
465 }
466
467 /**
468 * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Product.
469 *
470 * @since 2.2.3
471 *
472 * @return string ConvertKit App URL.
473 */
474 function convertkit_get_new_product_url() {
475
476 return add_query_arg(
477 array(
478 'utm_source' => 'wordpress',
479 'utm_term' => get_locale(),
480 'utm_content' => 'convertkit',
481 ),
482 'https://app.convertkit.com/products/new/'
483 );
484
485 }
486
487 /**
488 * Helper method to enqueue Select2 scripts for use within the ConvertKit Plugin.
489 *
490 * @since 1.9.6.4
491 */
492 function convertkit_select2_enqueue_scripts() {
493
494 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 );
495 wp_enqueue_script( 'convertkit-admin-select2', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/select2.js', array( 'convertkit-select2' ), CONVERTKIT_PLUGIN_VERSION, false );
496
497 }
498
499 /**
500 * Helper method to enqueue Select2 stylesheets for use within the ConvertKit Plugin.
501 *
502 * @since 1.9.6.4
503 */
504 function convertkit_select2_enqueue_styles() {
505
506 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 );
507 wp_enqueue_style( 'convertkit-admin-select2', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/select2.css', array(), CONVERTKIT_PLUGIN_VERSION );
508
509 }
510
511 /**
512 * Return the contents of the given local file.
513 *
514 * @since 2.2.2
515 *
516 * @param string $local_file Local file, including path.
517 * @return string File contents.
518 */
519 function convertkit_get_file_contents( $local_file ) {
520
521 // Bail if the file doesn't exist.
522 if ( ! file_exists( $local_file ) ) {
523 return '';
524 }
525
526 // Read file.
527 $contents = file_get_contents( $local_file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
528
529 // Return an empty string if the contents of the file could not be read.
530 if ( ! $contents ) {
531 return '';
532 }
533
534 // Return file's contents.
535 return $contents;
536
537 }
538
539 /**
540 * Returns a dropdown field commonly used for settings, comprising of:
541 * - Do not subscribe
542 * - Subscribe
543 * - Subscribe to Form
544 *
545 * @since 2.5.2
546 *
547 * @param string $name Field name.
548 * @param string $value Field value.
549 * @param string $id Field ID attribute.
550 * @param string $css_class Field CSS class(es).
551 * @param string $context Resource context.
552 * @param bool|array $additional_options Additional <option> key/value pairs.
553 */
554 function convertkit_get_subscription_dropdown_field( $name, $value, $id, $css_class = '', $context = '', $additional_options = false ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter
555
556 // Load resource classes.
557 $forms = new ConvertKit_Resource_Forms( $context );
558 $tags = new ConvertKit_Resource_Tags( $context );
559 $sequences = new ConvertKit_Resource_Sequences( $context );
560
561 ob_start();
562 include CONVERTKIT_PLUGIN_PATH . '/views/backend/subscription-dropdown-field.php';
563 $output = trim( ob_get_clean() );
564
565 // Return output.
566 return $output;
567
568 }
569