-
Notifications
You must be signed in to change notification settings - Fork 964
Decouple the block editor sidebar from the metabox hidden fields #23324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from 89 commits
6cbc70e
1a5e71a
00961c1
11b670d
2ff66d4
239f5cf
fb6d339
ce731ef
f5d16a9
36c68de
05bf66a
baa7659
209eb6b
6792b23
cad6d57
0b39e94
c2b4258
c82633b
a249ebc
978060b
0f0838a
aa8cfea
4175b9b
8864bd1
8ae6ee6
24d7611
bf32880
5f13afc
e8b1441
b43cded
07fe84d
3596d35
e54569e
ec9b973
c2e6a42
95c6358
2b7341a
89a9d07
cbcc517
5709b39
2c38bf3
7a09e56
5a66346
7f177d0
49e4b67
b86f05e
8664c5b
2e7c2bf
932e493
8513d38
df67c4a
98aaddb
6a58b4e
61f8646
9e17158
ed8ae36
7bb0ff0
b01800a
af0d6d3
0bbfeb3
1936004
f54137b
83ec10e
2b0833f
ca48fec
a22f938
e578764
0741cb3
e08174a
61c2236
b2e2ff1
1039044
626f75e
3edba17
d5f17ca
f34a605
fa49fed
03f3541
2083ee7
afc017b
8c5b1c3
4c008b4
d964ac6
258ccab
93d473a
ad93352
c8044ee
30f19bb
690dc99
c578cef
c6480bf
c47f239
20a0b83
8854e29
af484bc
38e6a9c
799eaad
3ec4daa
81483df
9de6f06
5a6f161
24ae9e6
495db0b
ed540a8
7230c9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Keeping the regular register meta doesn't harm. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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', | ||
|
|
@@ -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', | ||
| ], | ||
| ], | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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', | ||
|
|
@@ -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, | ||
|
|
@@ -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 ); | ||
|
|
@@ -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. | ||
| * | ||
|
|
||
|
FAMarfuaty marked this conversation as resolved.
|
|
FAMarfuaty marked this conversation as resolved.
|
There was a problem hiding this comment.
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.