Make WordPress Core

Ticket #20417: 20417-meta-api.diff

File 20417-meta-api.diff, 7.2 KB (added by nacin, 12 years ago)
  • wp-includes/post.php

     
    20342034        $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) );
    20352035
    20362036        $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
    2037         if ( ! empty($comment_ids) ) {
    2038                 do_action( 'delete_comment', $comment_ids );
    2039                 foreach ( $comment_ids as $comment_id )
    2040                         wp_delete_comment( $comment_id, true );
    2041                 do_action( 'deleted_comment', $comment_ids );
    2042         }
     2037        foreach ( $comment_ids as $comment_id )
     2038                wp_delete_comment( $comment_id, true );
    20432039
    20442040        $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ));
    2045         if ( !empty($post_meta_ids) ) {
    2046                 do_action( 'delete_postmeta', $post_meta_ids );
    2047                 $in_post_meta_ids = "'" . implode("', '", $post_meta_ids) . "'";
    2048                 $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id IN($in_post_meta_ids)" );
    2049                 do_action( 'deleted_postmeta', $post_meta_ids );
    2050         }
     2041        foreach ( $post_meta_ids as $mid )
     2042                delete_metadata_by_id( 'post', $mid );
    20512043
    20522044        do_action( 'delete_post', $postid );
    20532045        $wpdb->delete( $wpdb->posts, array( 'ID' => $postid ) );
     
    38003792        wp_delete_object_term_relationships($post_id, array('category', 'post_tag'));
    38013793        wp_delete_object_term_relationships($post_id, get_object_taxonomies($post->post_type));
    38023794
    3803         $wpdb->delete( $wpdb->postmeta, array( 'meta_key' => '_thumbnail_id' , 'meta_value' => $post_id ) );
     3795        delete_metadata( 'post', null, '_thumbnail_id', $post_id, true ); // delete all for any posts.
    38043796
    38053797        $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ));
    3806         if ( ! empty( $comment_ids ) ) {
    3807                 do_action( 'delete_comment', $comment_ids );
    3808                 foreach ( $comment_ids as $comment_id )
    3809                         wp_delete_comment( $comment_id, true );
    3810                 do_action( 'deleted_comment', $comment_ids );
    3811         }
     3798        foreach ( $comment_ids as $comment_id )
     3799                wp_delete_comment( $comment_id, true );
    38123800
    38133801        $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ));
    3814         if ( !empty($post_meta_ids) ) {
    3815                 do_action( 'delete_postmeta', $post_meta_ids );
    3816                 $in_post_meta_ids = "'" . implode("', '", $post_meta_ids) . "'";
    3817                 $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id IN($in_post_meta_ids)" );
    3818                 do_action( 'deleted_postmeta', $post_meta_ids );
    3819         }
     3802        foreach ( $post_meta_ids as $mid )
     3803                delete_metadata_by_id( 'post', $mid );
    38203804
    38213805        do_action( 'delete_post', $post_id );
    38223806        $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) );
     
    45644548                return;
    45654549
    45664550        $data = array( 'post_id' => $post_id, 'meta_value' => '1' );
    4567         if ( get_option('default_pingback_flag') ) {
    4568                 $wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_pingme' ) );
    4569                 do_action( 'added_postmeta', $wpdb->insert_id, $post_id, '_pingme', 1 );
    4570         }
    4571         $wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_encloseme' ) );
    4572         do_action( 'added_postmeta', $wpdb->insert_id, $post_id, '_encloseme', 1 );
     4551        if ( get_option('default_pingback_flag') )
     4552                add_post_meta( $post_id, '_pingme', '1' );
     4553        add_post_meta( $post_id, '_encloseme', '1' );
    45734554
    45744555        wp_schedule_single_event(time(), 'do_pings');
    45754556}
  • wp-includes/comment.php

     
    980980        }
    981981
    982982        // Delete metadata
    983         $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d ", $comment_id ) );
    984         if ( !empty($meta_ids) ) {
    985                 do_action( 'delete_commentmeta', $meta_ids );
    986                 $in_meta_ids = "'" . implode("', '", $meta_ids) . "'";
    987                 $wpdb->query( "DELETE FROM $wpdb->commentmeta WHERE meta_id IN ($in_meta_ids)" );
    988                 do_action( 'deleted_commentmeta', $meta_ids );
    989         }
     983        $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment_id ) );
     984        foreach ( $meta_ids as $mid )
     985                delete_metadata_by_id( 'comment', $mid );
    990986
    991987        if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment_id ) ) )
    992988                return false;
  • wp-includes/functions.php

     
    426426
    427427        foreach ( $pung as $link_test ) {
    428428                if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post
    429                         $mid = $wpdb->get_col( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape( $link_test ) . '%') );
    430                         do_action( 'delete_postmeta', $mid );
    431                         $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id IN(%s)", implode( ',', $mid ) ) );
    432                         do_action( 'deleted_postmeta', $mid );
     429                        $mids = $wpdb->get_col( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape( $link_test ) . '%') );
     430                        foreach ( $mids as $mid )
     431                                delete_metadata_by_mid( 'post', $mid );
    433432                }
    434433        }
    435434
     
    469468                                }
    470469
    471470                                if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
    472                                         $meta_value = "$url\n$len\n$type\n";
    473                                         $wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value) );
    474                                         do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, 'enclosure', $meta_value );
     471                                        add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" );
    475472                                }
    476473                        }
    477474                }
  • wp-includes/meta.php

     
    223223
    224224        do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
    225225
     226        // Old-style action.
    226227        if ( 'post' == $meta_type )
    227228                do_action( 'delete_postmeta', $meta_ids );
    228229
     
    243244
    244245        do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
    245246
     247        // Old-style action.
    246248        if ( 'post' == $meta_type )
    247249                do_action( 'deleted_postmeta', $meta_ids );
    248250
     
    485487
    486488                do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
    487489
    488                 if ( 'post' == $meta_type )
    489                         do_action( 'delete_postmeta', $meta_id );
     490                // Old-style action.
     491                if ( 'post' == $meta_type || 'comment' == $meta_type )
     492                        do_action( "delete_{$meta_type}meta", $meta_id );
    490493
    491494                // Run the query, will return true if deleted, false otherwise
    492495                $result = (bool) $wpdb->delete( $table, array( $id_column => $meta_id ) );
     
    496499
    497500                do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
    498501
    499                 if ( 'post' == $meta_type )
    500                         do_action( 'deleted_postmeta', $meta_id );
     502                // Old-style action.
     503                if ( 'post' == $meta_type || 'comment' == $meta_type )
     504                        do_action( "deleted_{$meta_type}meta", $meta_id );
    501505
    502506                return $result;
    503507