| 1 |
<?php |
| 2 |
/** |
| 3 |
* WordPress 7.1 compatibility functions for the Gutenberg |
| 4 |
* editor plugin changes related to REST API. |
| 5 |
* |
| 6 |
* @package gutenberg |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Registers the View Config REST API routes. |
| 11 |
*/ |
| 12 |
function gutenberg_register_view_config_controller_endpoints() { |
| 13 |
$view_config_controller = new Gutenberg_REST_View_Config_Controller_7_1(); |
| 14 |
$view_config_controller->register_routes(); |
| 15 |
} |
| 16 |
add_action( 'rest_api_init', 'gutenberg_register_view_config_controller_endpoints', PHP_INT_MAX ); |
| 17 |
|
| 18 |
/** |
| 19 |
* Add the `date` value to the `wp_template` schema. |
| 20 |
* |
| 21 |
* @since 7.1.0 Added 'date' property and response value. |
| 22 |
*/ |
| 23 |
function gutenberg_add_date_wp_template_schema() { |
| 24 |
register_rest_field( |
| 25 |
array( 'wp_template', 'wp_template_part' ), |
| 26 |
'date', |
| 27 |
array( |
| 28 |
'schema' => array( |
| 29 |
'description' => __( "The date the template was published, in the site's timezone.", 'gutenberg' ), |
| 30 |
'type' => array( 'string', 'null' ), |
| 31 |
'format' => 'date-time', |
| 32 |
'context' => array( 'view', 'edit' ), |
| 33 |
'readonly' => true, |
| 34 |
), |
| 35 |
'get_callback' => function ( $item ) { |
| 36 |
if ( ! empty( $item['wp_id'] ) ) { |
| 37 |
$post = get_post( $item['wp_id'] ); |
| 38 |
if ( $post && isset( $post->post_date ) ) { |
| 39 |
return mysql_to_rfc3339( $post->post_date ); |
| 40 |
} |
| 41 |
} |
| 42 |
return null; |
| 43 |
}, |
| 44 |
) |
| 45 |
); |
| 46 |
} |
| 47 |
add_filter( 'rest_api_init', 'gutenberg_add_date_wp_template_schema' ); |
| 48 |
|