Skip to content

Commit 25e4b58

Browse files
author
Salil Kothadia
authored
Merge pull request #24 from elevati/development
override get_items_permissions_check
2 parents e8f3220 + d596a77 commit 25e4b58

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/nbproject

lib/endpoints/class-wp-rest-multiple-posttype-controller.php

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
* @author Ruben Vreeken
1212
* @author Elevati Team
1313
*/
14-
class WP_REST_Multiple_PostType_Controller extends WP_REST_Controller {
14+
class WP_REST_Multiple_PostType_Controller extends WP_REST_Controller
15+
{
1516

16-
public function __construct() {
17+
/**
18+
* Constructor
19+
*/
20+
public function __construct()
21+
{
1722
$this->version = '2';
1823
$this->namespace = 'wp/v' . $this->version;
1924
$this->rest_base = 'multiple-post-type';
@@ -22,7 +27,8 @@ public function __construct() {
2227
/**
2328
* Register the routes for the objects of the controller.
2429
*/
25-
public function register_routes() {
30+
public function register_routes()
31+
{
2632
register_rest_route($this->namespace, '/' . $this->rest_base, array(
2733
array(
2834
'methods' => WP_REST_Server::READABLE,
@@ -36,9 +42,22 @@ public function register_routes() {
3642
/**
3743
* Check if a given request has access to get items
3844
*
39-
* @return bool
45+
* @param WP_REST_Request $request
46+
* @return boolean
47+
*/
48+
public function get_items_permissions_check($request)
49+
{
50+
return true;
51+
}
52+
53+
/**
54+
* Check if a given request has access to get items
55+
*
56+
* @param WP_REST_Request $request
57+
* @return boolean
4058
*/
41-
public function get_items_permissions_check($request) {
59+
public function has_items_permissions_check($request)
60+
{
4261
return true;
4362
}
4463

@@ -48,7 +67,8 @@ public function get_items_permissions_check($request) {
4867
* @param WP_REST_Request $request Full data about the request.
4968
* @return WP_Error|WP_REST_Response
5069
*/
51-
public function get_items($request) {
70+
public function get_items($request)
71+
{
5272
$args = array();
5373
$args['author__in'] = $request['author'];
5474
$args['author__not_in'] = $request['author_exclude'];
@@ -73,14 +93,12 @@ public function get_items($request) {
7393
}
7494

7595
$args['date_query'] = array();
76-
// Set before into date query. Date query must be specified as an array
77-
// of an array.
96+
// Set before into date query. Date query must be specified as an array of an array.
7897
if (isset($request['before'])) {
7998
$args['date_query'][0]['before'] = $request['before'];
8099
}
81100

82-
// Set after into date query. Date query must be specified as an array
83-
// of an array.
101+
// Set after into date query. Date query must be specified as an array of an array.
84102
if (isset($request['after'])) {
85103
$args['date_query'][0]['after'] = $request['after'];
86104
}
@@ -205,8 +223,8 @@ public function get_items($request) {
205223
*
206224
* @return array $query_args
207225
*/
208-
protected function prepare_items_query($prepared_args = array(), $request = null) {
209-
226+
protected function prepare_items_query($prepared_args = array(), $request = null)
227+
{
210228
$valid_vars = array_flip($this->get_allowed_query_vars($request['type']));
211229
$query_args = array();
212230
foreach ($valid_vars as $var => $index) {
@@ -239,11 +257,13 @@ protected function prepare_items_query($prepared_args = array(), $request = null
239257
/**
240258
* Get all the WP Query vars that are allowed for the API request.
241259
*
260+
* @global object $wp
261+
* @param array $post_types
242262
* @return array
243263
*/
244-
protected function get_allowed_query_vars($post_types) {
264+
protected function get_allowed_query_vars($post_types)
265+
{
245266
global $wp;
246-
$editPosts = true;
247267

248268
/**
249269
* Filter the publicly allowed query vars.
@@ -326,7 +346,8 @@ protected function get_allowed_query_vars($post_types) {
326346
*
327347
* @return array
328348
*/
329-
public function get_collection_params() {
349+
public function get_collection_params()
350+
{
330351
$params = parent::get_collection_params();
331352

332353
$params['context']['default'] = 'view';
@@ -467,7 +488,8 @@ public function get_collection_params() {
467488
*
468489
* @return WP_Error|boolean
469490
*/
470-
public function validate_user_can_query_private_statuses($value, $request, $parameter) {
491+
public function validate_user_can_query_private_statuses($value, $request, $parameter)
492+
{
471493
if ('publish' === $value) {
472494
return true;
473495
}

plugin.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
/**
1414
* WP_REST_Multiple_PostType_Controller class.
1515
*/
16-
17-
function init_wp_rest_multiple_posttype_endpoint() {
16+
function init_wp_rest_multiple_posttype_endpoint()
17+
{
1818
if (!class_exists('WP_REST_Multiple_PostType_Controller')) {
1919
require_once dirname(__FILE__) . '/lib/endpoints/class-wp-rest-multiple-posttype-controller.php';
2020
}
@@ -26,4 +26,3 @@ function init_wp_rest_multiple_posttype_endpoint() {
2626
* REST INIT
2727
*/
2828
add_action('rest_api_init', 'init_wp_rest_multiple_posttype_endpoint');
29-

0 commit comments

Comments
 (0)