WP_REST_Posts_Controller::prepare_date_response() WordPress Method
The prepare_date_response() method is used to prepare the date response for a post request. This method is used to setup the date response for a WP_REST_Posts_Controller::get_item() request.
WP_REST_Posts_Controller::prepare_date_response( string $date_gmt, string|null $date = null ) #
Checks the post_date_gmt or modified_gmt and prepare any post or modified date for single post output.
Parameters
- $date_gmt
(string)(Required)GMT publication time.
- $date
(string|null)(Optional) Local publication time.
Default value: null
Return
(string|null) ISO8601/RFC3339 formatted datetime.
Source
File: wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
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 );
}
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |