On this page
wp_ajax_trash_post( string $action )
Ajax handler for sending a post to the Trash.
Parameters
$actionstring Required-
Action to perform.
Source
File: wp-admin/includes/ajax-actions.php. View all references
function wp_ajax_trash_post( $action ) {
if ( empty( $action ) ) {
$action = 'trash-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 ( 'trash-post' === $action ) {
$done = wp_trash_post( $id );
} else {
$done = wp_untrash_post( $id );
}
if ( $done ) {
wp_die( 1 );
}
wp_die( 0 );
}
Related
Uses
| Uses | Description |
|---|---|
| wp_trash_post() wp-includes/post.php | Moves a post or page to the Trash |
| wp_untrash_post() wp-includes/post.php | Restores a post from the Trash. |
| current_user_can() wp-includes/capabilities.php | Returns whether the current user has the specified capability. |
| check_ajax_referer() wp-includes/pluggable.php | Verifies the Ajax request to prevent processing requests external of the blog. |
| wp_die() wp-includes/functions.php | Kills WordPress execution and displays HTML page with an error message. |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
Used By
| Used By | Description |
|---|---|
| wp_ajax_untrash_post() wp-admin/includes/ajax-actions.php | Ajax handler to restore a post from the Trash. |
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_ajax_trash_post