Use the metadata API rather than raw queries and direct do_action calls. see #20417.
git-svn-id: http://svn.automattic.com/wordpress/trunk@20435 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b46712cc96
commit
c7cf0927fc
|
@ -980,13 +980,9 @@ function wp_delete_comment($comment_id, $force_delete = false) {
|
|||
}
|
||||
|
||||
// Delete metadata
|
||||
$meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d ", $comment_id ) );
|
||||
if ( !empty($meta_ids) ) {
|
||||
do_action( 'delete_commentmeta', $meta_ids );
|
||||
$in_meta_ids = "'" . implode("', '", $meta_ids) . "'";
|
||||
$wpdb->query( "DELETE FROM $wpdb->commentmeta WHERE meta_id IN ($in_meta_ids)" );
|
||||
do_action( 'deleted_commentmeta', $meta_ids );
|
||||
}
|
||||
$meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment_id ) );
|
||||
foreach ( $meta_ids as $mid )
|
||||
delete_metadata_by_mid( 'comment', $mid );
|
||||
|
||||
if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment_id ) ) )
|
||||
return false;
|
||||
|
|
|
@ -426,10 +426,9 @@ function do_enclose( $content, $post_ID ) {
|
|||
|
||||
foreach ( $pung as $link_test ) {
|
||||
if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post
|
||||
$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 ) . '%') );
|
||||
do_action( 'delete_postmeta', $mid );
|
||||
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id IN(%s)", implode( ',', $mid ) ) );
|
||||
do_action( 'deleted_postmeta', $mid );
|
||||
$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 ) . '%') );
|
||||
foreach ( $mids as $mid )
|
||||
delete_metadata_by_mid( 'post', $mid );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -469,9 +468,7 @@ function do_enclose( $content, $post_ID ) {
|
|||
}
|
||||
|
||||
if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
|
||||
$meta_value = "$url\n$len\n$type\n";
|
||||
$wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value) );
|
||||
do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, 'enclosure', $meta_value );
|
||||
add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -223,6 +223,7 @@ function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $d
|
|||
|
||||
do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
|
||||
|
||||
// Old-style action.
|
||||
if ( 'post' == $meta_type )
|
||||
do_action( 'delete_postmeta', $meta_ids );
|
||||
|
||||
|
@ -243,6 +244,7 @@ function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $d
|
|||
|
||||
do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
|
||||
|
||||
// Old-style action.
|
||||
if ( 'post' == $meta_type )
|
||||
do_action( 'deleted_postmeta', $meta_ids );
|
||||
|
||||
|
@ -485,8 +487,9 @@ function delete_metadata_by_mid( $meta_type, $meta_id ) {
|
|||
|
||||
do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
|
||||
|
||||
if ( 'post' == $meta_type )
|
||||
do_action( 'delete_postmeta', $meta_id );
|
||||
// Old-style action.
|
||||
if ( 'post' == $meta_type || 'comment' == $meta_type )
|
||||
do_action( "delete_{$meta_type}meta", $meta_id );
|
||||
|
||||
// Run the query, will return true if deleted, false otherwise
|
||||
$result = (bool) $wpdb->delete( $table, array( $id_column => $meta_id ) );
|
||||
|
@ -496,8 +499,9 @@ function delete_metadata_by_mid( $meta_type, $meta_id ) {
|
|||
|
||||
do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
|
||||
|
||||
if ( 'post' == $meta_type )
|
||||
do_action( 'deleted_postmeta', $meta_id );
|
||||
// Old-style action.
|
||||
if ( 'post' == $meta_type || 'comment' == $meta_type )
|
||||
do_action( "deleted_{$meta_type}meta", $meta_id );
|
||||
|
||||
return $result;
|
||||
|
||||
|
|
|
@ -2034,20 +2034,12 @@ function wp_delete_post( $postid = 0, $force_delete = false ) {
|
|||
$wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) );
|
||||
|
||||
$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
|
||||
if ( ! empty($comment_ids) ) {
|
||||
do_action( 'delete_comment', $comment_ids );
|
||||
foreach ( $comment_ids as $comment_id )
|
||||
wp_delete_comment( $comment_id, true );
|
||||
do_action( 'deleted_comment', $comment_ids );
|
||||
}
|
||||
foreach ( $comment_ids as $comment_id )
|
||||
wp_delete_comment( $comment_id, true );
|
||||
|
||||
$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ));
|
||||
if ( !empty($post_meta_ids) ) {
|
||||
do_action( 'delete_postmeta', $post_meta_ids );
|
||||
$in_post_meta_ids = "'" . implode("', '", $post_meta_ids) . "'";
|
||||
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id IN($in_post_meta_ids)" );
|
||||
do_action( 'deleted_postmeta', $post_meta_ids );
|
||||
}
|
||||
foreach ( $post_meta_ids as $mid )
|
||||
delete_metadata_by_mid( 'post', $mid );
|
||||
|
||||
do_action( 'delete_post', $postid );
|
||||
$wpdb->delete( $wpdb->posts, array( 'ID' => $postid ) );
|
||||
|
@ -3800,23 +3792,15 @@ function wp_delete_attachment( $post_id, $force_delete = false ) {
|
|||
wp_delete_object_term_relationships($post_id, array('category', 'post_tag'));
|
||||
wp_delete_object_term_relationships($post_id, get_object_taxonomies($post->post_type));
|
||||
|
||||
$wpdb->delete( $wpdb->postmeta, array( 'meta_key' => '_thumbnail_id' , 'meta_value' => $post_id ) );
|
||||
delete_metadata( 'post', null, '_thumbnail_id', $post_id, true ); // delete all for any posts.
|
||||
|
||||
$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ));
|
||||
if ( ! empty( $comment_ids ) ) {
|
||||
do_action( 'delete_comment', $comment_ids );
|
||||
foreach ( $comment_ids as $comment_id )
|
||||
wp_delete_comment( $comment_id, true );
|
||||
do_action( 'deleted_comment', $comment_ids );
|
||||
}
|
||||
foreach ( $comment_ids as $comment_id )
|
||||
wp_delete_comment( $comment_id, true );
|
||||
|
||||
$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ));
|
||||
if ( !empty($post_meta_ids) ) {
|
||||
do_action( 'delete_postmeta', $post_meta_ids );
|
||||
$in_post_meta_ids = "'" . implode("', '", $post_meta_ids) . "'";
|
||||
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id IN($in_post_meta_ids)" );
|
||||
do_action( 'deleted_postmeta', $post_meta_ids );
|
||||
}
|
||||
foreach ( $post_meta_ids as $mid )
|
||||
delete_metadata_by_mid( 'post', $mid );
|
||||
|
||||
do_action( 'delete_post', $post_id );
|
||||
$wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) );
|
||||
|
@ -4563,13 +4547,9 @@ function _publish_post_hook($post_id) {
|
|||
if ( defined('WP_IMPORTING') )
|
||||
return;
|
||||
|
||||
$data = array( 'post_id' => $post_id, 'meta_value' => '1' );
|
||||
if ( get_option('default_pingback_flag') ) {
|
||||
$wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_pingme' ) );
|
||||
do_action( 'added_postmeta', $wpdb->insert_id, $post_id, '_pingme', 1 );
|
||||
}
|
||||
$wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_encloseme' ) );
|
||||
do_action( 'added_postmeta', $wpdb->insert_id, $post_id, '_encloseme', 1 );
|
||||
if ( get_option('default_pingback_flag') )
|
||||
add_post_meta( $post_id, '_pingme', '1' );
|
||||
add_post_meta( $post_id, '_encloseme', '1' );
|
||||
|
||||
wp_schedule_single_event(time(), 'do_pings');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue