before_delete_post
Action HookDescription
Fires before a post is deleted, at the start of wp_delete_post().Hook Information
File Location |
wp-includes/post.php
View on GitHub
|
Hook Type | Action |
Line Number | 3753 |
Hook Parameters
Type | Name | Description |
---|---|---|
int
|
$post_id
|
Post ID. |
WP_Post
|
$post
|
Post object. |
Usage Examples
Basic Usage
<?php
// Hook into before_delete_post
add_action('before_delete_post', 'my_custom_function', 10, 2);
function my_custom_function($post_id, $post) {
// Your custom code here
}
Source Code Context
wp-includes/post.php:3753
- How this hook is used in WordPress core
<?php
3748 * @see wp_delete_post()
3749 *
3750 * @param int $post_id Post ID.
3751 * @param WP_Post $post Post object.
3752 */
3753 do_action( 'before_delete_post', $post_id, $post );
3754
3755 delete_post_meta( $post_id, '_wp_trash_meta_status' );
3756 delete_post_meta( $post_id, '_wp_trash_meta_time' );
3757
3758 wp_delete_object_term_relationships( $post_id, get_object_taxonomies( $post->post_type ) );
PHP Documentation
<?php
/**
* Fires before a post is deleted, at the start of wp_delete_post().
*
* @since 3.2.0
* @since 5.5.0 Added the `$post` parameter.
*
* @see wp_delete_post()
*
* @param int $post_id Post ID.
* @param WP_Post $post Post object.
*/
Quick Info
- Hook Type: Action
- Parameters: 2
- File: wp-includes/post.php
Related Hooks
Related hooks will be displayed here in future updates.