Disable REST API for a user ROLE

The plugin has a filter drh_allow_rest_api which determines whether the current user has full access and can skip the whitelist check. By default this is just is_user_logged_in(): /** * Allow carte blanche access for logged-in users (or allow override via filter) * * @return bool */ private function allow_rest_api() { return (bool) apply_filters( ‘dra_allow_rest_api’, is_user_logged_in() … Read more

API JSON Data in WordPress

Here is some quick first draft code for populating a dropdown from the Google Font API, I do not know about the options framework so this will not deal with that. 1. Get an API Access Key from Google Your request will need a valid key, you can follow the instruction here on how to … Read more

Add Category Name to REST API

The API responses are designed to only return the IDs. You can then fetch the full information for each term. Of course it would not be very performant to make dozens of requests. So instead, the REST API has the concept of embedding resources. If you make your request, but include _embed=1 in your URL, … Read more

How Do I Add User Custom Field to REST API Response?

I got it. Turns out the tutorial I was looking at was old and I was using the wrong WP function. I was using register_api_field but the correct one to use is register_rest_field. It goes like this… function facebook_add_user_data() { register_rest_field( ‘user’, ‘facebook’, array( ‘get_callback’ => ‘rest_get_user_field’, ‘update_callback’ => null, ‘schema’ => null, ) ); … Read more

Android authentication

The best way to authenticate an app with the REST API would be to use OAuth. There’s a good section on OAuth Authentication the REST API documentation site. You will need to install the OAuth1 plugin on your site as well. There are some gotchas with implementing the OAuth plugin on WordPress. I found this … Read more

How to Use JSON With AJAX?

Usually, you can use the global variable ajaxurl instead of any path using admin-ajax.php. More importantly, the PHP function should echo the response before calling wp_die(). Because you haven’t called wp_die(), AJAX is probably waiting for more from PHP. Hope this helps. P.S. What is that ‘json’ string doing where the AJAX fail() function should … Read more