introduce query filter for REST API

Enabled WP REST API to query for ticker slug, GMT timestamp and limit
parameter as used by AJAX calls. This is done in preparation for
migration to WP REST instead of WP AJAX.
This commit is contained in:
2020-11-10 10:05:51 +01:00
parent af609d8928
commit ca0311622e
6 changed files with 4323 additions and 26 deletions

View File

@ -26,7 +26,7 @@ class SCLiveticker {
*
* @var string OPTIONS
*/
const VERSION = '1.1.1';
const VERSION = '1.2.0';
/**
* Options tag.
@ -71,7 +71,10 @@ class SCLiveticker {
// Load plugin options.
self::update_options();
// Skip on AJAX if not enabled disabled.
// Add filter for REST API queries.
add_filter( 'rest_scliveticker_tick_query', array( 'SCLiveticker\\Api', 'tick_query_filter' ), 10, 2 );
// Skip on AJAX if not enabled.
if ( ( ! isset( self::$options['enable_ajax'] ) || 1 !== self::$options['enable_ajax'] ) && ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
return;
}
@ -300,7 +303,7 @@ class SCLiveticker {
// Extract update requests.
if ( isset( $_POST['update'] ) && is_array( $_POST['update'] ) ) { // Input var okay.
$res = array();
// @codingStandardsIgnoreLine Sanitization of arrayhandled on field level.
// @codingStandardsIgnoreLine Sanitization of array handled on field level.
foreach ( wp_unslash( $_POST['update'] ) as $update_req ) {
if ( is_array( $update_req ) && ( isset( $update_req['s'] ) || isset( $update_req['w'] ) ) ) {
if ( isset( $update_req['s'] ) ) {
@ -310,7 +313,7 @@ class SCLiveticker {
$is_widget = true;
$slug = sanitize_text_field( $update_req['w'] );
} else {
// Should never occur, but for completenes' sake...
// Should never occur, but for completeness' sake...
break;
}