Skip to content

Commit e849e47

Browse files
authored
Merge pull request #2 from BeAPI/errors_get_contents_check
Errors get contents check
2 parents 491ad54 + f7a4669 commit e849e47

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

bea-silo.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/*
33
Plugin Name: BEA - Silo
4-
Version: 1.1.3
4+
Version: 1.1.4
55
Version Boilerplate: 2.1.0
66
Plugin URI: http://www.beapi.fr
77
Description: Add silo feature
@@ -12,7 +12,7 @@
1212
Network: True
1313
----
1414
15-
Copyright 2017 BE API Technical team ([email protected])
15+
Copyright 2018 BE API Technical team ([email protected])
1616
1717
This program is free software; you can redistribute it and/or modify
1818
it under the terms of the GNU General Public License as published by
@@ -39,7 +39,7 @@
3939
}
4040

4141
// Plugin constants
42-
define( 'BEA_SILO_VERSION', '1.1.3' );
42+
define( 'BEA_SILO_VERSION', '1.1.4' );
4343
define( 'BEA_SILO_MIN_PHP_VERSION', '5.4' );
4444

4545
// Plugin URL and PATH

classes/rest/controller.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function register_routes() {
1414
register_rest_route( $this->namespace, '/' . $this->rest_base, [
1515
/**
1616
* Get contents
17-
* AJAX check jQuery.ajax( { url :'https://ipsen.beapi.space/wp-json/bea/silo?post_types[]=post&term_id=4', params : { 'post_types' : [ 'post', 'page' ], term_id : 34 }, method : "GET" });
17+
* AJAX check jQuery.ajax( { url :'https://yourdomain.com/wp-json/bea/silo?post_types[]=post&term_id=4', params : { 'post_types' : [ 'post', 'page' ], term_id : 34 }, method : "GET" });
1818
*/
1919
[
2020
'methods' => \WP_REST_Server::READABLE,
@@ -92,7 +92,14 @@ public function get_contents( $request ) {
9292
*/
9393
public function get_contents_check( \WP_REST_Request $request ) {
9494
$term = \WP_Term::get_instance( (int) $request->get_param( 'term_id' ) );
95+
if ( is_wp_error( $term ) ) {
96+
return new \WP_Error( 'rest_error_silo_no_term', __( 'Term is missing.', 'bea-silo' ), [ 'status' => rest_authorization_required_code() ] );
97+
}
98+
9599
$post_types = (array) $request->get_param( 'post_types' );
100+
if ( empty( $post_types ) ) {
101+
return new \WP_Error( 'rest_error_silo_no_post_types', __( 'Post Types are missing.', 'bea-silo' ), [ 'status' => rest_authorization_required_code() ] );
102+
}
96103

97104
if ( ! Main::is_silotable_term( $post_types, $term ) ) {
98105
return new \WP_Error( 'rest_error_silo_content_args', __( 'Given args are not silotable ones.', 'bea-silo' ), [ 'status' => rest_authorization_required_code() ] );

readme.md

+3
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ REST Api route looks like `{ndd}/wp-json/bea/silo?post_types[0]=post&term_id=4`,
214214

215215
# Changelog
216216

217+
## 1.1.4 - 12 Nov 2018
218+
* Add errors on function get_contents_check
219+
217220
## 1.1.3 - 11 Mar 2018
218221
* Fix items response with childrens
219222

0 commit comments

Comments
 (0)