| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Yoast\WP\SEO\Integrations\Third_Party; |
| 4 | 4 | |
| 5 | +use Elementor\Plugin; | |
| 5 | 6 | use WP_Post; |
| 6 | -use WP_Screen; | |
| 7 | 7 | use WPSEO_Admin_Asset_Manager; |
| 8 | 8 | use WPSEO_Admin_Recommended_Replace_Vars; |
| 9 | 9 | use WPSEO_Meta; |
| 10 | 10 | use WPSEO_Metabox_Analysis_Inclusive_Language; |
| @@ -17,8 +17,9 @@ | ||
| 17 | 17 | use Yoast\WP\SEO\Conditionals\Third_Party\Elementor_Edit_Conditional; |
| 18 | 18 | use Yoast\WP\SEO\Editors\Application\Site\Website_Information_Repository; |
| 19 | 19 | use Yoast\WP\SEO\Elementor\Infrastructure\Request_Post; |
| 20 | 20 | use Yoast\WP\SEO\Helpers\Capability_Helper; |
| 21 | +use Yoast\WP\SEO\Helpers\Current_Page_Helper; | |
| 21 | 22 | use Yoast\WP\SEO\Helpers\Options_Helper; |
| 22 | 23 | use Yoast\WP\SEO\Integrations\Integration_Interface; |
| 23 | 24 | use Yoast\WP\SEO\Presenters\Admin\Meta_Fields_Presenter; |
| 24 | 25 | use Yoast\WP\SEO\Promotions\Application\Promotion_Manager; |
| @@ -63,8 +64,15 @@ | ||
| 63 | 64 | */ |
| 64 | 65 | private $request_post; |
| 65 | 66 | |
| 66 | 67 | /** |
| 68 | + * Holds the current page helper. | |
| 69 | + * | |
| 70 | + * @var Current_Page_Helper | |
| 71 | + */ | |
| 72 | + private $current_page_helper; | |
| 73 | + | |
| 74 | + /** | |
| 67 | 75 | * Holds whether the socials are enabled. |
| 68 | 76 | * |
| 69 | 77 | * @var bool |
| 70 | 78 | */ |
| @@ -116,23 +124,26 @@ | ||
| 116 | 124 | |
| 117 | 125 | /** |
| 118 | 126 | * Constructor. |
| 119 | 127 | * |
| 120 | - * @param WPSEO_Admin_Asset_Manager $asset_manager The asset manager. | |
| 121 | - * @param Options_Helper $options The options helper. | |
| 122 | - * @param Capability_Helper $capability The capability helper. | |
| 123 | - * @param Request_Post $request_post The Request_Post. | |
| 128 | + * @param WPSEO_Admin_Asset_Manager $asset_manager The asset manager. | |
| 129 | + * @param Options_Helper $options The options helper. | |
| 130 | + * @param Capability_Helper $capability The capability helper. | |
| 131 | + * @param Request_Post $request_post The Request_Post. | |
| 132 | + * @param Current_Page_Helper $current_page_helper The current page helper. | |
| 124 | 133 | */ |
| 125 | 134 | public function __construct( |
| 126 | 135 | WPSEO_Admin_Asset_Manager $asset_manager, |
| 127 | 136 | Options_Helper $options, |
| 128 | 137 | Capability_Helper $capability, |
| 129 | - Request_Post $request_post | |
| 138 | + Request_Post $request_post, | |
| 139 | + Current_Page_Helper $current_page_helper | |
| 130 | 140 | ) { |
| 131 | - $this->asset_manager = $asset_manager; | |
| 132 | - $this->options = $options; | |
| 133 | - $this->capability = $capability; | |
| 134 | - $this->request_post = $request_post; | |
| 141 | + $this->asset_manager = $asset_manager; | |
| 142 | + $this->options = $options; | |
| 143 | + $this->capability = $capability; | |
| 144 | + $this->request_post = $request_post; | |
| 145 | + $this->current_page_helper = $current_page_helper; | |
| 135 | 146 | |
| 136 | 147 | $this->seo_analysis = new WPSEO_Metabox_Analysis_SEO(); |
| 137 | 148 | $this->readability_analysis = new WPSEO_Metabox_Analysis_Readability(); |
| 138 | 149 | $this->inclusive_language_analysis = new WPSEO_Metabox_Analysis_Inclusive_Language(); |
| @@ -420,8 +431,14 @@ | ||
| 420 | 431 | |
| 421 | 432 | $this->asset_manager->enqueue_script( 'admin-global' ); |
| 422 | 433 | $this->asset_manager->enqueue_script( 'elementor' ); |
| 423 | 434 | |
| 435 | + $is_v4_atomic = $this->is_elementor_v4_atomic_active(); | |
| 436 | + | |
| 437 | + if ( $is_v4_atomic ) { | |
| 438 | + $this->asset_manager->enqueue_script( 'elementor-v4' ); | |
| 439 | + } | |
| 440 | + | |
| 424 | 441 | $this->asset_manager->localize_script( 'elementor', 'wpseoAdminGlobalL10n', \YoastSEO()->helpers->wincher->get_admin_global_links() ); |
| 425 | 442 | $this->asset_manager->localize_script( 'elementor', 'wpseoAdminL10n', WPSEO_Utils::get_admin_l10n() ); |
| 426 | 443 | $this->asset_manager->localize_script( 'elementor', 'wpseoFeaturesL10n', WPSEO_Utils::retrieve_enabled_features() ); |
| 427 | 444 | |
| @@ -455,11 +472,12 @@ | ||
| 455 | 472 | |
| 456 | 473 | $script_data = [ |
| 457 | 474 | 'metabox' => $this->get_metabox_script_data( $permalink ), |
| 458 | 475 | 'isPost' => true, |
| 459 | - 'isBlockEditor' => WP_Screen::get()->is_block_editor(), | |
| 476 | + 'isBlockEditor' => $this->current_page_helper->is_block_editor(), | |
| 460 | 477 | 'isElementorEditor' => true, |
| 461 | 478 | 'isAlwaysIntroductionV2' => $this->is_elementor_version_compatible_with_introduction_v2(), |
| 479 | + 'isElementorV4Atomic' => $is_v4_atomic, | |
| 462 | 480 | 'postStatus' => \get_post_status( $post_id ), |
| 463 | 481 | 'postType' => \get_post_type( $post_id ), |
| 464 | 482 | 'analysis' => [ |
| 465 | 483 | 'plugins' => $plugins_script_data, |
| @@ -500,8 +518,36 @@ | ||
| 500 | 518 | $version = ( \preg_match( '/^([0-9]+.[0-9]+.[0-9]+)/', \ELEMENTOR_VERSION, $matches ) > 0 ) ? $matches[1] : \ELEMENTOR_VERSION; |
| 501 | 519 | |
| 502 | 520 | // Check if the version is 3.30.0 or higher. This is where the editor v2 was taken out of the experimental into the default state. |
| 503 | 521 | return \version_compare( $version, '3.30.0', '>=' ); |
| 522 | + } | |
| 523 | + | |
| 524 | + /** | |
| 525 | + * Checks whether Elementor V4 (the atomic editor) is currently active on this site. | |
| 526 | + * | |
| 527 | + * Mirrors Elementor's own atomic check (`Atomic_Widgets\OptIn\Opt_In::EXPERIMENT_NAME`): | |
| 528 | + * the `e_opt_in_v4` experiment is the authoritative signal for the atomic editor and is | |
| 529 | + * only registered on Elementor versions that ship it, so `is_feature_active()` already | |
| 530 | + * returns false on older versions or partial installs. No separate version gate is used: | |
| 531 | + * the experiment is an opt-in to V4 that can be enabled before the major version bump, so | |
| 532 | + * a version comparison would wrongly suppress sites that opt in early. Defensive at each | |
| 533 | + * step so missing Elementor internals never throw. | |
| 534 | + * | |
| 535 | + * @return bool Whether the V4 atomic editor path should be used. | |
| 536 | + */ | |
| 537 | + private function is_elementor_v4_atomic_active(): bool { | |
| 538 | + if ( ! \class_exists( '\Elementor\Plugin' ) ) { | |
| 539 | + return false; | |
| 540 | + } | |
| 541 | + $elementor = ( Plugin::$instance ?? null ); | |
| 542 | + if ( $elementor === null || ! isset( $elementor->experiments ) ) { | |
| 543 | + return false; | |
| 544 | + } | |
| 545 | + if ( ! \method_exists( $elementor->experiments, 'is_feature_active' ) ) { | |
| 546 | + return false; | |
| 547 | + } | |
| 548 | + | |
| 549 | + return (bool) $elementor->experiments->is_feature_active( 'e_opt_in_v4' ); | |
| 504 | 550 | } |
| 505 | 551 | |
| 506 | 552 | /** |
| 507 | 553 | * Renders the metabox hidden fields. |