| @@ -39,18 +39,34 @@ | ||
| 39 | 39 | * @since 1.9.6 |
| 40 | 40 | */ |
| 41 | 41 | public function __construct() { |
| 42 | 42 | |
| 43 | - // Initialize class(es) to register hooks. | |
| 43 | + // Initialize classes that have hooks prior to the `init` hook. | |
| 44 | + // Divi Theme requires us to do this, although the Divi Builder Plugin works fine when loading | |
| 45 | + // our integration on `init`. | |
| 46 | + $this->classes['divi'] = new ConvertKit_Divi(); | |
| 47 | + $this->classes['widgets'] = new ConvertKit_Widgets(); | |
| 48 | + | |
| 49 | + // Initialize Plugin classes on init, so the `_load_textdomain_just_in_time` warning isn't triggered. | |
| 50 | + add_action( 'init', array( $this, 'initialize' ), 1 ); | |
| 51 | + add_action( 'init', array( $this, 'setup' ), 2 ); | |
| 52 | + | |
| 53 | + } | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * Initialize classes. | |
| 57 | + * | |
| 58 | + * @since 2.7.7 | |
| 59 | + */ | |
| 60 | + public function initialize() { | |
| 61 | + | |
| 44 | 62 | $this->initialize_admin(); |
| 45 | 63 | $this->initialize_admin_or_frontend_editor(); |
| 46 | 64 | $this->initialize_cli_cron(); |
| 47 | 65 | $this->initialize_frontend(); |
| 48 | 66 | $this->initialize_global(); |
| 67 | + $this->initialize_mcp(); | |
| 49 | 68 | |
| 50 | - // Load language files. | |
| 51 | - add_action( 'init', array( $this, 'load_language_files' ) ); | |
| 52 | - | |
| 53 | 69 | } |
| 54 | 70 | |
| 55 | 71 | /** |
| 56 | 72 | * Initialize classes for the WordPress Administration interface |
| @@ -63,21 +79,27 @@ | ||
| 63 | 79 | if ( ! is_admin() ) { |
| 64 | 80 | return; |
| 65 | 81 | } |
| 66 | 82 | |
| 67 | - $this->classes['admin_bulk_edit'] = new ConvertKit_Admin_Bulk_Edit(); | |
| 68 | - $this->classes['admin_cache_plugins'] = new ConvertKit_Admin_Cache_Plugins(); | |
| 69 | - $this->classes['admin_category'] = new ConvertKit_Admin_Category(); | |
| 70 | - $this->classes['admin_notices'] = new ConvertKit_Admin_Notices(); | |
| 71 | - $this->classes['admin_post'] = new ConvertKit_Admin_Post(); | |
| 72 | - $this->classes['admin_quick_edit'] = new ConvertKit_Admin_Quick_Edit(); | |
| 73 | - $this->classes['admin_refresh_resources'] = new ConvertKit_Admin_Refresh_Resources(); | |
| 74 | - $this->classes['admin_restrict_content'] = new ConvertKit_Admin_Restrict_Content(); | |
| 75 | - $this->classes['admin_settings'] = new ConvertKit_Admin_Settings(); | |
| 76 | - $this->classes['admin_setup_wizard_plugin'] = new ConvertKit_Admin_Setup_Wizard_Plugin(); | |
| 77 | - $this->classes['admin_setup_wizard_restrict_content'] = new ConvertKit_Admin_Setup_Wizard_Restrict_Content(); | |
| 78 | - $this->classes['admin_tinymce'] = new ConvertKit_Admin_TinyMCE(); | |
| 79 | - $this->classes['admin_user'] = new ConvertKit_Admin_User(); | |
| 83 | + $this->classes['admin_bulk_edit'] = new ConvertKit_Admin_Bulk_Edit(); | |
| 84 | + $this->classes['admin_cache_plugins'] = new ConvertKit_Admin_Cache_Plugins(); | |
| 85 | + $this->classes['admin_category'] = new ConvertKit_Admin_Category(); | |
| 86 | + $this->classes['admin_landing_page'] = new ConvertKit_Admin_Landing_Page(); | |
| 87 | + $this->classes['admin_legacy_resource_notice'] = new ConvertKit_Admin_Legacy_Resource_Notice(); | |
| 88 | + $this->classes['admin_importer_activecampaign'] = new ConvertKit_Admin_Importer_ActiveCampaign(); | |
| 89 | + $this->classes['admin_importer_aweber'] = new ConvertKit_Admin_Importer_AWeber(); | |
| 90 | + $this->classes['admin_importer_campaignmonitor'] = new ConvertKit_Admin_Importer_CampaignMonitor(); | |
| 91 | + $this->classes['admin_importer_convertkit_legacy_forms'] = new ConvertKit_Admin_Importer_ConvertKit_Legacy_Forms(); | |
| 92 | + $this->classes['admin_importer_mc4wp'] = new ConvertKit_Admin_Importer_MC4WP(); | |
| 93 | + $this->classes['admin_importer_mailpoet'] = new ConvertKit_Admin_Importer_Mailpoet(); | |
| 94 | + $this->classes['admin_importer_newsletter'] = new ConvertKit_Admin_Importer_Newsletter(); | |
| 95 | + $this->classes['admin_post'] = new ConvertKit_Admin_Post(); | |
| 96 | + $this->classes['admin_quick_edit'] = new ConvertKit_Admin_Quick_Edit(); | |
| 97 | + $this->classes['admin_restrict_content'] = new ConvertKit_Admin_Restrict_Content(); | |
| 98 | + $this->classes['admin_settings'] = new ConvertKit_Admin_Settings(); | |
| 99 | + $this->classes['admin_setup_wizard_landing_page'] = new ConvertKit_Admin_Setup_Wizard_Landing_Page(); | |
| 100 | + $this->classes['admin_setup_wizard_plugin'] = new ConvertKit_Admin_Setup_Wizard_Plugin(); | |
| 101 | + $this->classes['admin_setup_wizard_restrict_content'] = new ConvertKit_Admin_Setup_Wizard_Restrict_Content(); | |
| 80 | 102 | |
| 81 | 103 | /** |
| 82 | 104 | * Initialize integration classes for the WordPress Administration interface. |
| 83 | 105 | * |
| @@ -140,10 +162,11 @@ | ||
| 140 | 162 | if ( is_admin() ) { |
| 141 | 163 | return; |
| 142 | 164 | } |
| 143 | 165 | |
| 144 | - $this->classes['output'] = new ConvertKit_Output(); | |
| 145 | - $this->classes['output_restrict_content'] = new ConvertKit_Output_Restrict_Content(); | |
| 166 | + $this->classes['cache_plugins'] = new ConvertKit_Cache_Plugins(); | |
| 167 | + $this->classes['output'] = new ConvertKit_Output(); | |
| 168 | + $this->classes['output_broadcasts'] = new ConvertKit_Output_Broadcasts(); | |
| 146 | 169 | |
| 147 | 170 | /** |
| 148 | 171 | * Initialize integration classes for the frontend web site. |
| 149 | 172 | * |
| @@ -160,29 +183,38 @@ | ||
| 160 | 183 | * @since 1.9.6 |
| 161 | 184 | */ |
| 162 | 185 | private function initialize_global() { |
| 163 | 186 | |
| 164 | - $this->classes['ajax'] = new ConvertKit_AJAX(); | |
| 165 | - $this->classes['blocks_convertkit_broadcasts'] = new ConvertKit_Block_Broadcasts(); | |
| 166 | - $this->classes['blocks_convertkit_content'] = new ConvertKit_Block_Content(); | |
| 167 | - $this->classes['blocks_convertkit_formtrigger'] = new ConvertKit_Block_Form_Trigger(); | |
| 168 | - $this->classes['blocks_convertkit_form'] = new ConvertKit_Block_Form(); | |
| 169 | - $this->classes['blocks_convertkit_product'] = new ConvertKit_Block_Product(); | |
| 170 | - $this->classes['block_formatter_form_link'] = new ConvertKit_Block_Formatter_Form_Link(); | |
| 171 | - $this->classes['block_formatter_product_link'] = new ConvertKit_Block_Formatter_Product_Link(); | |
| 172 | - $this->classes['elementor'] = new ConvertKit_Elementor(); | |
| 173 | - $this->classes['gutenberg'] = new ConvertKit_Gutenberg(); | |
| 174 | - $this->classes['review_request'] = new ConvertKit_Review_Request( 'ConvertKit', 'convertkit', CONVERTKIT_PLUGIN_PATH ); | |
| 175 | - $this->classes['preview_output'] = new ConvertKit_Preview_Output(); | |
| 176 | - $this->classes['setup'] = new ConvertKit_Setup(); | |
| 177 | - $this->classes['shortcodes'] = new ConvertKit_Shortcodes(); | |
| 178 | - $this->classes['widgets'] = new ConvertKit_Widgets(); | |
| 187 | + $this->classes['admin_notices'] = new ConvertKit_Admin_Notices(); | |
| 188 | + $this->classes['admin_tinymce'] = new ConvertKit_Admin_TinyMCE(); | |
| 189 | + $this->classes['admin_refresh_resources'] = new ConvertKit_Admin_Refresh_Resources(); | |
| 190 | + $this->classes['blocks_convertkit_broadcasts'] = new ConvertKit_Block_Broadcasts(); | |
| 191 | + $this->classes['blocks_convertkit_content'] = new ConvertKit_Block_Content(); | |
| 192 | + $this->classes['blocks_convertkit_formtrigger'] = new ConvertKit_Block_Form_Trigger(); | |
| 193 | + $this->classes['blocks_convertkit_form'] = new ConvertKit_Block_Form(); | |
| 194 | + $this->classes['blocks_convertkit_form_builder'] = new ConvertKit_Block_Form_Builder(); | |
| 195 | + $this->classes['blocks_convertkit_form_builder_field_email'] = new ConvertKit_Block_Form_Builder_Field_Email(); | |
| 196 | + $this->classes['blocks_convertkit_form_builder_field_name'] = new ConvertKit_Block_Form_Builder_Field_Name(); | |
| 197 | + $this->classes['blocks_convertkit_form_builder_field_custom'] = new ConvertKit_Block_Form_Builder_Field_Custom(); | |
| 198 | + $this->classes['blocks_convertkit_member_content_login'] = new ConvertKit_Block_Member_Content_Login(); | |
| 199 | + $this->classes['blocks_convertkit_product'] = new ConvertKit_Block_Product(); | |
| 200 | + $this->classes['block_formatter_form_link'] = new ConvertKit_Block_Formatter_Form_Link(); | |
| 201 | + $this->classes['block_formatter_product_link'] = new ConvertKit_Block_Formatter_Product_Link(); | |
| 202 | + $this->classes['pre_publish_action_broadcast_export'] = new ConvertKit_Pre_Publish_Action_Broadcast_Export(); | |
| 203 | + $this->classes['plugin_sidebar_post_settings'] = new ConvertKit_Plugin_Sidebar_Post_Settings(); | |
| 204 | + $this->classes['broadcasts_exporter'] = new ConvertKit_Broadcasts_Exporter(); | |
| 205 | + $this->classes['broadcasts_importer'] = new ConvertKit_Broadcasts_Importer(); | |
| 206 | + $this->classes['elementor'] = new ConvertKit_Elementor(); | |
| 207 | + $this->classes['gutenberg'] = new ConvertKit_Gutenberg(); | |
| 208 | + $this->classes['mcp'] = new ConvertKit_MCP(); | |
| 209 | + $this->classes['media_library'] = new ConvertKit_Media_Library(); | |
| 210 | + $this->classes['output_restrict_content'] = new ConvertKit_Output_Restrict_Content(); | |
| 211 | + $this->classes['restrict_content_cache'] = new ConvertKit_Restrict_Content_Cache(); | |
| 212 | + $this->classes['review_request'] = new ConvertKit_Review_Request( 'Kit', 'convertkit', CONVERTKIT_PLUGIN_PATH ); | |
| 213 | + $this->classes['preview_output'] = new ConvertKit_Preview_Output(); | |
| 214 | + $this->classes['setup'] = new ConvertKit_Setup(); | |
| 215 | + $this->classes['shortcodes'] = new ConvertKit_Shortcodes(); | |
| 179 | 216 | |
| 180 | - // Run the setup's update process on WordPress' init hook. | |
| 181 | - // Doing this sooner may result in errors with WordPress functions that are not yet | |
| 182 | - // available to the update routine. | |
| 183 | - add_action( 'init', array( $this, 'update' ) ); | |
| 184 | - | |
| 185 | 217 | /** |
| 186 | 218 | * Initialize integration classes for the frontend web site. |
| 187 | 219 | * |
| 188 | 220 | * @since 1.9.6 |
| @@ -191,16 +223,63 @@ | ||
| 191 | 223 | |
| 192 | 224 | } |
| 193 | 225 | |
| 194 | 226 | /** |
| 195 | - * Runs the Plugin's update routine, which checks if | |
| 227 | + * Initializes the MCP server if enabled in the Plugin's settings. | |
| 228 | + * | |
| 229 | + * @since 3.4.0 | |
| 230 | + */ | |
| 231 | + public function initialize_mcp() { | |
| 232 | + | |
| 233 | + // Bail if the MCP server is not enabled. | |
| 234 | + $settings = new ConvertKit_Settings_MCP(); | |
| 235 | + if ( ! $settings->enabled() ) { | |
| 236 | + return; | |
| 237 | + } | |
| 238 | + | |
| 239 | + // Bail if the Abilities API is unavailable (WordPress < 6.9). | |
| 240 | + if ( ! function_exists( 'wp_register_ability' ) ) { | |
| 241 | + return; | |
| 242 | + } | |
| 243 | + | |
| 244 | + // Bail if PHP 7.4+ is not installed, as this is required for the MCP Adapter classes. | |
| 245 | + if ( version_compare( PHP_VERSION, '7.4', '<' ) ) { | |
| 246 | + return; | |
| 247 | + } | |
| 248 | + | |
| 249 | + // Load MCP Adapter if another Plugin hasn't already loaded it. | |
| 250 | + if ( ! class_exists( 'WP\\MCP\\Core\\McpAdapter' ) ) { | |
| 251 | + // Bail if the WordPress MCP Adapter autoloader is missing. | |
| 252 | + if ( ! file_exists( CONVERTKIT_PLUGIN_PATH . '/vendor/autoload.php' ) ) { | |
| 253 | + return; | |
| 254 | + } | |
| 255 | + | |
| 256 | + // Load MCP Adapter. | |
| 257 | + require_once CONVERTKIT_PLUGIN_PATH . '/vendor/autoload.php'; | |
| 258 | + | |
| 259 | + // Bail if the MCP Adapter class doesn't exist - something went wrong with the autoloader. | |
| 260 | + if ( ! class_exists( 'WP\\MCP\\Core\\McpAdapter' ) ) { // @phpstan-ignore-line | |
| 261 | + return; | |
| 262 | + } | |
| 263 | + } | |
| 264 | + | |
| 265 | + // Bootstrap the MCP Adapter, per WordPress/mcp-adapter's recommended | |
| 266 | + // integration pattern. | |
| 267 | + // @see https://github.com/WordPress/mcp-adapter#using-mcp-adapter-in-your-plugin. | |
| 268 | + \WP\MCP\Core\McpAdapter::instance(); | |
| 269 | + | |
| 270 | + } | |
| 271 | + | |
| 272 | + /** | |
| 273 | + * Runs the Plugin's initialization and update routines, which checks if | |
| 196 | 274 | * the Plugin has just been updated to a newer version, |
| 197 | 275 | * and if so runs any specific processes that might be needed. |
| 198 | 276 | * |
| 199 | 277 | * @since 1.9.7.4 |
| 200 | 278 | */ |
| 201 | - public function update() { | |
| 279 | + public function setup() { | |
| 202 | 280 | |
| 281 | + $this->get_class( 'setup' )->initialize(); | |
| 203 | 282 | $this->get_class( 'setup' )->update(); |
| 204 | 283 | |
| 205 | 284 | } |
| 206 | 285 | |
| @@ -220,15 +299,15 @@ | ||
| 220 | 299 | } |
| 221 | 300 | |
| 222 | 301 | // Pro. |
| 223 | 302 | if ( array_key_exists( 'REQUEST_URI', $_SERVER ) ) { |
| 224 | - if ( strpos( sanitize_text_field( $_SERVER['REQUEST_URI'] ), '/pro/' ) !== false ) { | |
| 303 | + if ( strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), '/pro/' ) !== false ) { | |
| 225 | 304 | return true; |
| 226 | 305 | } |
| 227 | - if ( strpos( sanitize_text_field( $_SERVER['REQUEST_URI'] ), '/x/' ) !== false ) { | |
| 306 | + if ( strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), '/x/' ) !== false ) { | |
| 228 | 307 | return true; |
| 229 | 308 | } |
| 230 | - if ( strpos( sanitize_text_field( $_SERVER['REQUEST_URI'] ), 'cornerstone-endpoint' ) !== false ) { | |
| 309 | + if ( strpos( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'cornerstone-endpoint' ) !== false ) { | |
| 231 | 310 | return true; |
| 232 | 311 | } |
| 233 | 312 | } |
| 234 | 313 | |
| @@ -260,9 +339,9 @@ | ||
| 260 | 339 | return true; |
| 261 | 340 | } |
| 262 | 341 | |
| 263 | 342 | // Elementor. |
| 264 | - if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( $_REQUEST['action'] ) === 'elementor' ) { | |
| 343 | + if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) === 'elementor' ) { | |
| 265 | 344 | return true; |
| 266 | 345 | } |
| 267 | 346 | |
| 268 | 347 | // Kallyas. |
| @@ -290,9 +369,9 @@ | ||
| 290 | 369 | return true; |
| 291 | 370 | } |
| 292 | 371 | |
| 293 | 372 | // Zion Builder. |
| 294 | - if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( $_REQUEST['action'] ) === 'zion_builder_active' ) { | |
| 373 | + if ( array_key_exists( 'action', $_REQUEST ) && sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) === 'zion_builder_active' ) { | |
| 295 | 374 | return true; |
| 296 | 375 | } |
| 297 | 376 | |
| 298 | 377 | // Assume we're not in the Administration interface. |
| @@ -344,34 +423,13 @@ | ||
| 344 | 423 | * @return bool Is WP CRON Request |
| 345 | 424 | */ |
| 346 | 425 | public function is_cron() { |
| 347 | 426 | |
| 348 | - if ( ! defined( 'DOING_CRON' ) ) { | |
| 349 | - return false; | |
| 350 | - } | |
| 351 | - if ( ! DOING_CRON ) { | |
| 352 | - return false; | |
| 353 | - } | |
| 427 | + return wp_doing_cron(); | |
| 354 | 428 | |
| 355 | - return true; | |
| 356 | - | |
| 357 | 429 | } |
| 358 | 430 | |
| 359 | 431 | /** |
| 360 | - * Loads the plugin's translated strings, if available. | |
| 361 | - * | |
| 362 | - * @since 1.0.0 | |
| 363 | - */ | |
| 364 | - public function load_language_files() { | |
| 365 | - | |
| 366 | - // If the .mo file for a given language is available in WP_LANG_DIR/convertkit | |
| 367 | - // i.e. it's available as a translation at https://translate.wordpress.org/projects/wp-plugins/convertkit/, | |
| 368 | - // it will be used instead of the .mo file in convertkit/languages. | |
| 369 | - load_plugin_textdomain( 'convertkit', false, 'convertkit/languages' ); | |
| 370 | - | |
| 371 | - } | |
| 372 | - | |
| 373 | - /** | |
| 374 | 432 | * Returns the given class |
| 375 | 433 | * |
| 376 | 434 | * @since 1.9.6 |
| 377 | 435 | * |
| @@ -387,9 +445,9 @@ | ||
| 387 | 445 | $error = new WP_Error( |
| 388 | 446 | 'convertkit_get_class', |
| 389 | 447 | sprintf( |
| 390 | 448 | /* translators: %1$s: PHP class name */ |
| 391 | - __( 'ConvertKit Error: Could not load Plugin class <strong>%1$s</strong>', 'convertkit' ), | |
| 449 | + __( 'Kit Error: Could not load Plugin class <strong>%1$s</strong>', 'convertkit' ), | |
| 392 | 450 | $name |
| 393 | 451 | ) |
| 394 | 452 | ); |
| 395 | 453 | |
| @@ -397,9 +455,9 @@ | ||
| 397 | 455 | // Admin UI. |
| 398 | 456 | if ( is_admin() ) { |
| 399 | 457 | wp_die( |
| 400 | 458 | esc_attr( $error->get_error_message() ), |
| 401 | - esc_html__( 'ConvertKit Error', 'convertkit' ), | |
| 459 | + esc_html__( 'Kit Error', 'convertkit' ), | |
| 402 | 460 | array( |
| 403 | 461 | 'back_link' => true, |
| 404 | 462 | ) |
| 405 | 463 | ); |