apiFetch security

I’m writing some code that updates options using update_option using the REST API and apiFetch. I’m used to doing this using AJAX where I would pass a nonce along in the request to my PHP function, as well as check for current user capabilities. Using the REST API and apiFetch feels much better than using … Read more

Testing custom API endpoint with class dependency

Sorry I feel like really stuck here. I have a plugin introducing a new Rest API controller (WP_REST_Controller) with basically a single endpoint which uses a separate class as a client to fetch some data. Let’s say: #my_plugin.php function register_items_routes() { if ( ! class_exists( ‘WP_REST_My_Controller’ ) ) { require_once __DIR__ . ‘/class-wp-my-controller.php’; } if … Read more

Is there a hook to process a backbone restful PUT request inside wordpress?

I play around with Backbone.js (Great !) and want to synchronize my model data with the wordpress ajax api (3.6.1) on the server-side. Adapted to this http://addyosmani.github.io/backbone-fundamentals/#restful-persistence, here is my backbone example: var new_posts; var post; (function($){ var Post = Backbone.Model.extend({ id: ”, title: ”, }); var Posts = Backbone.Collection.extend({ model: Post, url: APP.ajaxurl + … Read more

Rest API Custom Endpoint with space character

I’m trying to add an endpoint with the following: register_rest_route(‘namespace/v1′,’custom-search/(?P<search>[a-zA-Z\s]+)’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘gm_custom_search_callback’ ) ); It registers the route, but won’t recognise when I add a space character i.e. %20 or pass a string with a ” ” in, I can’t see anywhere that would suggest how this should be achieved, … Read more