In WP REST API v2 use the permission_callback found in the Adding Custom Endpoints Docs.
<?php
add_action( 'rest_api_init', function () {
register_rest_route( 'myplugin/v2', '/author/(?P<id>\d+)', array(
'methods' => 'GET',
'callback' => 'my_awesome_func',
'args' => array(
'id' => array(
'validate_callback' => 'is_numeric'
),
),
'permission_callback' => function (WP_REST_Request $request) {
if ( current_user_can( 'edit_others_posts' ) ) {
return true;
}
else {
return false;
}
}
) );
} );
Related Posts:
- WP-API and Basic Auth returning 403 on POST but not GET
- Ajax for non-logged-in users
- Extending wp JavaScript base class to make a post request to a custom REST endpoint
- wp-admin AJAX with Fetch API is done without user
- How to add WP API and JS featured image attachment
- how to send Ajax request in wordpress backend
- Why a strange discrepency between get_current_user_id() when using AJAX versus output of document.cookie?
- SSO autologin WordPress + Ajax
- post values to custom post type which has advanced custom fields
- Should I edit a user meta field with PUT, PATCH, or POST and WP::Editable
- Usage of wp_send_json_success and wp_redirect at the same time
- How to submit a button automatically after every scheduled hours?
- How to cache json with wp-super cache
- Why might a plugin’s ‘do_shortcode’ not work in an AJAX request?
- Get Previous & Next posts by Post ID
- Nonces and Cache
- REST API endpoint for elasticpress autosuggest
- ajax – why multiple calls to wp_create_nonce() return same value?
- AJAX request on the frontend always returns 0 if user is not admin
- Admin Notification after save_post, when ajax saving in gutenberg
- Using ajax on categories and wordpress loops
- Cannot load admin-ajax.php. No access-control allow origin*
- Initialize JS with an ajax loaded ACF form
- WordPress Nonce Issue for Ajax Login and Logout
- Nonces and Ajax request to REST API and verification
- Vue.js + AJAX Shortcode
- Can’t seem to get wp_localize_script to work
- wp_ajax action is not running
- Can we access the REST request parameters from within the permission_callback to enforce a 401 by returning false?
- Ajax – gettext without a plugin
- WordPress AJAX calls not detecting language properly?
- AJAX issue – Uncaught SyntaxError when processing Zip File
- wp_verify_nonce doesn’t return true on server when it matches the nonce
- update_user_meta doesn’t work with AJAX
- How do I set the url to make an ajax request for a html document?
- Using wp_handle_upload and media_handle_sideload with ajax
- Populating content dynamically via AJAX and Advanced Custom Fields [closed]
- Load ajax if is_home()
- How to know what page is calling admin-ajax.php?
- Populate a Map at The Same Time as showing Posts via AJAX
- wp_localize_script not working on ajax response
- Why Does WordPress not output admin-ajax.php path by default?
- Jetpack Infinite Scroll – Add more than 7 posts each time?
- Test WordPress api with postman
- How to handle 400 status in Ajax [duplicate]
- How to process wordpress ajax call without action parameter?
- Update attachment metadata fails
- Nonce fails on ajax save
- WordPress P2 live problem
- All AJAX requests return a 400 error
- Unable to successfully verify nonce
- Create custom POST Method URL
- Getting a variable using $post ajax back from php to js response in WP
- AJAX Call – Failed to load resource: the server responded with a status of 500 (Internal Server Error)
- WordPress is Not Setting PHP $_POST on Custom Ajax
- bulk update meta value with ajax
- Ajax for subscibers not working
- javascript ajax and nonce
- Is it possible to determine whether a page is a page template by page_id in ajax call?
- Chained ajax call, second call returns 0
- PHP session when called wp_ajax_nopriv
- What exactly does ‘authenticated’ mean for wp_ajax_nopriv?
- How to make image in TinyMCE clickable
- How to use Jeditable plugin with admin-ajax.php?
- WordPress Ajax Not Firing
- Get uploaded attachment width & height and attachment ID after upload them
- Uncaught TypeError: Cannot read properties of undefined (reading ‘message’) [closed]
- Disabling ajax code that does a POST request that ends in a 400 error code
- Refresh checkout fields on add to cart with order bump
- Is it good practice to use REST API in wp-admin plugin page? [closed]
- How to prevent my external API call from being called by anyone but me (my site)
- get a bad request 400 on my ajax-admin.php file
- Registration form AJAX check for existing username (simple version)
- How to check Ajax request only when i opened the Notifications list?
- Trigger action via button
- Syntax error on query_vars while handling with Jquery
- Want to send ajax request in wordpress to a custom file in plugin
- How to send the checkbox value to email
- Class called in template, AJAX not registering
- Sending email with wp_email and AJAX
- AJAX Call in Plugin Returns More than JSON
- Ajax take too long to return code
- problem when adding wp_editor with ajax [duplicate]
- Get wp-load.php PATH with wp_localize_script and JavaScript for plugin
- Ajax Form seems to post, but does not return
- Ajax request to admin-ajax.php and window.location.href
- Objects and get_post_meta() gives me 1 string for latitude and longitude
- Why can wordpress not find the actions I add in my constructor?
- delete attachment for one post without deleting actual attachment post
- Memberpress isn’t cooperating with WooCommerce
- where does my function output from load-* go?
- WordPress ajax requst returns zero
- wp_editor() in content that was loaded with ajax [duplicate]
- WordPress blocking polling request when signed into Admin
- Send button using own contact form [closed]
- Translating wordpress foreach to ajax
- AJAX loading with custom parameters
- Adding custom fields to Wired Impact Volunteer Management Plugin
- How to update my jquery/PHP function to add/remove user as favorites in (WordPress) users list
- randomly get 400 error while user is logged in wp_ajax