-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Output post classes in the editor #6716
Changes from all commits
9ba5965
e6bb75c
c3f58eb
8986cbb
4b07732
a4aef1d
0b6dc03
4a7051f
c393ade
4b97352
3124c09
0657411
715274a
baf2b50
48c74a2
5586415
d24ee39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1998,6 +1998,10 @@ public function prepare_item_for_response( $item, $request ) { | |
$data['generated_slug'] = $sample_permalink[1]; | ||
} | ||
} | ||
|
||
if ( rest_is_field_included( 'class_list', $fields ) ) { | ||
$data['class_list'] = get_post_class( array(), $post->ID ); | ||
} | ||
} | ||
|
||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view'; | ||
|
@@ -2353,6 +2357,16 @@ public function get_item_schema() { | |
'context' => array( 'edit' ), | ||
'readonly' => true, | ||
); | ||
|
||
$schema['properties']['class_list'] = array( | ||
'description' => __( 'An array of the class names for the post container element.' ), | ||
'type' => 'array', | ||
'context' => array( 'view', 'edit' ), | ||
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'm not sure about the context. 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. Yeah The 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. Thank you for the information. It's indeed very helpful in understanding when to use the embed context. |
||
'readonly' => true, | ||
'items' => array( | ||
'type' => 'string', | ||
), | ||
); | ||
} | ||
|
||
if ( $post_type_obj->hierarchical ) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -759,17 +759,23 @@ private function normalize_fixture( $data, $path ) { | |
return $data; | ||
} | ||
|
||
$datetime_keys = array( 'date', 'date_gmt', 'modified', 'modified_gmt' ); | ||
|
||
foreach ( $data as $key => $value ) { | ||
if ( is_string( $value ) && ( | ||
'date' === $key || | ||
'date_gmt' === $key || | ||
'modified' === $key || | ||
'modified_gmt' === $key | ||
) ) { | ||
$data[ $key ] = '2017-02-14T00:00:00'; | ||
} else { | ||
$data[ $key ] = $this->normalize_fixture( $value, "$path.$key" ); | ||
if ( is_string( $value ) ) { | ||
if ( in_array( $key, $datetime_keys, true ) ) { | ||
$data[ $key ] = '2017-02-14T00:00:00'; | ||
continue; | ||
} | ||
|
||
if ( 1 === preg_match( '/^post-\d+$/', $value ) ) { | ||
// Normalize the class value to ensure test stability. | ||
$data[ $key ] = 'post-1073'; | ||
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. What is this? Why is this hardcoded? Is it for test stability? Might be good to comment. 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. Yes, it's to ensure test stability. Fixed in d24ee39. 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've discovered an improved method for adding these fixture replacements. While the current implementation works, the approach detailed here offers a better solution: WordPress Core Ticket #61369. This isn't urgent since the current setup functions adequately for mocking the REST API. However, it would be great if someone could review the new approach when they have time. |
||
continue; | ||
} | ||
} | ||
|
||
$data[ $key ] = $this->normalize_fixture( $value, "$path.$key" ); | ||
} | ||
|
||
return $data; | ||
|
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.
We should add a
readonly
keyword.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.
Good catch. Fixed in e4c1641
Thanks.