initialize(); // Check if we are on a multisite install, activating network wide, or a single install. if ( ! is_multisite() || ! $network_wide ) { // Single Site activation. $convertkit->get_class( 'setup' )->activate(); // Set a transient for 30 seconds to redirect to the setup screen on activation. set_transient( 'convertkit-setup', true, 30 ); } else { // Multisite network wide activation. $sites = get_sites( array( 'number' => 0, ) ); foreach ( $sites as $site ) { switch_to_blog( (int) $site->blog_id ); $convertkit->get_class( 'setup' )->activate(); restore_current_blog(); } } } /** * Runs the activation and update routines when the plugin is activated * on a WordPress multisite setup. * * @since 1.9.7.4 * * @param WP_Site|int $site_or_blog_id WP_Site or Blog ID. */ function convertkit_plugin_activate_new_site( $site_or_blog_id ) { // Check if $site_or_blog_id is a WP_Site or a blog ID. if ( is_a( $site_or_blog_id, 'WP_Site' ) ) { $site_or_blog_id = $site_or_blog_id->blog_id; } // Initialise Plugin. $convertkit = WP_ConvertKit(); $convertkit->initialize(); // Run installation routine. switch_to_blog( $site_or_blog_id ); $convertkit->get_class( 'setup' )->activate(); restore_current_blog(); } /** * Runs the deactivation routine when the plugin is deactivated. * * @since 1.9.7.4 * * @param bool $network_wide Is network wide deactivation. */ function convertkit_plugin_deactivate( $network_wide ) { // Initialise Plugin. $convertkit = WP_ConvertKit(); $convertkit->initialize(); // Check if we are on a multisite install, activating network wide, or a single install. if ( ! is_multisite() || ! $network_wide ) { // Single Site activation. $convertkit->get_class( 'setup' )->deactivate(); } else { // Multisite network wide activation. $sites = get_sites( array( 'number' => 0, ) ); foreach ( $sites as $site ) { switch_to_blog( (int) $site->blog_id ); $convertkit->get_class( 'setup' )->deactivate(); restore_current_blog(); } } } /** * Helper method to get supported Post Types. * * @since 1.9.6 * * @return array Post Types */ function convertkit_get_supported_post_types() { // Define supported Post Types. $post_types = array( 'page', 'post', ); // If public Custom Post Types can be fetched, include them now. if ( function_exists( 'get_post_types' ) ) { // Get public Custom Post Types. $custom_post_types = (array) get_post_types( array( 'public' => true, // Don't include WordPress' built in Post Types, such as attachment, revisino and nav_menu_item. '_builtin' => false, ) ); $post_types = array_merge( $post_types, array_keys( $custom_post_types ) ); } /** * Defines the Post Types that support ConvertKit Forms. * * @since 1.9.6 * * @param array $post_types Post Types */ $post_types = apply_filters( 'convertkit_get_supported_post_types', $post_types ); return $post_types; } /** * Determines whether the current user can create and publish the given Post Type. * * @since 3.3.9 * * @param string $post_type Post Type. * @return bool User can create and publish Post Type. */ function convertkit_user_can_create_published_post_type( $post_type ) { $post_type_object = get_post_type_object( $post_type ); if ( ! $post_type_object ) { return false; } return current_user_can( $post_type_object->cap->create_posts ) && current_user_can( $post_type_object->cap->publish_posts ); } /** * Helper method to get supported Post Types for Restricted Content (Member's Content) * * @since 2.1.0 * * @deprecated 2.4.3 No longer used by internal code and not recommended. Use `convertkit_get_supported_post_types` instead. * * @return array Post Types */ function convertkit_get_supported_restrict_content_post_types() { return convertkit_get_supported_post_types(); } /** * Helper method to get registered Shortcodes. * * @since 1.9.6.5 * * @return array Shortcodes */ function convertkit_get_shortcodes() { $shortcodes = array(); /** * Registers shortcodes for the ConvertKit Plugin. * * @since 1.9.6.5 * * @param array $shortcodes Shortcodes */ $shortcodes = apply_filters( 'convertkit_shortcodes', $shortcodes ); return $shortcodes; } /** * Helper method to get registered Blocks. * * @since 1.9.6 * * @return array Blocks */ function convertkit_get_blocks() { $blocks = array(); /** * Registers blocks for the ConvertKit Plugin. * * @since 1.9.6 * * @param array $blocks Blocks */ $blocks = apply_filters( 'convertkit_blocks', $blocks ); return $blocks; } /** * Helper method to get registered Block formatters for Gutenberg. * * @since 2.2.0 * * @return array Block formatters */ function convertkit_get_block_formatters() { $block_formatters = array(); /** * Registers block formatters in Gutenberg for the ConvertKit Plugin. * * @since 2.2.0 * * @param array $block_formatters Block formatters. */ $block_formatters = apply_filters( 'convertkit_get_block_formatters', $block_formatters ); return $block_formatters; } /** * Helper method to get registered plugin sidebars. * * @since 3.3.0 * * @return array Plugin sidebars */ function convertkit_get_plugin_sidebars() { $plugin_sidebars = array(); /** * Registers plugin sidebars for the WordPress block editor. * * @since 3.3.0 * * @param array $plugin_sidebars Plugin sidebars. */ $plugin_sidebars = apply_filters( 'convertkit_plugin_sidebars', $plugin_sidebars ); return $plugin_sidebars; } /** * Helper method to get registered pre-publish actions. * * @since 2.4.0 * * @return array Pre-publish actions */ function convertkit_get_pre_publish_actions() { $pre_publish_actions = array(); /** * Registers pre-publish actions for the ConvertKit Plugin. * * @since 2.4.0 * * @param array $pre_publish_panels Pre-publish actions. */ $pre_publish_actions = apply_filters( 'convertkit_get_pre_publish_actions', $pre_publish_actions ); return $pre_publish_actions; } /** * Helper method to get registered importers that can replace third party * form shortcodes and blocks with Kit form shortcodes and blocks. * * @since 3.1.7 * * @return array Importers. */ function convertkit_get_form_importers() { $importers = array(); /** * Registers form importers for the ConvertKit Plugin. * * @since 3.1.7 * * @param array $importers Importers. */ $importers = apply_filters( 'convertkit_get_form_importers', $importers ); return $importers; } /** * Helper method to get registered abilities. * * @since 3.4.0 * * @return array Abilities. */ function convertkit_get_abilities() { $abilities = array(); /** * Registers abilities for the Kit Plugin. * * @since 3.4.0 * * @param array $abilities Abilities. */ $abilities = apply_filters( 'convertkit_abilities', $abilities ); return $abilities; } /** * Helper method to return the Plugin Settings Link * * @since 1.9.6 * * @param array $query_args Optional Query Args. * @return string Settings Link */ function convertkit_get_settings_link( $query_args = array() ) { $query_args = array_merge( $query_args, array( 'page' => '_wp_convertkit_settings', ) ); return add_query_arg( $query_args, admin_url( 'options-general.php' ) ); } /** * Helper method to return the Plugin Settings Link * * @since 2.2.4 * * @param array $query_args Optional Query Args. * @return string Settings Link */ function convertkit_get_setup_wizard_plugin_link( $query_args = array() ) { $query_args = array_merge( $query_args, array( 'page' => 'convertkit-setup', ) ); return add_query_arg( $query_args, admin_url( 'options.php' ) ); } /** * Helper method to return the URL the user needs to visit to register a ConvertKit account. * * @since 1.9.8.4 * * @return string ConvertKit Registration URL. */ function convertkit_get_registration_url() { return add_query_arg( array( 'utm_source' => 'wordpress', 'utm_term' => get_locale(), 'utm_content' => 'convertkit', ), 'https://app.kit.com/users/signup' ); } /** * Helper method to return the URL the user needs to visit to sign in to their ConvertKit account. * * @since 1.9.6.1 * * @return string ConvertKit Login URL. */ function convertkit_get_sign_in_url() { return add_query_arg( array( 'utm_source' => 'wordpress', 'utm_term' => get_locale(), 'utm_content' => 'convertkit', ), 'https://app.kit.com/' ); } /** * Helper method to return the URL the user needs to visit to manage thier billing. * * @since 2.2.7 * * @return string ConvertKit Billing URL. */ function convertkit_get_billing_url() { return add_query_arg( array( 'utm_source' => 'wordpress', 'utm_term' => get_locale(), 'utm_content' => 'convertkit', ), 'https://app.kit.com/account_settings/billing/' ); } /** * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Form or Landing Page. * * @since 2.2.3 * * @return string ConvertKit App URL */ function convertkit_get_new_form_url() { return add_query_arg( array( 'utm_source' => 'wordpress', 'utm_term' => get_locale(), 'utm_content' => 'convertkit', ), 'https://app.kit.com/forms/new/' ); } /** * Helper method to return the URL the user needs to visit to edit ConvertKit forms. * * @since 2.2.3 * * @return string ConvertKit Form Editor URL. */ function convertkit_get_form_editor_url() { return add_query_arg( array( 'utm_source' => 'wordpress', 'utm_term' => get_locale(), 'utm_content' => 'convertkit', ), 'https://app.kit.com/forms' ); } /** * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Landing Page. * * @since 2.5.5 * * @return string ConvertKit App URL */ function convertkit_get_new_landing_page_url() { return add_query_arg( array( 'utm_source' => 'wordpress', 'utm_term' => get_locale(), 'utm_content' => 'convertkit', ), 'https://app.kit.com/pages/new/' ); } /** * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Tag. * * @since 2.3.3 * * @return string ConvertKit App URL. */ function convertkit_get_new_tag_url() { return add_query_arg( array( 'utm_source' => 'wordpress', 'utm_term' => get_locale(), 'utm_content' => 'convertkit', ), 'https://app.kit.com/subscribers/' ); } /** * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Broadcast. * * @since 2.2.6 * * @return string ConvertKit App URL. */ function convertkit_get_new_broadcast_url() { return add_query_arg( array( 'utm_source' => 'wordpress', 'utm_term' => get_locale(), 'utm_content' => 'convertkit', ), 'https://app.kit.com/campaigns/' ); } /** * Helper method to return the URL the user needs to visit on the ConvertKit app to edit a draft Broadcast. * * @since 2.4.0 * * @param int $broadcast_id ConvertKit Broadcast ID. * @return string ConvertKit App URL. */ function convertkit_get_edit_broadcast_url( $broadcast_id ) { return add_query_arg( array( 'utm_source' => 'wordpress', 'utm_term' => get_locale(), 'utm_content' => 'convertkit', ), sprintf( 'https://app.kit.com/campaigns/%s/draft', $broadcast_id ) ); } /** * Helper method to return the URL the user needs to visit on the ConvertKit app to create a new Product. * * @since 2.2.3 * * @return string ConvertKit App URL. */ function convertkit_get_new_product_url() { return add_query_arg( array( 'utm_source' => 'wordpress', 'utm_term' => get_locale(), 'utm_content' => 'convertkit', ), 'https://app.kit.com/products/new/' ); } /** * Helper method to enqueue the frontend CSS file. * * @since 3.2.0 */ function convertkit_enqueue_frontend_css() { wp_enqueue_style( 'convertkit-frontend', CONVERTKIT_PLUGIN_URL . 'resources/frontend/css/frontend.css', array(), CONVERTKIT_PLUGIN_VERSION ); } /** * Helper method to enqueue the frontend JS file. * * @since 3.2.0 */ function convertkit_enqueue_frontend_js() { wp_enqueue_script( 'convertkit-js', CONVERTKIT_PLUGIN_URL . 'resources/frontend/js/dist/frontend.min.js', array(), CONVERTKIT_PLUGIN_VERSION, true ); } /** * Helper method to enqueue Select2 scripts for use within the ConvertKit Plugin. * * @since 1.9.6.4 */ function convertkit_select2_enqueue_scripts() { 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 ); wp_enqueue_script( 'convertkit-admin-select2', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/select2.js', array( 'convertkit-select2' ), CONVERTKIT_PLUGIN_VERSION, false ); } /** * Helper method to enqueue Select2 stylesheets for use within the ConvertKit Plugin. * * @since 1.9.6.4 */ function convertkit_select2_enqueue_styles() { 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 ); wp_enqueue_style( 'convertkit-admin-select2', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/select2.css', array(), CONVERTKIT_PLUGIN_VERSION ); } /** * Return the contents of the given local file. * * @since 2.2.2 * * @param string $local_file Local file, including path. * @return string File contents. */ function convertkit_get_file_contents( $local_file ) { // Bail if the file doesn't exist. if ( ! file_exists( $local_file ) ) { return ''; } // Read file. $contents = file_get_contents( $local_file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents // Return an empty string if the contents of the file could not be read. if ( ! $contents ) { return ''; } // Return file's contents. return $contents; } /** * Returns a dropdown field commonly used for settings, comprising of: * - Do not subscribe * - Subscribe * - Subscribe to Form * * @since 2.5.2 * * @param string $name Field name. * @param string $value Field value. * @param string $id Field ID attribute. * @param string $css_class Field CSS class(es). * @param string $context Resource context. * @param bool|array $additional_options Additional