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
|
// Delete metadata
|
||||||
$meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d ", $comment_id ) );
|
$meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment_id ) );
|
||||||
if ( !empty($meta_ids) ) {
|
foreach ( $meta_ids as $mid )
|
||||||
do_action( 'delete_commentmeta', $meta_ids );
|
delete_metadata_by_mid( 'comment', $mid );
|
||||||
$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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment_id ) ) )
|
if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment_id ) ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -426,10 +426,9 @@ function do_enclose( $content, $post_ID ) {
|
||||||
|
|
||||||
foreach ( $pung as $link_test ) {
|
foreach ( $pung as $link_test ) {
|
||||||
if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post
|
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 ) . '%') );
|
$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 ) . '%') );
|
||||||
do_action( 'delete_postmeta', $mid );
|
foreach ( $mids as $mid )
|
||||||
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id IN(%s)", implode( ',', $mid ) ) );
|
delete_metadata_by_mid( 'post', $mid );
|
||||||
do_action( 'deleted_postmeta', $mid );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,9 +468,7 @@ function do_enclose( $content, $post_ID ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
|
if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
|
||||||
$meta_value = "$url\n$len\n$type\n";
|
add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\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 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 );
|
do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
|
||||||
|
|
||||||
|
// Old-style action.
|
||||||
if ( 'post' == $meta_type )
|
if ( 'post' == $meta_type )
|
||||||
do_action( 'delete_postmeta', $meta_ids );
|
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 );
|
do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
|
||||||
|
|
||||||
|
// Old-style action.
|
||||||
if ( 'post' == $meta_type )
|
if ( 'post' == $meta_type )
|
||||||
do_action( 'deleted_postmeta', $meta_ids );
|
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 );
|
do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
|
||||||
|
|
||||||
if ( 'post' == $meta_type )
|
// Old-style action.
|
||||||
do_action( 'delete_postmeta', $meta_id );
|
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
|
// Run the query, will return true if deleted, false otherwise
|
||||||
$result = (bool) $wpdb->delete( $table, array( $id_column => $meta_id ) );
|
$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 );
|
do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
|
||||||
|
|
||||||
if ( 'post' == $meta_type )
|
// Old-style action.
|
||||||
do_action( 'deleted_postmeta', $meta_id );
|
if ( 'post' == $meta_type || 'comment' == $meta_type )
|
||||||
|
do_action( "deleted_{$meta_type}meta", $meta_id );
|
||||||
|
|
||||||
return $result;
|
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' ) );
|
$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 ));
|
$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
|
||||||
if ( ! empty($comment_ids) ) {
|
foreach ( $comment_ids as $comment_id )
|
||||||
do_action( 'delete_comment', $comment_ids );
|
wp_delete_comment( $comment_id, true );
|
||||||
foreach ( $comment_ids as $comment_id )
|
|
||||||
wp_delete_comment( $comment_id, true );
|
|
||||||
do_action( 'deleted_comment', $comment_ids );
|
|
||||||
}
|
|
||||||
|
|
||||||
$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ));
|
$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ));
|
||||||
if ( !empty($post_meta_ids) ) {
|
foreach ( $post_meta_ids as $mid )
|
||||||
do_action( 'delete_postmeta', $post_meta_ids );
|
delete_metadata_by_mid( 'post', $mid );
|
||||||
$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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
do_action( 'delete_post', $postid );
|
do_action( 'delete_post', $postid );
|
||||||
$wpdb->delete( $wpdb->posts, array( 'ID' => $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, array('category', 'post_tag'));
|
||||||
wp_delete_object_term_relationships($post_id, get_object_taxonomies($post->post_type));
|
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 ));
|
$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ));
|
||||||
if ( ! empty( $comment_ids ) ) {
|
foreach ( $comment_ids as $comment_id )
|
||||||
do_action( 'delete_comment', $comment_ids );
|
wp_delete_comment( $comment_id, true );
|
||||||
foreach ( $comment_ids as $comment_id )
|
|
||||||
wp_delete_comment( $comment_id, true );
|
|
||||||
do_action( 'deleted_comment', $comment_ids );
|
|
||||||
}
|
|
||||||
|
|
||||||
$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ));
|
$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) ) {
|
foreach ( $post_meta_ids as $mid )
|
||||||
do_action( 'delete_postmeta', $post_meta_ids );
|
delete_metadata_by_mid( 'post', $mid );
|
||||||
$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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
do_action( 'delete_post', $post_id );
|
do_action( 'delete_post', $post_id );
|
||||||
$wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) );
|
$wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) );
|
||||||
|
@ -4563,13 +4547,9 @@ function _publish_post_hook($post_id) {
|
||||||
if ( defined('WP_IMPORTING') )
|
if ( defined('WP_IMPORTING') )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$data = array( 'post_id' => $post_id, 'meta_value' => '1' );
|
if ( get_option('default_pingback_flag') )
|
||||||
if ( get_option('default_pingback_flag') ) {
|
add_post_meta( $post_id, '_pingme', '1' );
|
||||||
$wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_pingme' ) );
|
add_post_meta( $post_id, '_encloseme', '1' );
|
||||||
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 );
|
|
||||||
|
|
||||||
wp_schedule_single_event(time(), 'do_pings');
|
wp_schedule_single_event(time(), 'do_pings');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue