diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53a5344 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/nbproject diff --git a/lib/endpoints/class-wp-rest-multiple-posttype-controller.php b/lib/endpoints/class-wp-rest-multiple-posttype-controller.php index 6e9afeb..0093441 100644 --- a/lib/endpoints/class-wp-rest-multiple-posttype-controller.php +++ b/lib/endpoints/class-wp-rest-multiple-posttype-controller.php @@ -11,9 +11,14 @@ * @author Ruben Vreeken * @author Elevati Team */ -class WP_REST_Multiple_PostType_Controller extends WP_REST_Controller { +class WP_REST_Multiple_PostType_Controller extends WP_REST_Controller +{ - public function __construct() { + /** + * Constructor + */ + public function __construct() + { $this->version = '2'; $this->namespace = 'wp/v' . $this->version; $this->rest_base = 'multiple-post-type'; @@ -22,7 +27,8 @@ public function __construct() { /** * Register the routes for the objects of the controller. */ - public function register_routes() { + public function register_routes() + { register_rest_route($this->namespace, '/' . $this->rest_base, array( array( 'methods' => WP_REST_Server::READABLE, @@ -36,9 +42,22 @@ public function register_routes() { /** * Check if a given request has access to get items * - * @return bool + * @param WP_REST_Request $request + * @return boolean + */ + public function get_items_permissions_check($request) + { + return true; + } + + /** + * Check if a given request has access to get items + * + * @param WP_REST_Request $request + * @return boolean */ - public function get_items_permissions_check($request) { + public function has_items_permissions_check($request) + { return true; } @@ -48,7 +67,8 @@ public function get_items_permissions_check($request) { * @param WP_REST_Request $request Full data about the request. * @return WP_Error|WP_REST_Response */ - public function get_items($request) { + public function get_items($request) + { $args = array(); $args['author__in'] = $request['author']; $args['author__not_in'] = $request['author_exclude']; @@ -73,14 +93,12 @@ public function get_items($request) { } $args['date_query'] = array(); - // Set before into date query. Date query must be specified as an array - // of an array. + // Set before into date query. Date query must be specified as an array of an array. if (isset($request['before'])) { $args['date_query'][0]['before'] = $request['before']; } - // Set after into date query. Date query must be specified as an array - // of an array. + // Set after into date query. Date query must be specified as an array of an array. if (isset($request['after'])) { $args['date_query'][0]['after'] = $request['after']; } @@ -205,8 +223,8 @@ public function get_items($request) { * * @return array $query_args */ - protected function prepare_items_query($prepared_args = array(), $request = null) { - + protected function prepare_items_query($prepared_args = array(), $request = null) + { $valid_vars = array_flip($this->get_allowed_query_vars($request['type'])); $query_args = array(); foreach ($valid_vars as $var => $index) { @@ -239,11 +257,13 @@ protected function prepare_items_query($prepared_args = array(), $request = null /** * Get all the WP Query vars that are allowed for the API request. * + * @global object $wp + * @param array $post_types * @return array */ - protected function get_allowed_query_vars($post_types) { + protected function get_allowed_query_vars($post_types) + { global $wp; - $editPosts = true; /** * Filter the publicly allowed query vars. @@ -326,7 +346,8 @@ protected function get_allowed_query_vars($post_types) { * * @return array */ - public function get_collection_params() { + public function get_collection_params() + { $params = parent::get_collection_params(); $params['context']['default'] = 'view'; @@ -467,7 +488,8 @@ public function get_collection_params() { * * @return WP_Error|boolean */ - public function validate_user_can_query_private_statuses($value, $request, $parameter) { + public function validate_user_can_query_private_statuses($value, $request, $parameter) + { if ('publish' === $value) { return true; } diff --git a/plugin.php b/plugin.php index 8b875c1..af93e25 100644 --- a/plugin.php +++ b/plugin.php @@ -13,8 +13,8 @@ /** * WP_REST_Multiple_PostType_Controller class. */ - -function init_wp_rest_multiple_posttype_endpoint() { +function init_wp_rest_multiple_posttype_endpoint() +{ if (!class_exists('WP_REST_Multiple_PostType_Controller')) { require_once dirname(__FILE__) . '/lib/endpoints/class-wp-rest-multiple-posttype-controller.php'; } @@ -26,4 +26,3 @@ function init_wp_rest_multiple_posttype_endpoint() { * REST INIT */ add_action('rest_api_init', 'init_wp_rest_multiple_posttype_endpoint'); -