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

Yoast / wordpress-seo / 24655ded9bf78d673e7fb7784bf1fbea2b4d3cbc

21 May 2025 02:35PM UTC coverage: 53.028% (-0.007%) from 53.035%
24655ded9bf78d673e7fb7784bf1fbea2b4d3cbc

push

github

web-flow
Merge pull request #22293 from Yoast/2304-252---yoast-notification-is-out-of-place-in-upcoming-version-of-elementor-editor

Add Elementor version check to determine the introduction version

8175 of 14232 branches covered (57.44%)

Branch coverage included in aggregate %.

0 of 8 new or added lines in 2 files covered. (0.0%)

1 existing line in 1 file now uncovered.

29618 of 57038 relevant lines covered (51.93%)

41858.08 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
                $this->asset_manager->enqueue_style( 'scoring' );
×
374
                $this->asset_manager->enqueue_style( 'monorepo' );
×
375
                $this->asset_manager->enqueue_style( 'admin-css' );
×
376
                $this->asset_manager->enqueue_style( 'ai-generator' );
×
377
                $this->asset_manager->enqueue_style( 'elementor' );
×
378

379
                $this->asset_manager->enqueue_script( 'admin-global' );
×
380
                $this->asset_manager->enqueue_script( 'elementor' );
×
381

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

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

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

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

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

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

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

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

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

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

465
        /**
466
         * Renders the metabox hidden fields.
467
         *
468
         * @return void
469
         */
470
        protected function render_hidden_fields() {
×
471
                // Wrap in a form with an action and post_id for the submit.
472
                \printf(
×
473
                        '<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" />',
×
474
                        \esc_url( \admin_url( 'admin-ajax.php' ) ),
×
475
                        \esc_attr( $this->get_metabox_post()->ID )
×
476
                );
×
477

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

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

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

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

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

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

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

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

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

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

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

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

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

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

549
                return $values;
×
550
        }
551

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

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

565
                return $permalink;
×
566
        }
567

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

694
                return $custom_replace_vars;
×
695
        }
696

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

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

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

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

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

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

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

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

744
                return $custom_replace_vars;
×
745
        }
746

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

758
                return 'post';
×
759
        }
760

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

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

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

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

784
                return $shortcode_tags;
×
785
        }
786
}
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