-
-
Save marcosfreitas/027200a9e2e1b28ba93a5b532180d498 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ITTRoutes; | |
use ITTRoutes\HelpersTrait; | |
use ITTRoutes\ContentTrait; | |
use ITTRoutes\CategoryTrait; | |
class ConsumerRoutes extends AbstractRoutes | |
{ | |
use ContentTrait, CategoryTrait; | |
public function __construct() | |
{ | |
parent::__construct(); | |
add_action('rest_api_init', [$this, 'addRestRoute']); | |
add_filter('rest_post_dispatch', [$this, 'removeContentFromRestRequests'], 10, 3); | |
add_filter( 'wp_rest_cache/allowed_endpoints', [$this, 'wprc_add_acf_posts_endpoint'], 10, 1); | |
} | |
public function addRestRoute() | |
{ | |
( some other routes ) | |
register_rest_route( | |
'itt/v1', | |
'/posts/', | |
[ | |
'methods' => 'GET', | |
'callback' => [$this, 'getPostList'] | |
] | |
); | |
} | |
public function getPostList() | |
{ | |
(...) | |
} | |
/** | |
* Filtering WP API response for any post, clearing the content to prevent unathorized access | |
* @version 1.0.1 -fix foreach over empty variable $_data | |
* @param array $rest_response | |
* @param array $rest_server | |
* @param array $rest_request | |
* @return array | |
*/ | |
function removeContentFromRestRequests($rest_response, $rest_server, $rest_request) | |
{ | |
( make some validations... ) | |
return $rest_response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment