Skip to content

Commit

Permalink
add new filter on args for register_rest_route
Browse files Browse the repository at this point in the history
  • Loading branch information
asadowski10 committed Jan 24, 2019
1 parent e849e47 commit eae7463
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions bea-silo.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
Plugin Name: BEA - Silo
Version: 1.1.4
Version: 1.1.5
Version Boilerplate: 2.1.0
Plugin URI: http://www.beapi.fr
Description: Add silo feature
Expand Down Expand Up @@ -39,7 +39,7 @@
}

// Plugin constants
define( 'BEA_SILO_VERSION', '1.1.4' );
define( 'BEA_SILO_VERSION', '1.1.5' );
define( 'BEA_SILO_MIN_PHP_VERSION', '5.4' );

// Plugin URL and PATH
Expand Down
27 changes: 14 additions & 13 deletions classes/rest/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ public function register_routes() {
'methods' => \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,
],
] ),
],
] );
}
Expand Down Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit eae7463

Please sign in to comment.