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

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

359 lines 7.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 $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 );
140
141 /**
142 * Defines the Post Types that support Restricted Content / Members Content functionality.
143 *
144 * @since 2.0.0
145 *
146 * @param array $post_types Post Types
147 */
148 $post_types = apply_filters( 'convertkit_get_supported_restrict_content_post_types', $post_types );
149
150 return $post_types;
151
152 }
153
154 /**
155 * Helper method to get registered Shortcodes.
156 *
157 * @since 1.9.6.5
158 *
159 * @return array Shortcodes
160 */
161 function convertkit_get_shortcodes() {
162
163 $shortcodes = array();
164
165 /**
166 * Registers shortcodes for the ConvertKit Plugin.
167 *
168 * @since 1.9.6.5
169 *
170 * @param array $shortcodes Shortcodes
171 */
172 $shortcodes = apply_filters( 'convertkit_shortcodes', $shortcodes );
173
174 return $shortcodes;
175
176 }
177
178 /**
179 * Helper method to get registered Blocks.
180 *
181 * @since 1.9.6
182 *
183 * @return array Blocks
184 */
185 function convertkit_get_blocks() {
186
187 $blocks = array();
188
189 /**
190 * Registers blocks for the ConvertKit Plugin.
191 *
192 * @since 1.9.6
193 *
194 * @param array $blocks Blocks
195 */
196 $blocks = apply_filters( 'convertkit_blocks', $blocks );
197
198 return $blocks;
199
200 }
201
202 /**
203 * Helper method to get registered Block formatters for Gutenberg.
204 *
205 * @since 2.2.0
206 *
207 * @return array Block formatters
208 */
209 function convertkit_get_block_formatters() {
210
211 $block_formatters = array();
212
213 /**
214 * Registers block formatters in Gutenberg for the ConvertKit Plugin.
215 *
216 * @since 2.2.0
217 *
218 * @param array $block_formatters Block formatters.
219 */
220 $block_formatters = apply_filters( 'convertkit_get_block_formatters', $block_formatters );
221
222 return $block_formatters;
223
224 }
225
226 /**
227 * Helper method to return the Plugin Settings Link
228 *
229 * @since 1.9.6
230 *
231 * @param array $query_args Optional Query Args.
232 * @return string Settings Link
233 */
234 function convertkit_get_settings_link( $query_args = array() ) {
235
236 $query_args = array_merge(
237 $query_args,
238 array(
239 'page' => '_wp_convertkit_settings',
240 )
241 );
242
243 return add_query_arg( $query_args, admin_url( 'options-general.php' ) );
244
245 }
246
247 /**
248 * Helper method to return the URL the user needs to visit to register a ConvertKit account.
249 *
250 * @since 1.9.8.4
251 *
252 * @return string ConvertKit Registration URL.
253 */
254 function convertkit_get_registration_url() {
255
256 return add_query_arg(
257 array(
258 'utm_source' => 'wordpress',
259 'utm_term' => get_locale(),
260 'utm_content' => 'convertkit',
261 ),
262 'https://app.convertkit.com/users/signup'
263 );
264
265 }
266
267 /**
268 * Helper method to return the URL the user needs to visit to sign in to their ConvertKit account.
269 *
270 * @since 1.9.6.1
271 *
272 * @return string ConvertKit Login URL.
273 */
274 function convertkit_get_sign_in_url() {
275
276 return add_query_arg(
277 array(
278 'utm_source' => 'wordpress',
279 'utm_term' => get_locale(),
280 'utm_content' => 'convertkit',
281 ),
282 'https://app.convertkit.com/'
283 );
284
285 }
286
287 /**
288 * Helper method to return the URL the user needs to visit on the ConvertKit app to obtain their API Key and Secret.
289 *
290 * @since 1.9.6.1
291 *
292 * @return string ConvertKit App URL.
293 */
294 function convertkit_get_api_key_url() {
295
296 return add_query_arg(
297 array(
298 'utm_source' => 'wordpress',
299 'utm_term' => get_locale(),
300 'utm_content' => 'convertkit',
301 ),
302 'https://app.convertkit.com/account_settings/advanced_settings/'
303 );
304
305 }
306
307 /**
308 * Helper method to enqueue Select2 scripts for use within the ConvertKit Plugin.
309 *
310 * @since 1.9.6.4
311 */
312 function convertkit_select2_enqueue_scripts() {
313
314 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 );
315 wp_enqueue_script( 'convertkit-admin-select2', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/select2.js', array( 'convertkit-select2' ), CONVERTKIT_PLUGIN_VERSION, false );
316
317 }
318
319 /**
320 * Helper method to enqueue Select2 stylesheets for use within the ConvertKit Plugin.
321 *
322 * @since 1.9.6.4
323 */
324 function convertkit_select2_enqueue_styles() {
325
326 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 );
327 wp_enqueue_style( 'convertkit-admin-select2', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/select2.css', array(), CONVERTKIT_PLUGIN_VERSION );
328
329 }
330
331 /**
332 * Return the contents of the given local file.
333 *
334 * @since 2.2.2
335 *
336 * @param string $local_file Local file, including path.
337 * @return string File contents.
338 */
339 function convertkit_get_file_contents( $local_file ) {
340
341 // Call globals.
342 global $wp_filesystem;
343
344 // Load filesystem class.
345 require_once ABSPATH . 'wp-admin/includes/file.php';
346
347 // Initiate.
348 WP_Filesystem();
349
350 // Bail if the file doesn't exist.
351 if ( ! $wp_filesystem->exists( $local_file ) ) {
352 return '';
353 }
354
355 // Return file's contents.
356 return $wp_filesystem->get_contents( $local_file );
357
358 }
359