Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add website information to the script data in Elementor #21463

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions admin/metabox/class-metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,7 @@ public function enqueue() {
'isWooCommerceActive' => $woocommerce_active,
'woocommerceUpsell' => get_post_type( $post_id ) === 'product' && ! $woocommerce_seo_active && $woocommerce_active,
];

/**
* The website information repository.
*
Expand All @@ -936,6 +937,7 @@ public function enqueue() {
$site_information = $repo->get_post_site_information();
$site_information->set_permalink( $this->get_permalink() );
$script_data = array_merge_recursive( $site_information->get_legacy_site_information(), $script_data );

if ( post_type_supports( get_post_type(), 'thumbnail' ) ) {
$asset_manager->enqueue_style( 'featured-image' );

Expand Down
67 changes: 39 additions & 28 deletions src/integrations/third-party/elementor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
use WPSEO_Replace_Vars;
use WPSEO_Shortlinker;
use WPSEO_Utils;
use Yoast\WP\SEO\Actions\Alert_Dismissal_Action;
use Yoast\WP\SEO\Conditionals\Third_Party\Elementor_Edit_Conditional;
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
use Yoast\WP\SEO\Editors\Application\Site\Website_Information_Repository;
use Yoast\WP\SEO\Helpers\Capability_Helper;
use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Integrations\Integration_Interface;
use Yoast\WP\SEO\Introductions\Infrastructure\Wistia_Embed_Permission_Repository;
use Yoast\WP\SEO\Presenters\Admin\Meta_Fields_Presenter;
use Yoast\WP\SEO\Promotions\Application\Promotion_Manager;

Expand Down Expand Up @@ -120,21 +119,18 @@ public static function get_conditionals() {
/**
* Constructor.
*
* @param WPSEO_Admin_Asset_Manager $asset_manager The asset manager.
* @param Options_Helper $options The options helper.
* @param Capability_Helper $capability The capability helper.
* @param Promotion_Manager $promotion_manager The promotion manager.
* @param WPSEO_Admin_Asset_Manager $asset_manager The asset manager.
* @param Options_Helper $options The options helper.
* @param Capability_Helper $capability The capability helper.
*/
public function __construct(
WPSEO_Admin_Asset_Manager $asset_manager,
Options_Helper $options,
Capability_Helper $capability,
Promotion_Manager $promotion_manager
Capability_Helper $capability
) {
$this->asset_manager = $asset_manager;
$this->options = $options;
$this->capability = $capability;
$this->promotion_manager = $promotion_manager;
$this->asset_manager = $asset_manager;
$this->options = $options;
$this->capability = $capability;

$this->seo_analysis = new WPSEO_Metabox_Analysis_SEO();
$this->readability_analysis = new WPSEO_Metabox_Analysis_Readability();
Expand Down Expand Up @@ -454,13 +450,12 @@ public function enqueue() {
'enabled_features' => WPSEO_Utils::retrieve_enabled_features(),
];

$alert_dismissal_action = \YoastSEO()->classes->get( Alert_Dismissal_Action::class );
$dismissed_alerts = $alert_dismissal_action->all_dismissed();
$woocommerce_conditional = new WooCommerce_Conditional();
$permalink = $this->get_permalink();

$script_data = [
'media' => [ 'choose_image' => \__( 'Use Image', 'wordpress-seo' ) ],
'metabox' => $this->get_metabox_script_data(),
'metabox' => $this->get_metabox_script_data( $permalink ),
'userLanguageCode' => WPSEO_Language_Utils::get_language( \get_user_locale() ),
'isPost' => true,
'isBlockEditor' => WP_Screen::get()->is_block_editor(),
Expand All @@ -472,15 +467,20 @@ public function enqueue() {
'plugins' => $plugins_script_data,
'worker' => $worker_script_data,
],
'dismissedAlerts' => $dismissed_alerts,
'webinarIntroElementorUrl' => WPSEO_Shortlinker::get( 'https://yoa.st/webinar-intro-elementor' ),
'currentPromotions' => $this->promotion_manager->get_current_promotions(),
'usedKeywordsNonce' => \wp_create_nonce( 'wpseo-keyword-usage-and-post-types' ),
'linkParams' => WPSEO_Shortlinker::get_query_params(),
'pluginUrl' => \plugins_url( '', \WPSEO_FILE ),
'wistiaEmbedPermission' => \YoastSEO()->classes->get( Wistia_Embed_Permission_Repository::class )->get_value_for_user( \get_current_user_id() ),
];

/**
* The website information repository.
*
* @var $repo Website_Information_Repository
*/
$repo = \YoastSEO()->classes->get( Website_Information_Repository::class );
$site_information = $repo->get_post_site_information();
$site_information->set_permalink( $permalink );
$script_data = \array_merge_recursive( $site_information->get_legacy_site_information(), $script_data );

if ( \post_type_supports( $this->get_metabox_post()->post_type, 'thumbnail' ) ) {
$this->asset_manager->enqueue_style( 'featured-image' );

Expand Down Expand Up @@ -597,16 +597,11 @@ protected function get_metabox_post() {
/**
* Passes variables to js for use with the post-scraper.
*
* @param string $permalink The permalink.
*
* @return array
*/
protected function get_metabox_script_data() {
$permalink = '';

if ( \is_object( $this->get_metabox_post() ) ) {
$permalink = \get_sample_permalink( $this->get_metabox_post()->ID );
$permalink = $permalink[0];
}

protected function get_metabox_script_data( $permalink ) {
$post_formatter = new WPSEO_Metabox_Formatter(
new WPSEO_Post_Metabox_Formatter( $this->get_metabox_post(), [], $permalink )
);
Expand All @@ -624,6 +619,22 @@ protected function get_metabox_script_data() {
return $values;
}

/**
* Gets the permalink.
*
* @return string
*/
protected function get_permalink(): string {
$permalink = '';

if ( \is_object( $this->get_metabox_post() ) ) {
$permalink = \get_sample_permalink( $this->get_metabox_post()->ID );
$permalink = $permalink[0];
}

return $permalink;
}

/**
* Checks whether the highlighting functionality is available for Elementor:
* - in Free it's always available (as an upsell).
Expand Down
Loading