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( 'status' => 401 ) );
}
return $result;
});
This is posted in his gist on GitHub.
Related Posts:
- With Rest V2 (WP4.7) how does one restrict certain RESTFUL verbs?
- Fetch All Posts (Including Those Using a Custom Post Type) With WordPress API
- How to assign specific users the capability to edit specific pages / posts / custom post types
- Show custom post type endpoint in REST API just if user has capability
- Allow Users Access to Custom Post Type Only
- Custom post type capabilities require “create_posts” to access the edit posts list page
- How do I get the intended post type of a revision post?
- How to restrict CPT post’s fronted view only for specific user roles?
- Exclude objects from WordPress API based from ACF field using rest_prepare_{$post_type}
- Custom REST endpoint not working to retrieve single posts (“rest_no_route”)
- How to handle this specific case of custom post type?
- How can I remove “Add new” button on custom post type
- Post current post type to my Ajax
- Custom post type submenu capabilities – custom plugin
- re-register custom post type with custom capabilities
- Organize WordPress site, so it can maintain with huge database
- Pros and cons of a custom page vs custom post type template file
- Creating tags via API
- How to add/edit advanced custom fields on custom post type’s WordPress REST API?
- WordPress custom post type capabilities issue
- How to get all post of custom post type by rest api?
- Create custom post with meta field with AJAX and the WordPress REST API
- WordPress API for custom post types returns rest_no_route
- CRUD operations in wordpress
- Conflict between Capabilities and Menu Visibility with Custom Post Types
- Make (custom) post type accessible only by custom query
- Adding guestbook to my wordpress site
- Building Forums with Custom Post Types
- Role capabilities issue
- Api rest_route 404 while building filter for custom posts (filtered by multiple meta keys / custom fields)
- set_query_params using custom params defined in functions file?
- WordPress: Custom User Role cannot access Custom Post Type | “Sorry, you are not allowed to access this page”
- How to see posts in taxonomy endpoint
- Select other roles as custom post authors
- WP API Response does not show my registered metadata
- REST filters only firing when I have a param set
- WordPress custom API endpoint – how to make the request more flexible
- How to add a filter to a custom post type to get adjacent custom posts via the REST API
- How to handle new post from API request?
- Capabilities not working with custom post type
- wp-json API: not logged in when clicking link to the API from admin mode
- WordPress as a backend for external service? [closed]
- Restrict category access to specific users/groups. Author always has access
- Custom Post Type API doesn’t show taxonomy or category array
- Custom Post Type – after disable ‘Add New’, I can’t edit and delete post
- Wp custom post custom capability not working together
- Accessing a protected property of a post
- Custom capabilities not reflecting on admin panel
- Custom permalink structure for remote content pages
- Admin: Get all user for Custom Role
- Custom Post Type not working with Capabilities
- Post/Custom Post Type URL Access
- Roles and Capabilities in Custom Post Types
- custom post type capabilities – needs to be VERY secure
- Use Gravity Forms and a Shopping Cart for output to Freshbooks for an Estimate [closed]
- How to make an API call to a custom post type but filtering by meta value?
- Fetching custom post type without knowing post type (REST API)
- How to fix the Post Preview Button (CPT & map_meta_cap)
- Restrict Custom Post Type per role in Dashboard
- WordPress REST API V2: “{CUSTOM_POST_TYPE} matches Term ID List and Term ID Taxonomy Query, but should match only one.”
- Restrict access to custom post type based on its taxonomy terms
- no_rest_route in Unit Testing for REST endpoint for CPT registered via show_in_rest
- How can I create new CustomPostType record using wp.api.collections?
- Custom endpoint filtering post by custom taxonomies
- Restrict access only of custom post type with standard capabilities to edit_post
- wp rest api orderby field in a custom table
- Sync posts via JSON API
- Why “Mine” is the default view when adding ‘capability_type’ in register_post_type
- How To Read Read Custom Post Type Data in Headless CMS Mode
- CPT requires manage_options and edit_posts for some reason
- WP_Query: how to search tags in addition to a custom post type?
- How can I sort the results of a REST API response by the title of a connected custom post type?
- How to filter a matched value with custom key using WP REST API?
- URL issue retrieving Custom Post Types using Backbone JS API
- How to only display all posts to a custom User Role?
- How to add field to custom post type endpoint
- Create API’s for custom-post types & custom queries using REST or Graphql
- Action on Custom Post publish
- Use a template for a specific url slug without creating a page
- How to Grab Anime info using Jikan API and fill the value in Metabox
- Get Custom Post types data from the API
- Remove plugin settings from post creation page for a user role
- How to display “META” array in register_taxonomy
- How can I add a meta[] to my custom post type and search by term with the Rest API?
- Allowing custom role user to edit post assigned to them but don’t let them create new custom type post
- Can’t see post status drop down for custom post type
- register_rest_field update_callback don’t work for $_FILES
- Custom Post Type Capabilities Singular/Plural
- localize_script or rest api
- Issue with CPT posts within WP REST API showing as []
- Populating Custom Fields from live JSON
- Multiple useres editing specified content
- Saving custom post types post_meta over REST-API fails
- WP REST API Custom endpoint don’t work in my plugin
- WooThemes – Vendors / Bookings – Allow Vendors to manage resources
- filter rest api post by a acf filed
- How do you make a custom post type invisible for subscribers
- How to properly set a value to meta fields of a custom post type in WP-API/node-wpapi REST API?
- WordPress API only returning HTML
- How to create new permission for custom post types for doing specific tasks