Skip to content

Commit

Permalink
REST API: Add post class list field.
Browse files Browse the repository at this point in the history
See WordPress/gutenberg#60642.
See WordPress/wordpress-develop#6716.

Fixes #61360.

Props antonvlasenko, timothyblynjacobs, ellatrix, oandregal.


Built from https://develop.svn.wordpress.org/trunk@58326


git-svn-id: https://core.svn.wordpress.org/trunk@57783 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
ellatrix committed Jun 4, 2024
1 parent 2810bb4 commit 4d2349e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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' ),
'readonly' => true,
'items' => array(
'type' => 'string',
),
);
}

if ( $post_type_obj->hierarchical ) {
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.6-alpha-58325';
$wp_version = '6.6-alpha-58326';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit 4d2349e

Please sign in to comment.