classes['divi'] = new ConvertKit_Divi(); $this->classes['widgets'] = new ConvertKit_Widgets(); // Initialize Plugin classes on init, so the `_load_textdomain_just_in_time` warning isn't triggered. add_action( 'init', array( $this, 'initialize' ), 1 ); add_action( 'init', array( $this, 'setup' ), 2 ); } /** * Initialize classes. * * @since 2.7.7 */ public function initialize() { $this->initialize_admin(); $this->initialize_admin_or_frontend_editor(); $this->initialize_cli_cron(); $this->initialize_frontend(); $this->initialize_global(); $this->initialize_mcp(); } /** * Initialize classes for the WordPress Administration interface * * @since 1.9.6 */ private function initialize_admin() { // Bail if this request isn't for the WordPress Administration interface. if ( ! is_admin() ) { return; } $this->classes['admin_bulk_edit'] = new ConvertKit_Admin_Bulk_Edit(); $this->classes['admin_cache_plugins'] = new ConvertKit_Admin_Cache_Plugins(); $this->classes['admin_category'] = new ConvertKit_Admin_Category(); $this->classes['admin_landing_page'] = new ConvertKit_Admin_Landing_Page(); $this->classes['admin_legacy_resource_notice'] = new ConvertKit_Admin_Legacy_Resource_Notice(); $this->classes['admin_importer_activecampaign'] = new ConvertKit_Admin_Importer_ActiveCampaign(); $this->classes['admin_importer_aweber'] = new ConvertKit_Admin_Importer_AWeber(); $this->classes['admin_importer_campaignmonitor'] = new ConvertKit_Admin_Importer_CampaignMonitor(); $this->classes['admin_importer_convertkit_legacy_forms'] = new ConvertKit_Admin_Importer_ConvertKit_Legacy_Forms(); $this->classes['admin_importer_mc4wp'] = new ConvertKit_Admin_Importer_MC4WP(); $this->classes['admin_importer_mailpoet'] = new ConvertKit_Admin_Importer_Mailpoet(); $this->classes['admin_importer_newsletter'] = new ConvertKit_Admin_Importer_Newsletter(); $this->classes['admin_post'] = new ConvertKit_Admin_Post(); $this->classes['admin_quick_edit'] = new ConvertKit_Admin_Quick_Edit(); $this->classes['admin_restrict_content'] = new ConvertKit_Admin_Restrict_Content(); $this->classes['admin_settings'] = new ConvertKit_Admin_Settings(); $this->classes['admin_setup_wizard_landing_page'] = new ConvertKit_Admin_Setup_Wizard_Landing_Page(); $this->classes['admin_setup_wizard_plugin'] = new ConvertKit_Admin_Setup_Wizard_Plugin(); $this->classes['admin_setup_wizard_restrict_content'] = new ConvertKit_Admin_Setup_Wizard_Restrict_Content(); /** * Initialize integration classes for the WordPress Administration interface. * * @since 1.9.6 */ do_action( 'convertkit_initialize_admin' ); } /** * Initialize classes for the WordPress Administration interface or a frontend Page Builder * * @since 1.9.6 */ private function initialize_admin_or_frontend_editor() { // Bail if this request isn't for the WordPress Administration interface and isn't for a frontend Page Builder. if ( ! $this->is_admin_or_frontend_editor() ) { return; } /** * Initialize integration classes for the WordPress Administration interface or a frontend Page Builder. * * @since 1.9.6 */ do_action( 'convertkit_initialize_admin_or_frontend_editor' ); } /** * Initialize classes for WP-CLI and WP-Cron * * @since 2.5.2 */ private function initialize_cli_cron() { // Bail if this isn't a CLI or CRON request. if ( ! $this->is_cli() && ! $this->is_cron() ) { return; } /** * Initialize integration classes for WP-CLI and WP-Cron. * * @since 1.9.6 */ do_action( 'convertkit_initialize_cli_cron' ); } /** * Initialize classes for the frontend web site * * @since 1.9.6 */ private function initialize_frontend() { // Bail if this request isn't for the frontend web site. if ( is_admin() ) { return; } $this->classes['cache_plugins'] = new ConvertKit_Cache_Plugins(); $this->classes['output'] = new ConvertKit_Output(); $this->classes['output_broadcasts'] = new ConvertKit_Output_Broadcasts(); /** * Initialize integration classes for the frontend web site. * * @since 1.9.6 */ do_action( 'convertkit_initialize_frontend' ); } /** * Initialize classes required globally, across the WordPress Administration, CLI, Cron and Frontend * web site. * * @since 1.9.6 */ private function initialize_global() { $this->classes['admin_notices'] = new ConvertKit_Admin_Notices(); $this->classes['admin_tinymce'] = new ConvertKit_Admin_TinyMCE(); $this->classes['admin_refresh_resources'] = new ConvertKit_Admin_Refresh_Resources(); $this->classes['blocks_convertkit_broadcasts'] = new ConvertKit_Block_Broadcasts(); $this->classes['blocks_convertkit_content'] = new ConvertKit_Block_Content(); $this->classes['blocks_convertkit_formtrigger'] = new ConvertKit_Block_Form_Trigger(); $this->classes['blocks_convertkit_form'] = new ConvertKit_Block_Form(); $this->classes['blocks_convertkit_form_builder'] = new ConvertKit_Block_Form_Builder(); $this->classes['blocks_convertkit_form_builder_field_email'] = new ConvertKit_Block_Form_Builder_Field_Email(); $this->classes['blocks_convertkit_form_builder_field_name'] = new ConvertKit_Block_Form_Builder_Field_Name(); $this->classes['blocks_convertkit_form_builder_field_custom'] = new ConvertKit_Block_Form_Builder_Field_Custom(); $this->classes['blocks_convertkit_product'] = new ConvertKit_Block_Product(); $this->classes['block_formatter_form_link'] = new ConvertKit_Block_Formatter_Form_Link(); $this->classes['block_formatter_product_link'] = new ConvertKit_Block_Formatter_Product_Link(); $this->classes['pre_publish_action_broadcast_export'] = new ConvertKit_Pre_Publish_Action_Broadcast_Export(); $this->classes['plugin_sidebar_post_settings'] = new ConvertKit_Plugin_Sidebar_Post_Settings(); $this->classes['broadcasts_exporter'] = new ConvertKit_Broadcasts_Exporter(); $this->classes['broadcasts_importer'] = new ConvertKit_Broadcasts_Importer(); $this->classes['elementor'] = new ConvertKit_Elementor(); $this->classes['gutenberg'] = new ConvertKit_Gutenberg(); $this->classes['mcp'] = new ConvertKit_MCP(); $this->classes['media_library'] = new ConvertKit_Media_Library(); $this->classes['output_restrict_content'] = new ConvertKit_Output_Restrict_Content(); $this->classes['restrict_content_cache'] = new ConvertKit_Restrict_Content_Cache(); $this->classes['review_request'] = new ConvertKit_Review_Request( 'Kit', 'convertkit', CONVERTKIT_PLUGIN_PATH ); $this->classes['preview_output'] = new ConvertKit_Preview_Output(); $this->classes['setup'] = new ConvertKit_Setup(); $this->classes['shortcodes'] = new ConvertKit_Shortcodes(); /** * Initialize integration classes for the frontend web site. * * @since 1.9.6 */ do_action( 'convertkit_initialize_global' ); } /** * Initializes the MCP server if enabled in the Plugin's settings. * * @since 3.4.0 */ public function initialize_mcp() { // Bail if the MCP server is not enabled. $settings = new ConvertKit_Settings_MCP(); if ( ! $settings->enabled() ) { return; } // Bail if the Abilities API is unavailable (WordPress < 6.9). if ( ! function_exists( 'wp_register_ability' ) ) { return; } // Bail if PHP 7.4+ is not installed, as this is required for the MCP Adapter classes. if ( version_compare( PHP_VERSION, '7.4', '<' ) ) { return; } // Load MCP Adapter if another Plugin hasn't already loaded it. if ( ! class_exists( 'WP\\MCP\\Core\\McpAdapter' ) ) { // Bail if the WordPress MCP Adapter autoloader is missing. if ( ! file_exists( CONVERTKIT_PLUGIN_PATH . '/vendor/autoload.php' ) ) { return; } // Load MCP Adapter. require_once CONVERTKIT_PLUGIN_PATH . '/vendor/autoload.php'; // Bail if the MCP Adapter class doesn't exist - something went wrong with the autoloader. if ( ! class_exists( 'WP\\MCP\\Core\\McpAdapter' ) ) { // @phpstan-ignore-line return; } } // Bootstrap the MCP Adapter, per WordPress/mcp-adapter's recommended // integration pattern. // @see https://github.com/WordPress/mcp-adapter#using-mcp-adapter-in-your-plugin. \WP\MCP\Core\McpAdapter::instance(); } /** * Runs the Plugin's initialization and update routines, which checks if * the Plugin has just been updated to a newer version, * and if so runs any specific processes that might be needed. * * @since 1.9.7.4 */ public function setup() { $this->get_class( 'setup' )->initialize(); $this->get_class( 'setup' )->update(); } /** * Improved version of WordPress' is_admin(), which includes whether we're * editing on the frontend using a Page Builder. * * @since 1.9.6 * * @return bool Is Admin or Frontend Editor Request */ public function is_admin_or_frontend_editor() { // If we're in the wp-admin, return true. if ( is_admin() ) { return true; } // Pro. if ( array_key_exists( 'REQUEST_URI', $_SERVER ) ) { if ( strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), '/pro/' ) !== false ) { return true; } if ( strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), '/x/' ) !== false ) { return true; } if ( strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'cornerstone-endpoint' ) !== false ) { return true; } } // If the request global exists, check for specific request keys which tell us // that we're using a frontend editor. // Avada Live. // phpcs:disable WordPress.Security.NonceVerification.Recommended if ( array_key_exists( 'fb-edit', $_REQUEST ) ) { return true; } // Beaver Builder. if ( array_key_exists( 'fl_builder', $_REQUEST ) ) { return true; } // Brizy. if ( array_key_exists( 'brizy-edit', $_REQUEST ) ) { return true; } // Cornerstone (AJAX). if ( array_key_exists( '_cs_nonce', $_REQUEST ) ) { return true; } // Divi. if ( array_key_exists( 'et_fb', $_REQUEST ) ) { return true; } // Elementor. if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) === 'elementor' ) { return true; } // Kallyas. if ( array_key_exists( 'zn_pb_edit', $_REQUEST ) ) { return true; } // Oxygen. if ( array_key_exists( 'ct_builder', $_REQUEST ) ) { return true; } // Thrive Architect. if ( array_key_exists( 'tve', $_REQUEST ) ) { return true; } // Visual Composer. if ( array_key_exists( 'vcv-editable', $_REQUEST ) ) { return true; } // WPBakery Page Builder. if ( array_key_exists( 'vc_editable', $_REQUEST ) ) { return true; } // Zion Builder. if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) === 'zion_builder_active' ) { return true; } // Assume we're not in the Administration interface. $is_admin_or_frontend_editor = false; /** * Filters whether the current request is a WordPress Administration / Frontend Editor request or not. * * Page Builders can set this to true to allow ConvertKit to load its administration functionality. * * @since 1.9.6 * * @param bool $is_admin_or_frontend_editor Is WordPress Administration / Frontend Editor request. */ $is_admin_or_frontend_editor = apply_filters( 'convertkit_is_admin_or_frontend_editor', $is_admin_or_frontend_editor ); // phpcs:enable // Return filtered result. return $is_admin_or_frontend_editor; } /** * Detects if the request is through the WP-CLI * * @since 1.9.6 * * @return bool Is WP-CLI Request */ public function is_cli() { if ( ! defined( 'WP_CLI' ) ) { return false; } if ( ! WP_CLI ) { return false; } return true; } /** * Detects if the request is through the WP CRON * * @since 1.9.6 * * @return bool Is WP CRON Request */ public function is_cron() { return wp_doing_cron(); } /** * Returns the given class * * @since 1.9.6 * * @param string $name Class Name. * @return object Class Object */ public function get_class( $name ) { // If the class hasn't been loaded, throw a WordPress die screen // to avoid a PHP fatal error. if ( ! isset( $this->classes[ $name ] ) ) { // Define the error. $error = new WP_Error( 'convertkit_get_class', sprintf( /* translators: %1$s: PHP class name */ __( 'Kit Error: Could not load Plugin class %1$s', 'convertkit' ), $name ) ); // Depending on the request, return or display an error. // Admin UI. if ( is_admin() ) { wp_die( esc_attr( $error->get_error_message() ), esc_html__( 'Kit Error', 'convertkit' ), array( 'back_link' => true, ) ); } // Cron / CLI. return $error; } // Return the class object. return $this->classes[ $name ]; } /** * Returns the singleton instance of the class. * * @since 1.1.6 * * @return object Class. */ public static function get_instance() { if ( null === self::$instance ) { self::$instance = new self(); } return self::$instance; } }