All the WordPress AJAX calls should be handled by the admin-ajax.php
, wether they happen on the frontend or in the backend. To grant the access you have to register the callbackfuntion for the AJAX call add those lines to your file:
add_action( 'wp_ajax_prefix_update_post', 'prefix_update_post' );
add_action( 'wp_ajax_nopriv_prefix_update_post', 'prefix_update_post' );
Be sure to add some validation in the prefix_update_post
function, as a non loggedin user should not be allowed to send the draft.
So this line should do the trick:
function prefix_update_post() {
if ( current_user_can( 'edit_post' ) ) {
// your goodies here
}
}
If everything works out fine, perfect, else you may have to send the userID with the AJAX call and check if the User has the correct permissions (get_user_by('id', $userid)
)
Related Posts:
- jQuery Autocomplete in WordPress
- jQuery Autocomplete not working with wp_localize_script
- jQuery UI Autocomplete showing all results
- Issue with front-end ajax, getting a 302 redirect when accessing wp-admin/admin-ajax.php
- Ajax call in wordpress not working for subscriber user in front site
- Ajax Redirect role = ‘Editor’ to their Dashboard after register
- Why is on status span no search results?
- custom autocomplete search
- Auto-suggest to display meta-data, but not to include it upon click
- Adding user using admin ajax by a user with custom role
- Ajax call not working anymore
- Manually cache a special, non-WP-but-using-WP page (e.g. Ajax results) with W3TC
- Front-end ajax problem all users and guests getting a 302 redirect when accessing wp-admin/admin-ajax.php
- jQuery’s .on() method combined with the submit event
- Why use admin-ajax.php and how does it work?
- Why is die() used at the end of function that handles an Ajax request?
- Making my AJAX powered WordPress Crawlable
- WordPress Ajax Data Security
- admin-ajax.php doesn’t work when using POST data and Axios
- Custom Form with Ajax
- How to process ajax requests correctly using ajax plugins
- How is it possible that the function of the test page works, but it does not go live?
- WP REST API route request explain
- Ajax returning correct data BUT at wrong place
- get_posts empty when called via Ajax
- admin-ajax.php mixed content
- WP-API and Basic Auth returning 403 on POST but not GET
- Is there a hook to process a backbone restful PUT request inside wordpress?
- How to localized one js file for different actions?
- How do I check if AJAX nonces are implemented correctly?
- Can I fire an add_action hook inside of a function that recieves data via wp_ajax?
- WordPress Ajax Problems
- Force redirect not logged in user to (wp-login.php or wp-admin) for specific page
- How can I access the Header of and ajax response from the rest API
- Getting back to ajax search results from a page
- Updating a checkbox value to database for specific row in table
- WordPress Ajax Not Working ( Custom Admin page)
- WordPress ajax success response
- Admin WP List Table Columns Missing
- (updated) How to add AJAX error handling to a (fully) custom registration form?
- Load JavaScript from a post that’s loading into Fancybox via ajax
- Gravity form Load By Ajax Cannot Submit – Error 400
- wordpress admin ajax url rename
- rest_no_route custom route
- Using infinite scroll ajax load more with search parameter
- contact form ajax empty response error message
- Cache wp-json/posts without a plugin?
- What is the best way to do MyAjax error and success handling?
- Gravity Forms closes my popup on Validation Error [closed]
- infinite-scroll for 2 fixed height containers
- “Loadmore” button is not working in buddypress [closed]
- Uncaught ReferenceError: the_ajax_script is not defined . How is this not defined?
- infinite scroll not working when logged out
- Right way to include blog-header.php?
- AJAX action through direct link
- Ajax call on new site with jupiterx theme getting 400 response [closed]
- I can’t get a return value from Ajax
- WordPress AJAX return 0 – My case
- Creating an auto result search bar
- update_option is not saving an array, but saving the string ‘Array’
- Ajax call in wordpress not working for subscriber user
- Upload data from weather station to WordPress Website
- Ajax call in WordPress – unable to display the data on the page
- Need help with ajax
- Using nonce when loading posts with AJAX
- What WP-API authentication method should I use to interact with anonymous / not-logged visitors?
- How to call ajax in plugin file
- Get title and featured image using Ajax
- javascript onClick update user_meta from jquery.ajax
- WP_Query is not received in Ajax
- How can i find wrong word in search box and replace with correct word
- My function containing a mysql query launched by ajax is not working in wordpress. What am I missing?
- How do I mitigate replay attacks when talking about actions that shouldn’t happen twice?
- Updating Jquery object with newly created elements after AJAX call
- Wp admin ajax load more
- wordpress ajax search posts
- Ajax call from Plugin using Class
- How to inject data content from external json into a modal, using UIkit?
- Ajax by worpdress affects called jquery inside template file
- AJAX form not working, still reloads on submit
- Call public static method from ajax ‘wpcf7_mail_sent’ hook
- Update user meta via ajax from frontend, saving issue
- How to get the admin page slug using wp_loaded hook?
- Edit user meta on front-end via AJAX
- Having a self updating list
- First time doing Ajax with WP, how to do it?
- Unexpected WordPress search results
- WordPress Get Header and Footer using in Admin Area
- Tie the sending of an ajax request to WordPress hooks
- AJAX: admin-ajax.php is adding extra content to my script’s response – how to exclude header, footer, etc.?
- ajax page template
- apply_filters, EMBEDS and AJAX not a friends? [duplicate]
- Using Javascript Callback from plugin in a theme
- Why does my Ajax Get request give a 400 bad request?
- How to get data with Select AJAX PHP
- Add “load more” functionality to an AJAX response
- Bad Request 400… jQuery ajax post of json data to wordpress admin-ajax.php
- weird Internal Server Error – no error log produced
- Why are the most recent posts not appearing in a fetch request, unless I’m logged in?
- Successful ajax call returns lots of whitespace and text of code with 0