From eae746321d6ef9490439ebc6d064c1ea58c524bc Mon Sep 17 00:00:00 2001 From: Alexandre Sadowski Date: Thu, 24 Jan 2019 17:25:33 +0100 Subject: [PATCH] add new filter on args for register_rest_route --- bea-silo.php | 4 ++-- classes/rest/controller.php | 27 ++++++++++++++------------- readme.md | 3 +++ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/bea-silo.php b/bea-silo.php index c9d3e3d..77498fa 100644 --- a/bea-silo.php +++ b/bea-silo.php @@ -1,7 +1,7 @@ \WP_REST_Server::READABLE, 'callback' => [ $this, 'get_contents' ], 'permission_callback' => [ $this, 'get_contents_check' ], - 'args' => [ - 'post_types' => [ - 'validate_callback' => [ $this, 'is_array' ], - 'sanitize_callback' => [ $this, 'sanitize_array' ], - 'required' => true, - ], - 'term_id' => [ - 'validate_callback' => [ $this, 'is_numeric' ], - 'sanitize_callback' => 'absint', - 'required' => true, - ], - ], + 'args' => + apply_filters( 'bea\silo\register_rest_route\args', [ + 'post_types' => [ + 'validate_callback' => [ $this, 'is_array' ], + 'sanitize_callback' => [ $this, 'sanitize_array' ], + 'required' => true, + ], + 'term_id' => [ + 'validate_callback' => [ $this, 'is_numeric' ], + 'sanitize_callback' => 'absint', + 'required' => true, + ], + ] ), ], ] ); } @@ -65,7 +66,7 @@ public function get_contents( $request ) { * * @author Maxime CULEA */ - $contents = new \WP_Query( apply_filters( 'bea\silo\content\args', $args ) ); + $contents = new \WP_Query( apply_filters( 'bea\silo\content\args', $args, $request ) ); if ( ! $contents->have_posts() ) { new \WP_REST_Response( [ 'code' => 'rest_error_silo_content_empty', diff --git a/readme.md b/readme.md index ac1d19f..ff958e2 100644 --- a/readme.md +++ b/readme.md @@ -214,6 +214,9 @@ REST Api route looks like `{ndd}/wp-json/bea/silo?post_types[0]=post&term_id=4`, # Changelog +#1.1.5 - 24 Janv 2019 +* Add new filter on args for register_rest_route in controller + ## 1.1.4 - 12 Nov 2018 * Add errors on function get_contents_check