Skip to content

Commit

Permalink
Merge pull request #2 from BeAPI/errors_get_contents_check
Browse files Browse the repository at this point in the history
Errors get contents check
  • Loading branch information
MaximeCulea authored Nov 13, 2018
2 parents 491ad54 + f7a4669 commit e849e47
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 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.3
Version: 1.1.4
Version Boilerplate: 2.1.0
Plugin URI: http://www.beapi.fr
Description: Add silo feature
Expand All @@ -12,7 +12,7 @@
Network: True
----
Copyright 2017 BE API Technical team ([email protected])
Copyright 2018 BE API Technical team ([email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -39,7 +39,7 @@
}

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

// Plugin URL and PATH
Expand Down
9 changes: 8 additions & 1 deletion classes/rest/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function register_routes() {
register_rest_route( $this->namespace, '/' . $this->rest_base, [
/**
* Get contents
* 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" });
* 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" });
*/
[
'methods' => \WP_REST_Server::READABLE,
Expand Down Expand Up @@ -92,7 +92,14 @@ public function get_contents( $request ) {
*/
public function get_contents_check( \WP_REST_Request $request ) {
$term = \WP_Term::get_instance( (int) $request->get_param( 'term_id' ) );
if ( is_wp_error( $term ) ) {
return new \WP_Error( 'rest_error_silo_no_term', __( 'Term is missing.', 'bea-silo' ), [ 'status' => rest_authorization_required_code() ] );
}

$post_types = (array) $request->get_param( 'post_types' );
if ( empty( $post_types ) ) {
return new \WP_Error( 'rest_error_silo_no_post_types', __( 'Post Types are missing.', 'bea-silo' ), [ 'status' => rest_authorization_required_code() ] );
}

if ( ! Main::is_silotable_term( $post_types, $term ) ) {
return new \WP_Error( 'rest_error_silo_content_args', __( 'Given args are not silotable ones.', 'bea-silo' ), [ 'status' => rest_authorization_required_code() ] );
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.4 - 12 Nov 2018
* Add errors on function get_contents_check

## 1.1.3 - 11 Mar 2018
* Fix items response with childrens

Expand Down

0 comments on commit e849e47

Please sign in to comment.