| 1 | Index: wp-includes/post.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/post.php (revision 18495) |
|---|
| 4 | +++ wp-includes/post.php (working copy) |
|---|
| 5 | @@ -1497,22 +1497,7 @@ |
|---|
| 6 | * @return bool Whether the post meta key was deleted from the database |
|---|
| 7 | */ |
|---|
| 8 | function delete_post_meta_by_key($post_meta_key) { |
|---|
| 9 | - if ( !$post_meta_key ) |
|---|
| 10 | - return false; |
|---|
| 11 | - |
|---|
| 12 | - global $wpdb; |
|---|
| 13 | - $post_ids = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = %s", $post_meta_key)); |
|---|
| 14 | - if ( $post_ids ) { |
|---|
| 15 | - $postmetaids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = %s", $post_meta_key ) ); |
|---|
| 16 | - $in = implode( ',', array_fill(1, count($postmetaids), '%d')); |
|---|
| 17 | - do_action( 'delete_postmeta', $postmetaids ); |
|---|
| 18 | - $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id IN($in)", $postmetaids )); |
|---|
| 19 | - do_action( 'deleted_postmeta', $postmetaids ); |
|---|
| 20 | - foreach ( $post_ids as $post_id ) |
|---|
| 21 | - wp_cache_delete($post_id, 'post_meta'); |
|---|
| 22 | - return true; |
|---|
| 23 | - } |
|---|
| 24 | - return false; |
|---|
| 25 | + return delete_metadata( 'post', null, $post_meta_key, '', true ); |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | /** |
|---|
| 29 | Index: wp-includes/meta.php |
|---|
| 30 | =================================================================== |
|---|
| 31 | --- wp-includes/meta.php (revision 18495) |
|---|
| 32 | +++ wp-includes/meta.php (working copy) |
|---|
| 33 | @@ -149,6 +149,9 @@ |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); |
|---|
| 37 | + |
|---|
| 38 | + if ( 'post' == $meta_type ) |
|---|
| 39 | + do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); |
|---|
| 40 | |
|---|
| 41 | $wpdb->update( $table, $data, $where ); |
|---|
| 42 | |
|---|
| 43 | @@ -158,6 +161,9 @@ |
|---|
| 44 | clean_user_cache($object_id); |
|---|
| 45 | |
|---|
| 46 | do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); |
|---|
| 47 | + |
|---|
| 48 | + if ( 'post' == $meta_type ) |
|---|
| 49 | + do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); |
|---|
| 50 | |
|---|
| 51 | return true; |
|---|
| 52 | } |
|---|
| 53 | @@ -218,9 +224,12 @@ |
|---|
| 54 | return false; |
|---|
| 55 | |
|---|
| 56 | do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); |
|---|
| 57 | - |
|---|
| 58 | + |
|---|
| 59 | + if ( 'post' == $meta_type ) |
|---|
| 60 | + do_action( 'delete_postmeta', $meta_ids ); |
|---|
| 61 | + |
|---|
| 62 | $query = "DELETE FROM $table WHERE $id_column IN( " . implode( ',', $meta_ids ) . " )"; |
|---|
| 63 | - |
|---|
| 64 | + |
|---|
| 65 | $count = $wpdb->query($query); |
|---|
| 66 | |
|---|
| 67 | if ( !$count ) |
|---|
| 68 | @@ -232,6 +241,9 @@ |
|---|
| 69 | clean_user_cache($object_id); |
|---|
| 70 | |
|---|
| 71 | do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); |
|---|
| 72 | + |
|---|
| 73 | + if ( 'post' == $meta_type ) |
|---|
| 74 | + do_action( 'deleted_postmeta', $meta_ids ); |
|---|
| 75 | |
|---|
| 76 | return true; |
|---|
| 77 | } |
|---|
| 78 | @@ -381,6 +393,9 @@ |
|---|
| 79 | $where[$id_column] = $meta_id; |
|---|
| 80 | |
|---|
| 81 | do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); |
|---|
| 82 | + |
|---|
| 83 | + if ( 'post' == $meta_type ) |
|---|
| 84 | + do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); |
|---|
| 85 | |
|---|
| 86 | // Run the update query, all fields in $data are %s, $where is a %d. |
|---|
| 87 | $result = (bool) $wpdb->update( $table, $data, $where, '%s', '%d' ); |
|---|
| 88 | @@ -394,6 +409,9 @@ |
|---|
| 89 | |
|---|
| 90 | do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); |
|---|
| 91 | |
|---|
| 92 | + if ( 'post' == $meta_type ) |
|---|
| 93 | + do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); |
|---|
| 94 | + |
|---|
| 95 | return $result; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | @@ -436,6 +454,9 @@ |
|---|
| 99 | |
|---|
| 100 | do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value ); |
|---|
| 101 | |
|---|
| 102 | + if ( 'post' == $meta_type ) |
|---|
| 103 | + do_action( 'delete_postmeta', $object_id ); |
|---|
| 104 | + |
|---|
| 105 | // Run the query, will return true if deleted, false otherwise |
|---|
| 106 | $result = (bool) $wpdb->query( $wpdb->prepare( "DELETE FROM $table WHERE $id_column = %d LIMIT 1;", $meta_id ) ); |
|---|
| 107 | |
|---|
| 108 | @@ -448,6 +469,9 @@ |
|---|
| 109 | |
|---|
| 110 | do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value ); |
|---|
| 111 | |
|---|
| 112 | + if ( 'post' == $meta_type ) |
|---|
| 113 | + do_action( 'delete_postmeta', $object_id ); |
|---|
| 114 | + |
|---|
| 115 | return $result; |
|---|
| 116 | |
|---|
| 117 | } |
|---|
| 118 | Index: wp-admin/includes/post.php |
|---|
| 119 | =================================================================== |
|---|
| 120 | --- wp-admin/includes/post.php (revision 18495) |
|---|
| 121 | +++ wp-admin/includes/post.php (working copy) |
|---|
| 122 | @@ -701,17 +701,7 @@ |
|---|
| 123 | * @return unknown |
|---|
| 124 | */ |
|---|
| 125 | function delete_meta( $mid ) { |
|---|
| 126 | - global $wpdb; |
|---|
| 127 | - $mid = (int) $mid; |
|---|
| 128 | - |
|---|
| 129 | - $post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $mid) ); |
|---|
| 130 | - |
|---|
| 131 | - do_action( 'delete_postmeta', $mid ); |
|---|
| 132 | - wp_cache_delete($post_id, 'post_meta'); |
|---|
| 133 | - $rval = $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $mid) ); |
|---|
| 134 | - do_action( 'deleted_postmeta', $mid ); |
|---|
| 135 | - |
|---|
| 136 | - return $rval; |
|---|
| 137 | + return delete_metadata_by_mid( 'post' , $mid); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | /** |
|---|
| 141 | @@ -742,15 +732,7 @@ |
|---|
| 142 | * @return unknown |
|---|
| 143 | */ |
|---|
| 144 | function get_post_meta_by_id( $mid ) { |
|---|
| 145 | - global $wpdb; |
|---|
| 146 | - $mid = (int) $mid; |
|---|
| 147 | - |
|---|
| 148 | - $meta = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE meta_id = %d", $mid) ); |
|---|
| 149 | - if ( empty($meta) ) |
|---|
| 150 | - return false; |
|---|
| 151 | - if ( is_serialized_string( $meta->meta_value ) ) |
|---|
| 152 | - $meta->meta_value = maybe_unserialize( $meta->meta_value ); |
|---|
| 153 | - return $meta; |
|---|
| 154 | + return get_metadata_by_mid( 'post', $mid ); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | /** |
|---|
| 158 | @@ -782,27 +764,7 @@ |
|---|
| 159 | * @return unknown |
|---|
| 160 | */ |
|---|
| 161 | function update_meta( $meta_id, $meta_key, $meta_value ) { |
|---|
| 162 | - global $wpdb; |
|---|
| 163 | - |
|---|
| 164 | - $meta_key = stripslashes($meta_key); |
|---|
| 165 | - |
|---|
| 166 | - if ( '' === trim( $meta_value ) ) |
|---|
| 167 | - return false; |
|---|
| 168 | - |
|---|
| 169 | - $post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $meta_id) ); |
|---|
| 170 | - |
|---|
| 171 | - $meta_value = maybe_serialize( stripslashes_deep( $meta_value ) ); |
|---|
| 172 | - $meta_id = (int) $meta_id; |
|---|
| 173 | - |
|---|
| 174 | - $data = compact( 'meta_key', 'meta_value' ); |
|---|
| 175 | - $where = compact( 'meta_id' ); |
|---|
| 176 | - |
|---|
| 177 | - do_action( 'update_postmeta', $meta_id, $post_id, $meta_key, $meta_value ); |
|---|
| 178 | - $rval = $wpdb->update( $wpdb->postmeta, $data, $where ); |
|---|
| 179 | - wp_cache_delete($post_id, 'post_meta'); |
|---|
| 180 | - do_action( 'updated_postmeta', $meta_id, $post_id, $meta_key, $meta_value ); |
|---|
| 181 | - |
|---|
| 182 | - return $rval; |
|---|
| 183 | + return update_metadata_by_mid( 'post', $meta_id, $meta_value, $meta_key ); |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | // |
|---|