Skip to content
Open
Show file tree
Hide file tree
Changes from 89 commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
6cbc70e
feat: expose all sidebar-editable post meta fields in the REST API
vraja-pro Jun 1, 2026
1a5e71a
feat: add wpseo_disable_metabox_in_block_editor filter to skip hidden…
vraja-pro Jun 1, 2026
00961c1
feat: route Fields helper reads/writes through core/editor when metab…
vraja-pro Jun 1, 2026
11b670d
feat: use core/editor meta for snippet and score reads/writes when me…
vraja-pro Jun 1, 2026
2ff66d4
feat: sync is_cornerstone from core/editor into yoast-seo/editor
vraja-pro Jun 1, 2026
239f5cf
test: fix and extend useYoastMetaSync and initialize tests for setCor…
vraja-pro Jun 1, 2026
fb6d339
refactor: extract meta key strings into camelCase constants to fix ca…
vraja-pro Jun 1, 2026
ce731ef
refactor: move meta-key constants to shared-admin/constants/meta-keys.js
vraja-pro Jun 1, 2026
f5d16a9
refactor: re-export meta-keys from shared-admin/constants index and u…
vraja-pro Jun 1, 2026
36c68de
refactor: replace inline meta key strings with shared-admin constants…
vraja-pro Jun 1, 2026
05bf66a
fix: wrap long useDispatch.mockReturnValue call to satisfy max-len li…
vraja-pro Jun 1, 2026
baa7659
refactor: add schema meta keys to constants file
vraja-pro Jun 1, 2026
209eb6b
fix linting
vraja-pro Jun 1, 2026
6792b23
fix unrelated linting
vraja-pro Jun 1, 2026
cad6d57
Merge branch 'trunk' into 1275-decouple-the-metabox-from-the-block-ed…
vraja-pro Jun 1, 2026
0b39e94
fix: align array double arrows in script_data after adding disableMet…
vraja-pro Jun 1, 2026
c2b4258
feat: skip add_meta_box entirely when wpseo_disable_metabox_in_block_…
vraja-pro Jun 1, 2026
c82633b
fix: support pprimary taxonomy id meta data
vraja-pro Jun 1, 2026
a249ebc
refactor: extract helpers from initializePostAnalysis to fix max-stat…
vraja-pro Jun 1, 2026
978060b
fix: guard editPost dispatches in AnalysisFields until editor is ready
vraja-pro Jun 1, 2026
0f0838a
fix: remove object_subtype restriction from REST meta registration
vraja-pro Jun 2, 2026
aa8cfea
fix: gate render_hidden_fields() behind is_metabox_disabled_in_block_…
vraja-pro Jun 2, 2026
4175b9b
Fix score persistence when metabox is disabled
vraja-pro Jun 2, 2026
8864bd1
refactor: register all REST-exposed meta in a single register_meta call
vraja-pro Jun 2, 2026
8ae6ee6
fix: set single to true in register_meta for all post meta fields
vraja-pro Jun 2, 2026
24d7611
fix: scope save_postdata REST bail to requests without a metabox nonce
vraja-pro Jun 2, 2026
bf32880
revert: restore isLarge prop on ClipboardButton in PrimaryTaxonomyFilter
vraja-pro Jun 2, 2026
5f13afc
fix: queue AnalysisFields meta writes until core/editor is ready
vraja-pro Jun 2, 2026
e8b1441
docs: explain why object_subtype is used in register_primary_term_met…
vraja-pro Jun 2, 2026
b43cded
refactor: extract PrimaryTermFields helper for primary term meta pers…
vraja-pro Jun 2, 2026
07fe84d
refactor: extract shared isRestMetaActive helper to eliminate duplica…
vraja-pro Jun 2, 2026
3596d35
fix php cs
vraja-pro Jun 2, 2026
e54569e
fix: coerce meta values to string in writeOrQueue to pass REST type v…
vraja-pro Jun 2, 2026
ec9b973
fix: reflect advanced settings correctly when metabox is disabled in …
vraja-pro Jun 2, 2026
c2e6a42
refactor: remove scheduleSettingsSync from AdvancedFields
vraja-pro Jun 2, 2026
95c6358
refactor: remove getLoadableSettings and inline reads into loadAdvanc…
vraja-pro Jun 2, 2026
2b7341a
revert: remove is_cornerstone sync from useYoastMetaSync
vraja-pro Jun 2, 2026
89a9d07
test: remove setCornerstoneContent assertions from useYoastMetaSync t…
vraja-pro Jun 2, 2026
cbcc517
cleanup of show_in_rest default
vraja-pro Jun 3, 2026
5709b39
refactor: replace inline disableMetaboxInBlockEditor checks with isRe…
vraja-pro Jun 3, 2026
2c38bf3
fix: defer cornerstone dispatch until core/editor meta is loaded in R…
vraja-pro Jun 3, 2026
7a09e56
fix: prevent duplicate undo entries and score writes from polluting u…
vraja-pro Jun 3, 2026
5a66346
removes comment that is not relevant
vraja-pro Jun 3, 2026
7f177d0
refactor: rename is-rest-meta-active.js to rest-meta.js
vraja-pro Jun 3, 2026
49e4b67
refactor: rename is-rest-meta-active.js to rest-meta.js
vraja-pro Jun 3, 2026
b86f05e
fix: exclude estimated reading time from undo stack and register hidd…
vraja-pro Jun 3, 2026
8664c5b
refactor: extract writeMetaWithoutUndo helper and use it for estimate…
vraja-pro Jun 3, 2026
2e7c2bf
refactor: use lodash get in isRestMetaActive for safe nested property…
vraja-pro Jun 3, 2026
932e493
refactor: extract register_meta as a public static method for addon r…
vraja-pro Jun 3, 2026
8513d38
fix: strip all meta keys with the Yoast prefix from unauthorized REST…
vraja-pro Jun 3, 2026
df67c4a
refactor: isRestMetaActive shouldn't be a function
vraja-pro Jun 3, 2026
98aaddb
refactor: source isRestMetaActive from the preferences store
vraja-pro Jun 4, 2026
6a58b4e
Revert "refactor: source isRestMetaActive from the preferences store"
vraja-pro Jun 4, 2026
61f8646
refactor: pass field_def to register_meta to control REST API visibility
vraja-pro Jun 5, 2026
9e17158
fix: add traversable type hint to register_meta field_def param
vraja-pro Jun 5, 2026
ed8ae36
fix: php cs
vraja-pro Jun 5, 2026
7bb0ff0
fix: remove duplicate field
vraja-pro Jun 12, 2026
b01800a
fix: hide post meta from REST for all post types
vraja-pro Jun 12, 2026
af0d6d3
fix: register primary term meta on init so CPT taxonomies are available
vraja-pro Jun 12, 2026
0bbfeb3
fix: coerce imageId to string before dispatching to REST meta
vraja-pro Jun 12, 2026
1936004
refactor: centralize REST meta read/write into getMetaValue/setMetaVa…
vraja-pro Jun 12, 2026
f54137b
fix: invert setMetaValue undo param to withoutUndo for clearer default
vraja-pro Jun 12, 2026
83ec10e
refactor: move SchemaFields into helpers/fields and use getMetaValue/…
vraja-pro Jun 12, 2026
2b0833f
fix: correct stale @param name in setMetaValue JSDoc
vraja-pro Jun 12, 2026
ca48fec
fix: use isRestMetaActive instead of re-reading wpseoScriptData in po…
vraja-pro Jun 12, 2026
a22f938
fix: remove redundant optional chaining in PrimaryTermFields.getIniti…
vraja-pro Jun 12, 2026
e578764
fix: explain direct filter call and return false in save_postdata bail
vraja-pro Jun 12, 2026
0741cb3
refactor: unexport readMeta and writeMeta as they are internal helpers
vraja-pro Jun 12, 2026
e08174a
fix: correct deprecated version to 28.0 in Estimated_Reading_Time
vraja-pro Jun 12, 2026
61c2236
test: add unit tests for rest-meta helpers and PrimaryTermFields
vraja-pro Jun 12, 2026
b2e2ff1
refactor: use meta key constants in rest-meta tests
vraja-pro Jun 12, 2026
1039044
test: add unit tests for all helpers/fields classes
vraja-pro Jun 12, 2026
626f75e
fix: register primary term meta in fields_index and defaults to fix s…
vraja-pro Jun 12, 2026
3edba17
fix: register estimated reading time field via add_extra_wpseo_meta_f…
vraja-pro Jun 12, 2026
d5f17ca
fix: php cs
vraja-pro Jun 12, 2026
f34a605
Merge branch 'trunk' of github.com:Yoast/wordpress-seo into 1275-deco…
FAMarfuaty Jun 16, 2026
fa49fed
fix: fix saving of advanced settings
vraja-pro Jun 16, 2026
03f3541
fix: move schema defaults and showArticleInput flag to wpseoScriptData
vraja-pro Jun 16, 2026
2083ee7
fix primary term save
vraja-pro Jun 17, 2026
afc017b
fix: tests for helpers fields
vraja-pro Jun 17, 2026
8c5b1c3
fix: separate rest registration and cleanup wpseo meta and added a c…
vraja-pro Jun 17, 2026
4c008b4
fix: defer initial keyphrase load in REST meta mode until entity meta…
vraja-pro Jun 17, 2026
d964ac6
fix: ensure CPTs expose meta in REST API by adding custom-fields support
vraja-pro Jun 17, 2026
258ccab
fix: guard schema_page_type access when get_meta_field_defs returns e…
vraja-pro Jun 17, 2026
93d473a
fix: restore unauthorized REST read filter and fix stale JSDoc
vraja-pro Jun 17, 2026
ad93352
fix: fire wpseo_saved_postdata after REST API post update when metabo…
vraja-pro Jun 17, 2026
c8044ee
tests: add unit tests for Post_Meta_Rest_Fields
vraja-pro Jun 17, 2026
30f19bb
fix: consolidate REST meta boot-time deferral into one subscriber
vraja-pro Jun 17, 2026
690dc99
fix: remove unused this.input assignment in PrimaryTaxonomyPicker
vraja-pro Jun 18, 2026
c578cef
fix: cleanup unused prop
vraja-pro Jun 18, 2026
c6480bf
fix: preserve undoIgnore flag for queued meta writes in AnalysisFields
vraja-pro Jun 18, 2026
c47f239
refactor: route PostDataCollector field access through AnalysisFields…
vraja-pro Jun 18, 2026
20a0b83
tests: add REST meta and pending-write flush coverage for field helpers
vraja-pro Jun 18, 2026
8854e29
refactor: extract initializeSnippetEditorSync to snippet-editor-sync.js
vraja-pro Jun 18, 2026
af484bc
refactor: move snippet-editor-sync from initializers to helpers
vraja-pro Jun 18, 2026
38e6a9c
refactor: extract post-scraper sub-steps into initializers/post-scraper/
vraja-pro Jun 18, 2026
799eaad
tests: drop redundant description REST meta mode tests
vraja-pro Jun 18, 2026
3ec4daa
fix: initializeSnippetEditorSync imports
vraja-pro Jun 18, 2026
81483df
restore refactor
vraja-pro Jun 18, 2026
9de6f06
refactor: inline initializeSnippetEditorSync, extract dispatchInitial…
vraja-pro Jun 18, 2026
5a6f161
restore refactor to avoid scoop creep
vraja-pro Jun 18, 2026
24ae9e6
fix: gate add_post_type_support behind filter and block editor check
vraja-pro Jun 18, 2026
495db0b
fix: add wpseo_edit_advanced_metadata cap check to advanced/schema fi…
vraja-pro Jun 18, 2026
ed540a8
tests: replace unit tests with WP integration tests for Post_Meta_Res…
vraja-pro Jun 19, 2026
7230c9b
fix: removes default value from rest registration
vraja-pro Jun 19, 2026
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
6 changes: 5 additions & 1 deletion admin/formatter/class-metabox-formatter.php

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this change, the default page and article types were added to the hidden input field as attributes (coupled to the hidden fields).

Those values were never sent to be saved in the DB, so it's better to have them in the window object.

Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public function get_values() {
* @return array<string, string|array<string|int|bool>|bool|int> Default settings for the metabox.
*/
private function get_defaults() {
$schema_types = new Schema_Types();
$schema_types = new Schema_Types();
$schema_fields_defs = WPSEO_Meta::get_meta_field_defs( 'schema' );

$defaults = [
'author_name' => get_the_author_meta( 'display_name' ),
Expand All @@ -59,6 +60,9 @@ private function get_defaults() {
'displayFooter' => WPSEO_Capability_Utils::current_user_can( 'wpseo_manage_options' ),
'pageTypeOptions' => $schema_types->get_page_type_options(),
'articleTypeOptions' => $schema_types->get_article_type_options(),
'defaultPageType' => isset( $schema_fields_defs['schema_page_type'] ) ? $schema_fields_defs['schema_page_type']['default'] : '',
'defaultArticleType' => isset( $schema_fields_defs['schema_article_type'] ) ? $schema_fields_defs['schema_article_type']['default'] : '',
'showArticleInput' => isset( $schema_fields_defs['schema_article_type'] ),
],
'twitterCardType' => 'summary_large_image',
/**
Expand Down
67 changes: 56 additions & 11 deletions admin/metabox/class-metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ public function display_metabox( $identifier = null, $type = 'post_type' ) {
* @return void
*/
public function add_meta_box() {
if ( $this->is_metabox_disabled_in_block_editor() ) {
return;
}
Comment thread
vraja-pro marked this conversation as resolved.

$post_types = WPSEO_Post_Type::get_accessible_post_types();
$post_types = array_filter( $post_types, [ $this, 'display_metabox' ] );

Expand Down Expand Up @@ -330,10 +334,38 @@ private function determine_scope() {
* @return void
*/
public function meta_box() {
$this->render_hidden_fields();
if ( ! $this->is_metabox_disabled_in_block_editor() ) {
$this->render_hidden_fields();
}
$this->render_tabs();
}
Comment thread
vraja-pro marked this conversation as resolved.

/**
* Returns whether the metabox hidden fields and $_POST-based save are disabled for the block editor.
*
* When this returns true the block editor uses the REST API meta path instead: all WPSEO post meta
* fields are registered with show_in_rest, so core/editor carries and saves them automatically.
*
* Filter: 'wpseo_disable_metabox_in_block_editor'
*
* @return bool
*/
protected function is_metabox_disabled_in_block_editor() {
$screen = WP_Screen::get();
if ( ! $screen || ! $screen->is_block_editor() ) {
return false;
}

/**
* Filter: 'wpseo_disable_metabox_in_block_editor' - Disables the Yoast metabox hidden fields
* and the $_POST-based save hook in the block editor, so that post meta is saved via the
* WordPress REST API instead (requires all relevant fields to have show_in_rest enabled).
*
* @param bool $disable Whether to disable the metabox. Default false.
*/
return (bool) apply_filters( 'wpseo_disable_metabox_in_block_editor', false );
}

/**
* Renders the metabox hidden fields.
*
Expand Down Expand Up @@ -700,6 +732,18 @@ public function save_postdata( $post_id ) {
return false;
}

// Bail when the REST meta path is active and there is no metabox form submission.
// core/editor persists meta via the REST API, so $_POST will not contain the Yoast
// nonce or hidden-field values. Checking for the nonce absence ensures we only skip
// when there is genuinely no $_POST-based save to process.
// Note: is_metabox_disabled_in_block_editor() cannot be used here because WP_Screen
// is not initialised during REST requests, so the filter is called directly instead.
if ( apply_filters( 'wpseo_disable_metabox_in_block_editor', false )
&& ( defined( 'REST_REQUEST' ) && REST_REQUEST )
&& ! isset( $_POST['yoast_free_metabox_nonce'] ) ) {
return false;
Comment thread
vraja-pro marked this conversation as resolved.
}

if ( $post_id === null ) {
return false;
}
Expand Down Expand Up @@ -904,19 +948,20 @@ public function enqueue() {
$is_front_page = $homepage_is_page && $page_on_front === (int) $post_id;

$script_data = [
'metabox' => $this->get_metabox_script_data(),
'isPost' => true,
'isBlockEditor' => $is_block_editor,
'postId' => $post_id,
'postStatus' => get_post_status( $post_id ),
'postType' => get_post_type( $post_id ),
'isPage' => get_post_type( $post_id ) === 'page',
'usedKeywordsNonce' => wp_create_nonce( 'wpseo-keyword-usage-and-post-types' ),
'analysis' => [
'metabox' => $this->get_metabox_script_data(),
'isPost' => true,
'isBlockEditor' => $is_block_editor,
'disableMetaboxInBlockEditor' => $is_block_editor && (bool) apply_filters( 'wpseo_disable_metabox_in_block_editor', false ),
'postId' => $post_id,
'postStatus' => get_post_status( $post_id ),
'postType' => get_post_type( $post_id ),
'isPage' => get_post_type( $post_id ) === 'page',
'usedKeywordsNonce' => wp_create_nonce( 'wpseo-keyword-usage-and-post-types' ),
'analysis' => [
'plugins' => $plugins_script_data,
'worker' => $worker_script_data,
],
'isFrontPage' => $is_front_page,
'isFrontPage' => $is_front_page,
];

/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"Yoast\\WP\\SEO\\Composer\\Actions::check_coding_standards"
],
"check-cs-thresholds": [
"@putenv YOASTCS_THRESHOLD_ERRORS=2391",
"@putenv YOASTCS_THRESHOLD_ERRORS=2388",
"@putenv YOASTCS_THRESHOLD_WARNINGS=257",
"Yoast\\WP\\SEO\\Composer\\Actions::check_cs_thresholds"
],
Expand Down
61 changes: 0 additions & 61 deletions inc/class-wpseo-meta.php

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the REST registration of the meta data to an initializer class.

  • Separation of concerns
  • Support registration for CPT (registering the fields after the CPT is registered)
  • Easily add tests.

Keeping the regular register meta doesn't harm.

Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,16 @@ class WPSEO_Meta {
'focuskw' => [
'type' => 'hidden',
'title' => '',
'show_in_rest' => true,
'single' => true,
],
'title' => [
'type' => 'hidden',
'default_value' => '',
'show_in_rest' => true,
'single' => true,
],
'metadesc' => [
'type' => 'hidden',
'default_value' => '',
'class' => 'metadesc',
'rows' => 2,
'show_in_rest' => true,
'single' => true,
],
'linkdex' => [
'type' => 'hidden',
Expand Down Expand Up @@ -189,13 +183,6 @@ class WPSEO_Meta {
'options' => Schema_Types::ARTICLE_TYPES,
],
],
/* Fields we should validate & save, but not show on any form. */
'non_form' => [
'linkdex' => [
'type' => null,
'default_value' => '0',
],
],

@vraja-pro vraja-pro Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a duplicate, we already havethat in general.

'content_planner' => [
'is_content_planner_banner_rendered' => [
'type' => 'hidden',
Expand Down Expand Up @@ -287,24 +274,6 @@ public static function init() {
[ 'sanitize_callback' => [ self::class, 'sanitize_post_meta' ] ],
);

// Re-register for the 'post' subtype with REST exposure and auth callback when show_in_rest is enabled.
if ( ! empty( $field_def['show_in_rest'] ) ) {
register_meta(
'post',
self::$meta_prefix . $key,
[
'show_in_rest' => true,
'single' => ( $field_def['single'] ?? false ),
'type' => 'string',
'object_subtype' => 'post',
'sanitize_callback' => [ self::class, 'sanitize_post_meta' ],
'auth_callback' => static function ( $allowed, $meta_key, $object_id ) {
return current_user_can( 'edit_post', $object_id );
},
],
);
}

// Set the $fields_index property for efficiency.
self::$fields_index[ self::$meta_prefix . $key ] = [
'subset' => $subset,
Expand All @@ -323,12 +292,6 @@ public static function init() {
}
unset( $subset, $field_group, $key, $field_def );

// Strip meta fields that have show_in_rest enabled from REST responses for users
// without edit_post capability. register_meta's auth_callback only covers writes,
// so read access must be restricted separately via this filter.
// Register only for 'post' post type. Other post types don't expose these fields.
add_filter( 'rest_prepare_post', [ self::class, 'hide_meta_from_unauthorized_rest_response' ], 10, 2 );

self::filter_schema_article_types();

add_filter( 'update_post_metadata', [ self::class, 'remove_meta_if_default' ], 10, 5 );
Expand Down Expand Up @@ -1074,30 +1037,6 @@ public static function post_types_for_ids( $post_ids ) {
return $post_types;
}

/**
* Strips REST-exposed Yoast meta fields from the response for users without edit_post capability on the post.
*
* @param WP_REST_Response $response The REST response.
* @param WP_Post $post The post object.
*
* @return WP_REST_Response The (possibly modified) response.
*/
public static function hide_meta_from_unauthorized_rest_response( $response, $post ) {
if ( current_user_can( 'edit_post', $post->ID ) ) {
return $response;
}
$data = $response->get_data();
foreach ( self::$meta_fields as $field_group ) {
foreach ( $field_group as $key => $field_def ) {
if ( ! empty( $field_def['show_in_rest'] ) ) {
unset( $data['meta'][ self::$meta_prefix . $key ] );
}
}
}
$response->set_data( $data );
return $response;
}

/**
* Filter the schema article types.
*
Expand Down
2 changes: 1 addition & 1 deletion inc/class-wpseo-primary-term.php
Comment thread
FAMarfuaty marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function get_primary_term() {
* @return void
*/
public function set_primary_term( $new_primary_term ) {
update_post_meta( $this->post_ID, WPSEO_Meta::$meta_prefix . 'primary_' . $this->taxonomy_name, $new_primary_term );
update_post_meta( $this->post_ID, WPSEO_Meta::$meta_prefix . 'primary_' . $this->taxonomy_name, (string) $new_primary_term );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "cd ../.. && wp-scripts build --config config/webpack/webpack.config.js",
"test": "jest",
"lint": "eslint . --max-warnings=40"
"lint": "eslint . --max-warnings=34"
},
"dependencies": {
"@draft-js-plugins/mention": "^5.0.0",
Expand Down
10 changes: 4 additions & 6 deletions packages/js/src/ai-content-planner/hooks/use-apply-outline.js
Comment thread
FAMarfuaty marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback } from "@wordpress/element";
import { useDispatch, select } from "@wordpress/data";
import { metaKeyTitle, metaKeyMetaDesc, metaKeyFocusKw } from "../../shared-admin/constants";
import { buildBlocksFromOutline } from "../helpers/build-blocks-from-outline";
import { CONTENT_PLANNER_STORE } from "../constants";

Expand Down Expand Up @@ -48,12 +49,9 @@ export const useApplyOutline = ( { editedOutlineRef } ) => {
title: metaOutline.title,
blocks: buildBlocksFromOutline( structure ),
meta: {
// eslint-disable-next-line camelcase
_yoast_wpseo_title: metaOutline.title,
// eslint-disable-next-line camelcase
_yoast_wpseo_metadesc: metaOutline.metaDescription,
// eslint-disable-next-line camelcase
_yoast_wpseo_focuskw: metaOutline.focusKeyphrase,
[ metaKeyTitle ]: metaOutline.title,
[ metaKeyMetaDesc ]: metaOutline.metaDescription,
[ metaKeyFocusKw ]: metaOutline.focusKeyphrase,
},
};
if ( metaOutline.category?.id && metaOutline.category.id !== -1 ) {
Expand Down
13 changes: 7 additions & 6 deletions packages/js/src/ai-content-planner/hooks/use-yoast-meta-sync.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useDispatch, useSelect } from "@wordpress/data";
import { useEffect } from "@wordpress/element";
import { metaKeyTitle, metaKeyMetaDesc, metaKeyFocusKw } from "../../shared-admin/constants";

/**
* Mirrors core/editor meta changes into yoast-seo/editor. Fires on every meta change,
Expand All @@ -15,9 +16,9 @@ export function useYoastMetaSync() {
const meta = editor.getEditedPostAttribute( "meta" );
const { title, description } = select( "yoast-seo/editor" ).getSnippetEditorTemplates();
return {
yoastTitle: meta?._yoast_wpseo_title,
yoastMetaDesc: meta?._yoast_wpseo_metadesc,
yoastFocusKw: meta?._yoast_wpseo_focuskw,
yoastTitle: meta?.[ metaKeyTitle ],
yoastMetaDesc: meta?.[ metaKeyMetaDesc ],
yoastFocusKw: meta?.[ metaKeyFocusKw ],
isPost: editor.getCurrentPostType() === "post",
titleTemplate: title,
descTemplate: description,
Expand All @@ -31,9 +32,9 @@ export function useYoastMetaSync() {
if ( ! isPost ) {
return;
}
// Only sync non-empty values. An empty string means no custom value has been saved, in
// which case the snippet editor should keep showing the SEO title template instead of
// being overwritten with an empty string.
// Only sync non-empty values. An empty string means no custom value has been saved,
// in which case the snippet editor should keep showing the SEO title
// template instead of being overwritten with an empty string.
const dataToSync = {
title: titleTemplate,
description: descTemplate,
Expand Down
Loading
Loading