• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / 8ad612e0d07e81871206f56a097e212b74325549

07 Oct 2025 07:19AM UTC coverage: 53.67% (+0.9%) from 52.782%
8ad612e0d07e81871206f56a097e212b74325549

Pull #22245

github

web-flow
Merge 9c9c87348 into b095d7ef1
Pull Request #22245: Remove the translation loading.

7852 of 13939 branches covered (56.33%)

Branch coverage included in aggregate %.

30868 of 58205 relevant lines covered (53.03%)

41005.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/integrations/third-party/elementor.php
1
<?php
2

3
namespace Yoast\WP\SEO\Integrations\Third_Party;
4

5
use WP_Post;
6
use WP_Screen;
7
use WPSEO_Admin_Asset_Manager;
8
use WPSEO_Admin_Recommended_Replace_Vars;
9
use WPSEO_Meta;
10
use WPSEO_Metabox_Analysis_Inclusive_Language;
11
use WPSEO_Metabox_Analysis_Readability;
12
use WPSEO_Metabox_Analysis_SEO;
13
use WPSEO_Metabox_Formatter;
14
use WPSEO_Post_Metabox_Formatter;
15
use WPSEO_Replace_Vars;
16
use WPSEO_Utils;
17
use Yoast\WP\SEO\Conditionals\Third_Party\Elementor_Edit_Conditional;
18
use Yoast\WP\SEO\Editors\Application\Site\Website_Information_Repository;
19
use Yoast\WP\SEO\Elementor\Infrastructure\Request_Post;
20
use Yoast\WP\SEO\Helpers\Capability_Helper;
21
use Yoast\WP\SEO\Helpers\Options_Helper;
22
use Yoast\WP\SEO\Integrations\Integration_Interface;
23
use Yoast\WP\SEO\Presenters\Admin\Meta_Fields_Presenter;
24
use Yoast\WP\SEO\Promotions\Application\Promotion_Manager;
25

26
/**
27
 * Integrates the Yoast SEO metabox in the Elementor editor.
28
 */
29
class Elementor implements Integration_Interface {
30

31
        /**
32
         * Represents the post.
33
         *
34
         * @var WP_Post|null
35
         */
36
        protected $post;
37

38
        /**
39
         * Represents the admin asset manager.
40
         *
41
         * @var WPSEO_Admin_Asset_Manager
42
         */
43
        protected $asset_manager;
44

45
        /**
46
         * Represents the options helper.
47
         *
48
         * @var Options_Helper
49
         */
50
        protected $options;
51

52
        /**
53
         * Represents the capability helper.
54
         *
55
         * @var Capability_Helper
56
         */
57
        protected $capability;
58

59
        /**
60
         * Holds the Request_Post.
61
         *
62
         * @var Request_Post
63
         */
64
        private $request_post;
65

66
        /**
67
         * Holds whether the socials are enabled.
68
         *
69
         * @var bool
70
         */
71
        protected $social_is_enabled;
72

73
        /**
74
         * Holds whether the advanced settings are enabled.
75
         *
76
         * @var bool
77
         */
78
        protected $is_advanced_metadata_enabled;
79

80
        /**
81
         * Helper to determine whether or not the SEO analysis is enabled.
82
         *
83
         * @var WPSEO_Metabox_Analysis_SEO
84
         */
85
        protected $seo_analysis;
86

87
        /**
88
         * Helper to determine whether or not the readability analysis is enabled.
89
         *
90
         * @var WPSEO_Metabox_Analysis_Readability
91
         */
92
        protected $readability_analysis;
93

94
        /**
95
         * Helper to determine whether or not the inclusive language analysis is enabled.
96
         *
97
         * @var WPSEO_Metabox_Analysis_Inclusive_Language
98
         */
99
        protected $inclusive_language_analysis;
100

101
        /**
102
         * Holds the promotion manager.
103
         *
104
         * @var Promotion_Manager
105
         */
106
        protected $promotion_manager;
107

108
        /**
109
         * Returns the conditionals based in which this loadable should be active.
110
         *
111
         * @return array
112
         */
113
        public static function get_conditionals() {
×
114
                return [ Elementor_Edit_Conditional::class ];
×
115
        }
116

117
        /**
118
         * Constructor.
119
         *
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.
124
         */
125
        public function __construct(
×
126
                WPSEO_Admin_Asset_Manager $asset_manager,
127
                Options_Helper $options,
128
                Capability_Helper $capability,
129
                Request_Post $request_post
130
        ) {
131
                $this->asset_manager = $asset_manager;
×
132
                $this->options       = $options;
×
133
                $this->capability    = $capability;
×
134
                $this->request_post  = $request_post;
×
135

136
                $this->seo_analysis                 = new WPSEO_Metabox_Analysis_SEO();
×
137
                $this->readability_analysis         = new WPSEO_Metabox_Analysis_Readability();
×
138
                $this->inclusive_language_analysis  = new WPSEO_Metabox_Analysis_Inclusive_Language();
×
139
                $this->social_is_enabled            = $this->options->get( 'opengraph', false ) || $this->options->get( 'twitter', false );
×
140
                $this->is_advanced_metadata_enabled = $this->capability->current_user_can( 'wpseo_edit_advanced_metadata' ) || $this->options->get( 'disableadvanced_meta' ) === false;
×
141
        }
142

143
        /**
144
         * Initializes the integration.
145
         *
146
         * This is the place to register hooks and filters.
147
         *
148
         * @return void
149
         */
150
        public function register_hooks() {
×
151
                \add_action( 'wp_ajax_wpseo_elementor_save', [ $this, 'save_postdata' ] );
×
152

153
                // We need to delay the post type lookup to give other plugins a chance to register custom post types.
154
                \add_action( 'init', [ $this, 'register_elementor_hooks' ], \PHP_INT_MAX );
×
155
        }
156

157
        /**
158
         * Registers our Elementor hooks.
159
         * This is done for pages with metabox on page load and not on ajax request.
160
         *
161
         * @return void
162
         */
163
        public function register_elementor_hooks() {
×
164
                if ( $this->get_metabox_post() === null || ! $this->display_metabox( $this->get_metabox_post()->post_type ) ) {
×
165
                        return;
×
166
                }
167

168
                \add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'init' ] );
×
169
        }
170

171
        /**
172
         * Initializes the integration.
173
         *
174
         * @return void
175
         */
176
        public function init() {
×
177
                $this->asset_manager->register_assets();
×
178
                $this->enqueue();
×
179
                $this->render_hidden_fields();
×
180
        }
181

182
        // Below is mostly copied from `class-metabox.php`. That constructor has side-effects we do not need.
183

184
        /**
185
         * Determines whether the metabox should be shown for the passed identifier.
186
         *
187
         * By default, the check is done for post types, but can also be used for taxonomies.
188
         *
189
         * @param string|null $identifier The identifier to check.
190
         * @param string      $type       The type of object to check. Defaults to post_type.
191
         *
192
         * @return bool Whether the metabox should be displayed.
193
         */
194
        public function display_metabox( $identifier = null, $type = 'post_type' ) {
×
195
                return WPSEO_Utils::is_metabox_active( $identifier, $type );
×
196
        }
197

198
        /**
199
         * Saves the WP SEO metadata for posts.
200
         *
201
         * Outputs JSON via wp_send_json then stops code execution.
202
         *
203
         * {@internal $_POST parameters are validated via sanitize_post_meta().}}
204
         *
205
         * @return void
206
         */
207
        public function save_postdata() {
×
208
                global $post;
×
209

210
                if ( ! isset( $_POST['post_id'] ) || ! \is_string( $_POST['post_id'] ) ) {
×
211
                        \wp_send_json_error( 'Bad Request', 400 );
×
212
                }
213

214
                // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: No sanitization needed because we cast to an integer.
215
                $post_id = (int) \wp_unslash( $_POST['post_id'] );
×
216

217
                if ( $post_id <= 0 ) {
×
218
                        \wp_send_json_error( 'Bad Request', 400 );
×
219
                }
220

221
                if ( ! \current_user_can( 'edit_post', $post_id ) ) {
×
222
                        \wp_send_json_error( 'Forbidden', 403 );
×
223
                }
224

225
                \check_ajax_referer( 'wpseo_elementor_save', '_wpseo_elementor_nonce' );
×
226

227
                // Bail if this is a multisite installation and the site has been switched.
228
                if ( \is_multisite() && \ms_is_switched() ) {
×
229
                        \wp_send_json_error( 'Switched multisite', 409 );
×
230
                }
231

232
                \clean_post_cache( $post_id );
×
233
                // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- To setup the post we need to do this explicitly.
234
                $post = \get_post( $post_id );
×
235

236
                if ( ! \is_object( $post ) ) {
×
237
                        // Non-existent post.
238
                        \wp_send_json_error( 'Post not found', 400 );
×
239
                }
240

241
                \do_action( 'wpseo_save_compare_data', $post );
×
242

243
                // Initialize meta, amongst other things it registers sanitization.
244
                WPSEO_Meta::init();
×
245

246
                $social_fields = [];
×
247
                if ( $this->social_is_enabled ) {
×
248
                        $social_fields = WPSEO_Meta::get_meta_field_defs( 'social', $post->post_type );
×
249
                }
250

251
                // The below methods use the global post so make sure it is setup.
252
                \setup_postdata( $post );
×
253
                $meta_boxes = \apply_filters( 'wpseo_save_metaboxes', [] );
×
254
                $meta_boxes = \array_merge(
×
255
                        $meta_boxes,
×
256
                        WPSEO_Meta::get_meta_field_defs( 'general', $post->post_type ),
×
257
                        WPSEO_Meta::get_meta_field_defs( 'advanced', $post->post_type ),
×
258
                        $social_fields,
×
259
                        WPSEO_Meta::get_meta_field_defs( 'schema', $post->post_type )
×
260
                );
×
261

262
                foreach ( $meta_boxes as $key => $meta_box ) {
×
263
                        // If analysis is disabled remove that analysis score value from the DB.
264
                        if ( $this->is_meta_value_disabled( $key ) ) {
×
265
                                WPSEO_Meta::delete( $key, $post_id );
×
266
                                continue;
×
267
                        }
268

269
                        $data       = null;
×
270
                        $field_name = WPSEO_Meta::$form_prefix . $key;
×
271

272
                        if ( $meta_box['type'] === 'checkbox' ) {
×
273
                                $data = isset( $_POST[ $field_name ] ) ? 'on' : 'off';
×
274
                        }
275
                        else {
276
                                if ( isset( $_POST[ $field_name ] ) ) {
×
277
                                        // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: Sanitized through sanitize_post_meta.
278
                                        $data = \wp_unslash( $_POST[ $field_name ] );
×
279

280
                                        // For multi-select.
281
                                        if ( \is_array( $data ) ) {
×
282
                                                $data = \array_map( [ 'WPSEO_Utils', 'sanitize_text_field' ], $data );
×
283
                                        }
284

285
                                        if ( \is_string( $data ) ) {
×
286
                                                $data = ( $key !== 'canonical' ) ? WPSEO_Utils::sanitize_text_field( $data ) : WPSEO_Utils::sanitize_url( $data );
×
287
                                        }
288
                                }
289

290
                                // Reset options when no entry is present with multiselect - only applies to `meta-robots-adv` currently.
291
                                if ( ! isset( $_POST[ $field_name ] ) && ( $meta_box['type'] === 'multiselect' ) ) {
×
292
                                        $data = [];
×
293
                                }
294
                        }
295

296
                        if ( $data !== null ) {
×
297
                                WPSEO_Meta::set_value( $key, $data, $post_id );
×
298
                        }
299
                }
300

301
                if ( isset( $_POST[ WPSEO_Meta::$form_prefix . 'slug' ] ) && \is_string( $_POST[ WPSEO_Meta::$form_prefix . 'slug' ] ) ) {
×
302
                        $slug = \sanitize_title( \wp_unslash( $_POST[ WPSEO_Meta::$form_prefix . 'slug' ] ) );
×
303
                        if ( $post->post_name !== $slug ) {
×
304
                                $post_array              = $post->to_array();
×
305
                                $post_array['post_name'] = $slug;
×
306

307
                                $save_successful = \wp_insert_post( $post_array );
×
308
                                if ( \is_wp_error( $save_successful ) ) {
×
309
                                        \wp_send_json_error( 'Slug not saved', 400 );
×
310
                                }
311

312
                                // Update the post object to ensure we have the actual slug.
313
                                // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Updating the post is needed to get the current slug.
314
                                $post = \get_post( $post_id );
×
315
                                if ( ! \is_object( $post ) ) {
×
316
                                        \wp_send_json_error( 'Updated slug not found', 400 );
×
317
                                }
318
                        }
319
                }
320

321
                \do_action( 'wpseo_saved_postdata' );
×
322

323
                // Output the slug, because it is processed by WP and we need the actual slug again.
324
                \wp_send_json_success( [ 'slug' => $post->post_name ] );
×
325
        }
326

327
        /**
328
         * Determines if the given meta value key is disabled.
329
         *
330
         * @param string $key The key of the meta value.
331
         *
332
         * @return bool Whether the given meta value key is disabled.
333
         */
334
        public function is_meta_value_disabled( $key ) {
×
335
                if ( $key === 'linkdex' && ! $this->seo_analysis->is_enabled() ) {
×
336
                        return true;
×
337
                }
338

339
                if ( $key === 'content_score' && ! $this->readability_analysis->is_enabled() ) {
×
340
                        return true;
×
341
                }
342

343
                if ( $key === 'inclusive_language_score' && ! $this->inclusive_language_analysis->is_enabled() ) {
×
344
                        return true;
×
345
                }
346

347
                return false;
×
348
        }
349

350
        /**
351
         * Enqueues all the needed JS and CSS.
352
         *
353
         * @return void
354
         */
355
        public function enqueue() {
×
356
                $post_id = \get_queried_object_id();
×
357
                if ( empty( $post_id ) ) {
×
358
                        $post_id = 0;
×
359
                        // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are not processing form information.
360
                        if ( isset( $_GET['post'] ) && \is_string( $_GET['post'] ) ) {
×
361
                                // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.NonceVerification.Recommended -- Reason: No sanitization needed because we cast to an integer,We are not processing form information.
362
                                $post_id = (int) \wp_unslash( $_GET['post'] );
×
363
                        }
364
                }
365

366
                if ( $post_id !== 0 ) {
×
367
                        // Enqueue files needed for upload functionality.
368
                        \wp_enqueue_media( [ 'post' => $post_id ] );
×
369
                }
370

371
                $this->asset_manager->enqueue_style( 'admin-global' );
×
372
                $this->asset_manager->enqueue_style( 'metabox-css' );
×
373
                if ( $this->readability_analysis->is_enabled() ) {
×
374
                        $this->asset_manager->enqueue_style( 'scoring' );
×
375
                }
376
                $this->asset_manager->enqueue_style( 'monorepo' );
×
377
                $this->asset_manager->enqueue_style( 'admin-css' );
×
378
                $this->asset_manager->enqueue_style( 'ai-generator' );
×
379
                $this->asset_manager->enqueue_style( 'elementor' );
×
380

381
                $this->asset_manager->enqueue_script( 'admin-global' );
×
382
                $this->asset_manager->enqueue_script( 'elementor' );
×
383

384
                $this->asset_manager->localize_script( 'elementor', 'wpseoAdminGlobalL10n', \YoastSEO()->helpers->wincher->get_admin_global_links() );
×
385
                $this->asset_manager->localize_script( 'elementor', 'wpseoAdminL10n', WPSEO_Utils::get_admin_l10n() );
×
386
                $this->asset_manager->localize_script( 'elementor', 'wpseoFeaturesL10n', WPSEO_Utils::retrieve_enabled_features() );
×
387

388
                $plugins_script_data = [
×
389
                        'replaceVars' => [
×
390
                                'replace_vars'             => $this->get_replace_vars(),
×
391
                                'recommended_replace_vars' => $this->get_recommended_replace_vars(),
×
392
                                'hidden_replace_vars'      => $this->get_hidden_replace_vars(),
×
393
                                'scope'                    => $this->determine_scope(),
×
394
                                'has_taxonomies'           => $this->current_post_type_has_taxonomies(),
×
395
                        ],
×
396
                        'shortcodes'  => [
×
397
                                'wpseo_shortcode_tags'          => $this->get_valid_shortcode_tags(),
×
398
                                'wpseo_filter_shortcodes_nonce' => \wp_create_nonce( 'wpseo-filter-shortcodes' ),
×
399
                        ],
×
400
                ];
×
401

402
                $worker_script_data = [
×
403
                        'url'                     => \YoastSEO()->helpers->asset->get_asset_url( 'yoast-seo-analysis-worker' ),
×
404
                        'dependencies'            => \YoastSEO()->helpers->asset->get_dependency_urls_by_handle( 'yoast-seo-analysis-worker' ),
×
405
                        'keywords_assessment_url' => \YoastSEO()->helpers->asset->get_asset_url( 'yoast-seo-used-keywords-assessment' ),
×
406
                        'log_level'               => WPSEO_Utils::get_analysis_worker_log_level(),
×
407
                        // We need to make the feature flags separately available inside of the analysis web worker.
408
                        'enabled_features'        => WPSEO_Utils::retrieve_enabled_features(),
×
409
                ];
×
410

411
                $permalink        = $this->get_permalink();
×
412
                $page_on_front    = (int) \get_option( 'page_on_front' );
×
413
                $homepage_is_page = \get_option( 'show_on_front' ) === 'page';
×
414
                $is_front_page    = $homepage_is_page && $page_on_front === $post_id;
×
415

416
                $script_data = [
×
417
                        'metabox'                   => $this->get_metabox_script_data( $permalink ),
×
418
                        'isPost'                    => true,
×
419
                        'isBlockEditor'             => WP_Screen::get()->is_block_editor(),
×
420
                        'isElementorEditor'         => true,
×
421
                        'isAlwaysIntroductionV2'    => $this->is_elementor_version_compatible_with_introduction_v2(),
×
422
                        'postStatus'                => \get_post_status( $post_id ),
×
423
                        'postType'                  => \get_post_type( $post_id ),
×
424
                        'analysis'                  => [
×
425
                                'plugins' => $plugins_script_data,
×
426
                                'worker'  => $worker_script_data,
×
427
                        ],
×
428
                        'usedKeywordsNonce'         => \wp_create_nonce( 'wpseo-keyword-usage-and-post-types' ),
×
429
                        'isFrontPage'               => $is_front_page,
×
430
                ];
×
431

432
                /**
433
                 * The website information repository.
434
                 *
435
                 * @var Website_Information_Repository $repo
436
                 */
437
                $repo             = \YoastSEO()->classes->get( Website_Information_Repository::class );
×
438
                $site_information = $repo->get_post_site_information();
×
439
                $site_information->set_permalink( $permalink );
×
440
                $script_data = \array_merge_recursive( $site_information->get_legacy_site_information(), $script_data );
×
441

442
                $this->asset_manager->localize_script( 'elementor', 'wpseoScriptData', $script_data );
×
443
        }
444

445
        /**
446
         * Checks whether the current Elementor version is compatible with our introduction v2.
447
         *
448
         * In version 3.30.0, Elementor removed the experimental flag for the editor v2.
449
         * Resulting in the editor v2 being the default.
450
         *
451
         * @return bool Whether the Elementor version is compatible with introduction v2.
452
         */
453
        private function is_elementor_version_compatible_with_introduction_v2(): bool {
×
454
                if ( ! \defined( 'ELEMENTOR_VERSION' ) ) {
×
455
                        return false;
×
456
                }
457

458
                // Take the semver version from their version string.
459
                $matches = [];
×
460
                $version = ( \preg_match( '/^([0-9]+.[0-9]+.[0-9]+)/', \ELEMENTOR_VERSION, $matches ) > 0 ) ? $matches[1] : \ELEMENTOR_VERSION;
×
461

462
                // 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.
463
                return \version_compare( $version, '3.30.0', '>=' );
×
464
        }
465

466
        /**
467
         * Renders the metabox hidden fields.
468
         *
469
         * @return void
470
         */
471
        protected function render_hidden_fields() {
×
472
                // Wrap in a form with an action and post_id for the submit.
473
                \printf(
×
474
                        '<form id="yoast-form" method="post" action="%1$s"><input type="hidden" name="action" value="wpseo_elementor_save" /><input type="hidden" id="post_ID" name="post_id" value="%2$s" />',
×
475
                        \esc_url( \admin_url( 'admin-ajax.php' ) ),
×
476
                        \esc_attr( $this->get_metabox_post()->ID )
×
477
                );
×
478

479
                \wp_nonce_field( 'wpseo_elementor_save', '_wpseo_elementor_nonce' );
×
480
                // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: Meta_Fields_Presenter->present is considered safe.
481
                echo new Meta_Fields_Presenter( $this->get_metabox_post(), 'general' );
×
482

483
                if ( $this->is_advanced_metadata_enabled ) {
×
484
                        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: Meta_Fields_Presenter->present is considered safe.
485
                        echo new Meta_Fields_Presenter( $this->get_metabox_post(), 'advanced' );
×
486
                }
487

488
                // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: Meta_Fields_Presenter->present is considered safe.
489
                echo new Meta_Fields_Presenter( $this->get_metabox_post(), 'schema', $this->get_metabox_post()->post_type );
×
490

491
                if ( $this->social_is_enabled ) {
×
492
                        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: Meta_Fields_Presenter->present is considered safe.
493
                        echo new Meta_Fields_Presenter( $this->get_metabox_post(), 'social' );
×
494
                }
495

496
                \printf(
×
497
                        '<input type="hidden" id="%1$s" name="%1$s" value="%2$s" />',
×
498
                        \esc_attr( WPSEO_Meta::$form_prefix . 'slug' ),
×
499
                        /**
500
                         * It is important that this slug value is the same as in the database.
501
                         * If the DB value is empty we can auto-generate a slug.
502
                         * But if not empty, we should not touch it anymore.
503
                         */
504
                        \esc_attr( $this->get_metabox_post()->post_name )
×
505
                );
×
506

507
                // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output should be escaped in the filter.
508
                echo \apply_filters( 'wpseo_elementor_hidden_fields', '' );
×
509

510
                echo '</form>';
×
511
        }
512

513
        /**
514
         * Returns post in metabox context.
515
         *
516
         * @return WP_Post|null
517
         */
518
        protected function get_metabox_post() {
×
519
                if ( $this->post !== null ) {
×
520
                        return $this->post;
×
521
                }
522

523
                $this->post = $this->request_post->get_post();
×
524

525
                return $this->post;
×
526
        }
527

528
        /**
529
         * Passes variables to js for use with the post-scraper.
530
         *
531
         * @param string $permalink The permalink.
532
         *
533
         * @return array
534
         */
535
        protected function get_metabox_script_data( $permalink ) {
×
536
                $post_formatter = new WPSEO_Metabox_Formatter(
×
537
                        new WPSEO_Post_Metabox_Formatter( $this->get_metabox_post(), [], $permalink )
×
538
                );
×
539

540
                $values = $post_formatter->get_values();
×
541

542
                /** This filter is documented in admin/filters/class-cornerstone-filter.php. */
543
                $post_types = \apply_filters( 'wpseo_cornerstone_post_types', \YoastSEO()->helpers->post_type->get_accessible_post_types() );
×
544
                if ( $values['cornerstoneActive'] && ! \in_array( $this->get_metabox_post()->post_type, $post_types, true ) ) {
×
545
                        $values['cornerstoneActive'] = false;
×
546
                }
547

548
                $values['elementorMarkerStatus'] = $this->is_highlighting_available() ? 'enabled' : 'hidden';
×
549

550
                return $values;
×
551
        }
552

553
        /**
554
         * Gets the permalink.
555
         *
556
         * @return string
557
         */
558
        protected function get_permalink(): string {
×
559
                $permalink = '';
×
560

561
                if ( \is_object( $this->get_metabox_post() ) ) {
×
562
                        $permalink = \get_sample_permalink( $this->get_metabox_post()->ID );
×
563
                        $permalink = $permalink[0];
×
564
                }
565

566
                return $permalink;
×
567
        }
568

569
        /**
570
         * Checks whether the highlighting functionality is available for Elementor:
571
         * - in Free it's always available (as an upsell).
572
         * - in Premium it's available as long as the version is 21.8-RC0 or above.
573
         *
574
         * @return bool Whether the highlighting functionality is available.
575
         */
576
        private function is_highlighting_available() {
×
577
                $is_premium      = \YoastSEO()->helpers->product->is_premium();
×
578
                $premium_version = \YoastSEO()->helpers->product->get_premium_version();
×
579

580
                return ! $is_premium || \version_compare( $premium_version, '21.8-RC0', '>=' );
×
581
        }
582

583
        /**
584
         * Prepares the replace vars for localization.
585
         *
586
         * @return array Replace vars.
587
         */
588
        protected function get_replace_vars() {
×
589
                $cached_replacement_vars = [];
×
590

591
                $vars_to_cache = [
×
592
                        'date',
×
593
                        'id',
×
594
                        'sitename',
×
595
                        'sitedesc',
×
596
                        'sep',
×
597
                        'page',
×
598
                        'currentyear',
×
599
                        'currentdate',
×
600
                        'currentmonth',
×
601
                        'currentday',
×
602
                        'tag',
×
603
                        'category',
×
604
                        'category_title',
×
605
                        'primary_category',
×
606
                        'pt_single',
×
607
                        'pt_plural',
×
608
                        'modified',
×
609
                        'name',
×
610
                        'user_description',
×
611
                        'pagetotal',
×
612
                        'pagenumber',
×
613
                        'post_year',
×
614
                        'post_month',
×
615
                        'post_day',
×
616
                        'author_first_name',
×
617
                        'author_last_name',
×
618
                        'permalink',
×
619
                        'post_content',
×
620
                ];
×
621

622
                foreach ( $vars_to_cache as $var ) {
×
623
                        $cached_replacement_vars[ $var ] = \wpseo_replace_vars( '%%' . $var . '%%', $this->get_metabox_post() );
×
624
                }
625

626
                // Merge custom replace variables with the WordPress ones.
627
                return \array_merge( $cached_replacement_vars, $this->get_custom_replace_vars( $this->get_metabox_post() ) );
×
628
        }
629

630
        /**
631
         * Prepares the recommended replace vars for localization.
632
         *
633
         * @return array Recommended replacement variables.
634
         */
635
        protected function get_recommended_replace_vars() {
×
636
                $recommended_replace_vars = new WPSEO_Admin_Recommended_Replace_Vars();
×
637

638
                // What is recommended depends on the current context.
639
                $post_type = $recommended_replace_vars->determine_for_post( $this->get_metabox_post() );
×
640

641
                return $recommended_replace_vars->get_recommended_replacevars_for( $post_type );
×
642
        }
643

644
        /**
645
         * Returns the list of replace vars that should be hidden inside the editor.
646
         *
647
         * @return string[] The hidden replace vars.
648
         */
649
        protected function get_hidden_replace_vars() {
×
650
                return ( new WPSEO_Replace_Vars() )->get_hidden_replace_vars();
×
651
        }
652

653
        /**
654
         * Gets the custom replace variables for custom taxonomies and fields.
655
         *
656
         * @param WP_Post $post The post to check for custom taxonomies and fields.
657
         *
658
         * @return array Array containing all the replacement variables.
659
         */
660
        protected function get_custom_replace_vars( $post ) {
×
661
                return [
×
662
                        'custom_fields'     => $this->get_custom_fields_replace_vars( $post ),
×
663
                        'custom_taxonomies' => $this->get_custom_taxonomies_replace_vars( $post ),
×
664
                ];
×
665
        }
666

667
        /**
668
         * Gets the custom replace variables for custom taxonomies.
669
         *
670
         * @param WP_Post $post The post to check for custom taxonomies.
671
         *
672
         * @return array Array containing all the replacement variables.
673
         */
674
        protected function get_custom_taxonomies_replace_vars( $post ) {
×
675
                $taxonomies          = \get_object_taxonomies( $post, 'objects' );
×
676
                $custom_replace_vars = [];
×
677

678
                foreach ( $taxonomies as $taxonomy_name => $taxonomy ) {
×
679

680
                        if ( \is_string( $taxonomy ) ) { // If attachment, see https://core.trac.wordpress.org/ticket/37368 .
×
681
                                $taxonomy_name = $taxonomy;
×
682
                                $taxonomy      = \get_taxonomy( $taxonomy_name );
×
683
                        }
684

685
                        if ( $taxonomy->_builtin && $taxonomy->public ) {
×
686
                                continue;
×
687
                        }
688

689
                        $custom_replace_vars[ $taxonomy_name ] = [
×
690
                                'name'        => $taxonomy->name,
×
691
                                'description' => $taxonomy->description,
×
692
                        ];
×
693
                }
694

695
                return $custom_replace_vars;
×
696
        }
697

698
        /**
699
         * Gets the custom replace variables for custom fields.
700
         *
701
         * @param WP_Post $post The post to check for custom fields.
702
         *
703
         * @return array Array containing all the replacement variables.
704
         */
705
        protected function get_custom_fields_replace_vars( $post ) {
×
706
                $custom_replace_vars = [];
×
707

708
                // If no post object is passed, return the empty custom_replace_vars array.
709
                if ( ! \is_object( $post ) ) {
×
710
                        return $custom_replace_vars;
×
711
                }
712

713
                $custom_fields = \get_post_custom( $post->ID );
×
714

715
                // Simply concatenate all fields containing replace vars so we can handle them all with a single regex find.
716
                $replace_vars_fields = \implode(
×
717
                        ' ',
×
718
                        [
×
719
                                \YoastSEO()->meta->for_post( $post->ID )->presentation->title,
×
720
                                \YoastSEO()->meta->for_post( $post->ID )->presentation->meta_description,
×
721
                        ]
×
722
                );
×
723

724
                \preg_match_all( '/%%cf_([A-Za-z0-9_]+)%%/', $replace_vars_fields, $matches );
×
725
                $fields_to_include = $matches[1];
×
726
                foreach ( $custom_fields as $custom_field_name => $custom_field ) {
×
727
                        // Skip private custom fields.
728
                        if ( \substr( $custom_field_name, 0, 1 ) === '_' ) {
×
729
                                continue;
×
730
                        }
731

732
                        // Skip custom fields that are not used, new ones will be fetched dynamically.
733
                        if ( ! \in_array( $custom_field_name, $fields_to_include, true ) ) {
×
734
                                continue;
×
735
                        }
736

737
                        // Skip custom field values that are serialized.
738
                        if ( \is_serialized( $custom_field[0] ) ) {
×
739
                                continue;
×
740
                        }
741

742
                        $custom_replace_vars[ $custom_field_name ] = $custom_field[0];
×
743
                }
744

745
                return $custom_replace_vars;
×
746
        }
747

748
        /**
749
         * Determines the scope based on the post type.
750
         * This can be used by the replacevar plugin to determine if a replacement needs to be executed.
751
         *
752
         * @return string String describing the current scope.
753
         */
754
        protected function determine_scope() {
×
755
                if ( $this->get_metabox_post()->post_type === 'page' ) {
×
756
                        return 'page';
×
757
                }
758

759
                return 'post';
×
760
        }
761

762
        /**
763
         * Determines whether or not the current post type has registered taxonomies.
764
         *
765
         * @return bool Whether the current post type has taxonomies.
766
         */
767
        protected function current_post_type_has_taxonomies() {
×
768
                $post_taxonomies = \get_object_taxonomies( $this->get_metabox_post()->post_type );
×
769

770
                return ! empty( $post_taxonomies );
×
771
        }
772

773
        /**
774
         * Returns an array with shortcode tags for all registered shortcodes.
775
         *
776
         * @return array
777
         */
778
        protected function get_valid_shortcode_tags() {
×
779
                $shortcode_tags = [];
×
780

781
                foreach ( $GLOBALS['shortcode_tags'] as $tag => $description ) {
×
782
                        $shortcode_tags[] = $tag;
×
783
                }
784

785
                return $shortcode_tags;
×
786
        }
787
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc