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

Line Code
398      global $wpdb, $wp_rewrite;
399      $postid = (int) $postid;
400
401      if ( !$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $postid") )
402           return $post;
403
404      if ( 'attachment' == $post->post_type )
405           return wp_delete_attachment($postid);
406
407      do_action('delete_post', $postid);
408
409      if ( 'publish' == $post->post_status && 'post' == $post->post_type ) {
410           $categories = wp_get_post_categories($post->ID);
411           if( is_array( $categories ) ) {
412                foreach ( $categories as $cat_id ) {
413                     $wpdb->query("UPDATE $wpdb->categories SET category_count = category_count - 1 WHERE cat_ID = '$cat_id'");
414                     wp_cache_delete($cat_id, 'category');
415                     do_action('edit_category', $cat_id);
416                }