On this page
WP_REST_Posts_Controller::prepare_date_response( string $date_gmt, string|null $date = null ): string|null
Checks the post_date_gmt or modified_gmt and prepare any post or modified date for single post output.
Parameters
$date_gmtstring Required-
GMT publication time.
$datestring|null Optional-
Local publication time.
Default:
null
Return
string|null ISO8601/RFC3339 formatted datetime.
Source
File: wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php. View all references
protected function prepare_date_response( $date_gmt, $date = null ) {
// Use the date if passed.
if ( isset( $date ) ) {
return mysql_to_rfc3339( $date );
}
// Return null if $date_gmt is empty/zeros.
if ( '0000-00-00 00:00:00' === $date_gmt ) {
return null;
}
// Return the formatted datetime.
return mysql_to_rfc3339( $date_gmt );
}
Related
Uses
| Uses | Description |
|---|---|
| mysql_to_rfc3339() wp-includes/functions.php | Parses and formats a MySQL datetime (Y-m-d H:i:s) for ISO8601 (Y-m-d\TH:i:s). |
Used By
| Used By | Description |
|---|---|
| WP_REST_Posts_Controller::prepare_item_for_response() wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Prepares a single post output for response. |
Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/prepare_date_response