Source View: delete_post

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

  • Action hooks look like this: do_action( "hook_name" )
  • Filter hooks look like this: apply_filters( "hook_name", "what_to_filter" ).

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 2 times in this file.

Line Code
2285
2286      $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
2287      foreach ( $comment_ids as $comment_id )
2288           wp_delete_comment( $comment_id, true );
2289
2290      $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ));
2291      foreach ( $post_meta_ids as $mid )
2292           delete_metadata_by_mid( 'post', $mid );
2293
2294      do_action( 'delete_post', $postid );
2295      $wpdb->delete( $wpdb->posts, array( 'ID' => $postid ) );
2296      do_action( 'deleted_post', $postid );
2297
2298      clean_post_cache( $post );
2299
2300      if ( is_post_type_hierarchical( $post->post_type ) && $children ) {
2301           foreach ( $children as $child )
2302                clean_post_cache( $child );
2303      }
 
Line Code
4078
4079      $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ));
4080      foreach ( $comment_ids as $comment_id )
4081           wp_delete_comment( $comment_id, true );
4082
4083      $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ));
4084      foreach ( $post_meta_ids as $mid )
4085           delete_metadata_by_mid( 'post', $mid );
4086
4087      do_action( 'delete_post', $post_id );
4088      $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) );
4089      do_action( 'deleted_post', $post_id );
4090
4091      $uploadpath = wp_upload_dir();
4092
4093      if ( ! empty($meta['thumb']) ) {
4094           // Don't delete the thumb if another attachment uses it
4095           if (! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $meta['thumb'] . '%', $post_id)) ) {
4096                $thumbfile = str_replace(basename($file), $meta['thumb'], $file);