wp_ajax_delete_post() WordPress Function
wp_ajax_delete_post() is a function that allows you to delete a post via an AJAX call. This is useful for when you want to delete a post without having to reload the page.
wp_ajax_delete_post( string $action ) #
Ajax handler for deleting a post.
Parameters
- $action
(string)(Required)Action to perform.
Source
File: wp-admin/includes/ajax-actions.php
function wp_ajax_delete_post( $action ) { if ( empty( $action ) ) { $action = 'delete-post'; } $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; check_ajax_referer( "{$action}_$id" ); if ( ! current_user_can( 'delete_post', $id ) ) { wp_die( -1 ); } if ( ! get_post( $id ) ) { wp_die( 1 ); } if ( wp_delete_post( $id ) ) { wp_die( 1 ); } else { wp_die( 0 ); } }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
3.1.0 | Introduced. |