-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add post classes next to wp-post-block in the editor
- Loading branch information
Showing
2 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,3 +160,23 @@ function register_block_core_post_template() { | |
); | ||
} | ||
add_action( 'init', 'register_block_core_post_template' ); | ||
|
||
/** | ||
* Adds the post classes to the REST API response. | ||
* | ||
* @since 6.6.0? | ||
*/ | ||
function gutenberg_add_post_class_to_api( $data, $post, $context ) { | ||
Check failure on line 169 in packages/block-library/src/post-template/index.php GitHub Actions / PHP coding standards
Check failure on line 169 in packages/block-library/src/post-template/index.php GitHub Actions / PHP coding standards
|
||
$data->data['post_class'] = get_post_class( '', $post->ID ); | ||
|
||
return $data; | ||
} | ||
|
||
function gutenberg_add_post_class_to_all_post_types() { | ||
Check failure on line 175 in packages/block-library/src/post-template/index.php GitHub Actions / PHP coding standards
Check failure on line 175 in packages/block-library/src/post-template/index.php GitHub Actions / PHP coding standards
Check failure on line 175 in packages/block-library/src/post-template/index.php GitHub Actions / PHP coding standards
|
||
$post_types = get_post_types( array( 'public' => true ), 'names' ); | ||
|
||
foreach ( $post_types as $post_type ) { | ||
add_filter( "rest_prepare_{$post_type}", 'gutenberg_add_post_class_to_api', 10, 3 ); | ||
} | ||
} | ||
add_action( 'rest_api_init', 'gutenberg_add_post_class_to_all_post_types' ); |