add formatted date to REST response and use RFC3339 for the query
This commit is contained in:
parent
ca0311622e
commit
547fc521d0
@ -20,6 +20,28 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
* @since 1.2
|
* @since 1.2
|
||||||
*/
|
*/
|
||||||
class Api {
|
class Api {
|
||||||
|
/**
|
||||||
|
* Initialize custom fields for REST API responses.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function init() {
|
||||||
|
// Add rendered modification date to WP_Post object.
|
||||||
|
register_rest_field(
|
||||||
|
'scliveticker_tick',
|
||||||
|
'modified_rendered',
|
||||||
|
array(
|
||||||
|
'get_callback' => function ( $post ) {
|
||||||
|
return get_the_modified_date( 'd.m.Y H:i', $post );
|
||||||
|
},
|
||||||
|
'schema' => array(
|
||||||
|
'description' => __( 'Rendered modification date and time.', 'stklcode-liveticker' ),
|
||||||
|
'type' => 'string',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter tick queries by ticker slug and date.
|
* Filter tick queries by ticker slug and date.
|
||||||
*
|
*
|
||||||
@ -32,7 +54,7 @@ class Api {
|
|||||||
// Extract arguments.
|
// Extract arguments.
|
||||||
$ticker_slug = $request->get_param( 'ticker' );
|
$ticker_slug = $request->get_param( 'ticker' );
|
||||||
$limit = intval( $request->get_param( 'limit' ) );
|
$limit = intval( $request->get_param( 'limit' ) );
|
||||||
$last_poll = intval( $request->get_param( 'last' ) );
|
$last_poll = $request->get_param( 'last' );
|
||||||
|
|
||||||
if ( ! empty( $ticker_slug ) ) {
|
if ( ! empty( $ticker_slug ) ) {
|
||||||
$args['tax_query'][] = array(
|
$args['tax_query'][] = array(
|
||||||
@ -42,8 +64,10 @@ class Api {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty( $limit ) ) {
|
if ( ! empty( $limit ) && $limit > 0 ) {
|
||||||
$args['posts_per_page'] = $limit;
|
$args['posts_per_page'] = $limit;
|
||||||
|
} else {
|
||||||
|
$args['paged'] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $last_poll > 0 ) {
|
if ( $last_poll > 0 ) {
|
||||||
@ -51,7 +75,7 @@ class Api {
|
|||||||
',',
|
',',
|
||||||
gmdate(
|
gmdate(
|
||||||
'Y,m,d,H,i,s',
|
'Y,m,d,H,i,s',
|
||||||
$last_poll
|
rest_parse_date( $last_poll )
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ class SCLiveticker {
|
|||||||
self::update_options();
|
self::update_options();
|
||||||
|
|
||||||
// Add filter for REST API queries.
|
// Add filter for REST API queries.
|
||||||
|
add_filter( 'rest_api_init', array( 'SCLiveticker\\Api', 'init' ) );
|
||||||
add_filter( 'rest_scliveticker_tick_query', array( 'SCLiveticker\\Api', 'tick_query_filter' ), 10, 2 );
|
add_filter( 'rest_scliveticker_tick_query', array( 'SCLiveticker\\Api', 'tick_query_filter' ), 10, 2 );
|
||||||
|
|
||||||
// Skip on AJAX if not enabled.
|
// Skip on AJAX if not enabled.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user