How do I use the WP REST API plugin and the OAuth Server plugin to allow for registration and login?

I know it’s a bit far fetched, but might help. For anyone looking for WP REST API implementation with JWT, here’s our solution. Add it to your function.php add_action(‘rest_api_init’, ‘wp_rest_user_endpoints’); /** * Register a new user * * @param WP_REST_Request $request Full details about the request. * @return array $args. **/ function wp_rest_user_endpoints($request) { /** … Read more

REST API: How can I restrict a custom post type to only be accessible by authenticated users?

Looks like I found a snippet that do exactly that. It’s from Daniel Bachhuber, the API developer. add_filter( ‘rest_authentication_errors’, function( $result ) { if ( ! empty( $result ) ) { return $result; } if ( ! is_user_logged_in() ) { return new WP_Error( ‘restx_logged_out’, ‘Sorry, you must be logged in to make a request.’, array( … Read more

Google Maps not displaying in wordpress using Google Maps Javascript API

I was able to get this working after a bit of fiddling. Give the #map-canvas element a height (you can do this in CSS): <div id=”map-canvas” style=”height:500px”></div> Add the callback argument to the google-maps script URL and add the defer and async attributes to the google-maps script tag. Also make custom-scripts a dependency for google-maps: … Read more

Why is per_page not working with categories in WP API?

Pretty much all the URLs you are using are invalid in some way: http://foobar.com/wp-json/wp/v2/posts/categories_name=hello categories_name is not a valid argument for listing posts, and even if it was you are missing the ? part of the query string. http://foobar.com/wp-json/wp/v2/posts/categories_name=hello?per_page=‌​1 This one is also missing the ?. Query parameters on a URL, which the API uses … Read more

External WordPress API

As of WordPress 4.7 (released December 2016), a REST API is provided out of the box on WordPress. As you’re probably aware, REST APIs are interfaced with by standard HTTP GET and POST requests, so if you have a WordPress 4.7 installation, you can access it at this URL, by plugging this into your browser: … Read more

Use an attachment in multiple posts

When inside of the media uploaded in the post edit screen, just search for your previously attached media and embed it in your new post. The relationship between posts and attachments is preserved in the database. While an attachment can only belong to one post, it can still be embedded in many posts without worry.

REST API for Multisite

I’m using the REST API to pull data about one multisite installation and feed it to sites in another multisite installation. Here’s some of the code in use: class WPSE205354_Demo { function __construct() { add_filter( ‘json_endpoints’, array( $this, ‘register_routes’ ) ); } /** * Register the additional API routes * @param array $routes The routes … Read more