WordPress.org

Make WordPress Core

Ticket #18948: 18948.4.diff

File 18948.4.diff, 14.1 KB (added by justindgivens, 7 years ago)
  • wp-includes/taxonomy.php

     
    17651765                clean_object_term_cache( $objects, $object_type );
    17661766
    17671767        do_action( 'delete_term_taxonomy', $tt_id );
    1768         $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $tt_id ) );
     1768        $wpdb->delete( $wpdb->term_taxonomy , array( "term_taxonomy_id" => $tt_id ) , array( '%d' ) );
    17691769        do_action( 'deleted_term_taxonomy', $tt_id );
    17701770
    17711771        // Delete the term if no taxonomies use it.
    17721772        if ( !$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term) ) )
    1773                 $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->terms WHERE term_id = %d", $term) );
     1773                $wpdb->delete( $wpdb->terms , array( "term_id" => $term ) , array( '%d' ) );
    17741774
    17751775        clean_term_cache($term, $taxonomy);
    17761776
  • wp-includes/post.php

     
    20312031        }
    20322032
    20332033        do_action( 'delete_post', $postid );
    2034         $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE ID = %d", $postid ));
     2034        $wpdb->delete( $wpdb->posts , array( "ID" => $postid ) , array( '%d' ) );
    20352035        do_action( 'deleted_post', $postid );
    20362036
    20372037        if ( 'page' == $post->post_type ) {
     
    37833783        wp_delete_object_term_relationships($post_id, array('category', 'post_tag'));
    37843784        wp_delete_object_term_relationships($post_id, get_object_taxonomies($post->post_type));
    37853785
    3786         $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_thumbnail_id' AND meta_value = %d", $post_id ));
     3786        $wpdb->delete( $wpdb->postmeta , array( "meta_key" => '_thumbnail_id' , "meta_value" => $post_id ) , array( '%s' , '%d' ) );
    37873787
    37883788        $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ));
    37893789        if ( ! empty( $comment_ids ) ) {
     
    38023802        }
    38033803
    38043804        do_action( 'delete_post', $post_id );
    3805         $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE ID = %d", $post_id ));
     3805        $wpdb->delete( $wpdb->posts , array( "ID" => $post_id ) , array( '%d' ) );
    38063806        do_action( 'deleted_post', $post_id );
    38073807
    38083808        $uploadpath = wp_upload_dir();
  • wp-includes/comment.php

     
    970970                do_action( 'deleted_commentmeta', $meta_ids );
    971971        }
    972972
    973         if ( ! $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->comments WHERE comment_ID = %d LIMIT 1", $comment_id) ) )
     973        if ( ! $wpdb->delete( $wpdb->comments , array( "comment_ID" => $comment_id ) , array( '%d' ) , 1 ); )
    974974                return false;
    975975        do_action('deleted_comment', $comment_id);
    976976
  • wp-includes/functions.php

     
    665665        if ( is_null( $row ) )
    666666                return false;
    667667        do_action( 'delete_option', $option );
    668         $result = $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name = %s", $option) );
     668        $result = $wpdb->delete( $wpdb->options , array( "option_name" => $option ) , array( '%s' ) );
    669669        if ( ! defined( 'WP_INSTALLING' ) ) {
    670670                if ( 'yes' == $row->autoload ) {
    671671                        $alloptions = wp_load_alloptions();
     
    38903890                $cache_key = "{$wpdb->siteid}:$option";
    38913891                wp_cache_delete( $cache_key, 'site-options' );
    38923892
    3893                 $result = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid ) );
     3893                $result = $wpdb->delete( $wpdb->sitemeta , array( "meta_key" => $option , "site_id" => $wpdb->siteid ) , array( '%s' , '%d' ) );
    38943894        }
    38953895
    38963896        if ( $result ) {
  • wp-includes/wp-db.php

     
    409409         * @see wpdb:prepare()
    410410         * @see wpdb:insert()
    411411         * @see wpdb:update()
     412         * @see wpdb:delete()
    412413         * @see wp_set_wpdb_vars()
    413414         * @access public
    414415         * @var array
     
    12521253                $sql = "UPDATE `$table` SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres );
    12531254                return $this->query( $this->prepare( $sql, array_merge( array_values( $data ), array_values( $where ) ) ) );
    12541255        }
     1256       
     1257        /**
     1258         * Delete a row in the table
     1259         *
     1260         * <code>
     1261         * wpdb::delete( 'table', array( 'ID' => 1 ) )
     1262         * wpdb::delete( 'table', array( 'ID' => 1 ), array( '%d' ) )
     1263         * wpdb::delete( 'table', array( 'ID' => 1 ), array( '%d' ), 1 )
     1264         * </code>
     1265         *
     1266         * @since 2.5.0
     1267         * @see wpdb::prepare()
     1268         * @see wpdb::$field_types
     1269         * @see wp_set_wpdb_vars()
     1270         *
     1271         * @param string $table table name
     1272         * @param array $where A named array of WHERE clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $where columns and $where values should be "raw".
     1273         * @param array|string $where_format Optional. An array of formats to be mapped to each of the values in $where. If string, that format will be used for all of the items in $where.  A format is one of '%d', '%f', '%s' (integer, float, string).  If omitted, all values in $where will be treated as strings.
     1274         *      A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $where will be treated as strings unless otherwise specified in wpdb::$field_types.
     1275         * @param int $limit Optional. An int to limit the number of rows to delete.
     1276         * @return int|false The number of rows updated, or false on error.
     1277         */
     1278        function delete( $table, $where, $where_format = null, $limit = null ) {
     1279                if ( ! is_array( $where ) )
     1280                        return false;
     1281               
     1282                $bits = $wheres = array();
    12551283
     1284                $where_formats = $where_format = (array) $where_format;
     1285                foreach ( (array) array_keys( $where ) as $field ) {
     1286                        if ( !empty( $where_format ) )
     1287                                $form = ( $form = array_shift( $where_formats ) ) ? $form : $where_format[0];
     1288                        elseif ( isset( $this->field_types[$field] ) )
     1289                                $form = $this->field_types[$field];
     1290                        else
     1291                                $form = '%s';
     1292                        $wheres[] = "`$field` = {$form}";
     1293                }
     1294                $limits = '';
     1295                if (!empty($limit) {
     1296                        if (is_int($limit))
     1297                                $limits = ' LIMIT ' . $limit;
     1298                }
     1299               
     1300                $sql = "DELETE FROM `$table` WHERE " . implode( ' AND ', $wheres ) . $limits;
     1301                return $this->query( $this->prepare( $sql, $where ) );
     1302        }
     1303       
     1304       
    12561305        /**
    12571306         * Retrieve one variable from the database.
    12581307         *
  • wp-includes/deprecated.php

     
    22922292                do_action( 'delete_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value );
    22932293
    22942294        if ( ! empty($meta_value) )
    2295                 $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s AND meta_value = %s", $user_id, $meta_key, $meta_value) );
     2295                $wpdb->delete( $wpdb->usermeta , array( "user_id" => $user_id , "meta_key" => $meta_key , "meta_value" => $meta_value ) , array( '%d' , '%s' , '%s' ) );
    22962296        else
    2297                 $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) );
     2297                $wpdb->delete( $wpdb->usermeta , array( "user_id" => $user_id , "meta_key" => $meta_key ) , array( '%d' , '%s' ) );
    22982298
    22992299        clean_user_cache( $user_id );
    23002300        wp_cache_delete( $user_id, 'user_meta' );
  • wp-includes/ms-functions.php

     
    498498                $diff = $now - $registered_at;
    499499                // If registered more than two days ago, cancel registration and let this signup go through.
    500500                if ( $diff > 172800 )
    501                         $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->signups WHERE user_login = %s", $user_name) );
     501                        $wpdb->delete( $wpdb->signups , array( "user_login" => $user_name ) , array( '%s' ) );
    502502                else
    503503                        $errors->add('user_name', __('That username is currently reserved but may be available in a couple of days.'));
    504504
     
    511511                $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered);
    512512                // If registered more than two days ago, cancel registration and let this signup go through.
    513513                if ( $diff > 172800 )
    514                         $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->signups WHERE user_email = %s", $user_email) );
     514                        $wpdb->delete( $wpdb->signups , array( "user_email" => $user_email ) , array( '%s' ) );
    515515                else
    516516                        $errors->add('user_email', __('That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.'));
    517517        }
     
    614614                $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered);
    615615                // If registered more than two days ago, cancel registration and let this signup go through.
    616616                if ( $diff > 172800 )
    617                         $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->signups WHERE domain = %s AND path = %s", $mydomain, $path) );
     617                        $wpdb->delete( $wpdb->signups , array( "domain" => $mydomain , "path" => $path ) , array( '%s' , '%s' ) );
    618618                else
    619619                        $errors->add('blogname', __('That site is currently reserved but may be available in a couple days.'));
    620620        }
     
    11611161        $wpdb->update( $wpdb->options, array('option_value' => ''), array('option_name' => 'admin_email') );
    11621162
    11631163        // remove all perms
    1164         $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE meta_key = %s", $table_prefix.'user_level') );
    1165         $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE meta_key = %s", $table_prefix.'capabilities') );
     1164        $wpdb->delete( $wpdb->usermeta , array( "meta_key" => $table_prefix.'user_level' ) , array( '%s' ) );
     1165       
     1166        $wpdb->delete( $wpdb->usermeta , array( "meta_key" => $table_prefix.'capabilities' ) , array( '%s' ) );
    11661167
    11671168        $wpdb->suppress_errors( false );
    11681169}
  • wp-includes/meta.php

     
    489489                        do_action( 'delete_postmeta', $meta_id );
    490490
    491491                // Run the query, will return true if deleted, false otherwise
    492                 $result = (bool) $wpdb->query( $wpdb->prepare( "DELETE FROM $table WHERE $id_column = %d LIMIT 1;", $meta_id ) );
     492                $result = (bool) $wpdb->delete( $table , array( "$id_column" => $meta_id ) , array( '%d' ) , 1 );
    493493
    494494                // Clear the caches.
    495495                wp_cache_delete($object_id, $meta_type . '_meta');
  • wp-admin/includes/bookmark.php

     
    8383
    8484        wp_delete_object_term_relationships( $link_id, 'link_category' );
    8585
    86         $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->links WHERE link_id = %d", $link_id ) );
     86        $wpdb->delete( $wpdb->links , array( 'link_id' => $link_id ) , array ( '%d' ) );
    8787
    8888        do_action( 'deleted_link', $link_id );
    8989
  • wp-admin/includes/upgrade.php

     
    297297
    298298                // Delete any caps that snuck into the previously active blog. (Hardcoded to blog 1 for now.) TODO: Get previous_blog_id.
    299299                if ( !is_super_admin( $user_id ) && $user_id != 1 )
    300                         $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $wpdb->base_prefix.'1_capabilities') );
     300                        $wpdb->delete( $wpdb->usermeta , array( "user_id" => $user_id , "meta_key" => $wpdb->base_prefix.'1_capabilities' ) , array( '%d' , '%s' ) );
    301301        }
    302302}
    303303endif;
  • wp-admin/includes/user.php

     
    292292
    293293        // FINALLY, delete user
    294294        if ( !is_multisite() ) {
    295                 $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d", $id) );
    296                 $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->users WHERE ID = %d", $id) );
     295                $wpdb->delete( $wpdb->usermeta , array( "user_id" => $id ) , array( '%d' ) );
     296                $wpdb->delete( $wpdb->users , array( "ID" => $id ) , array( '%d' ) );
    297297        } else {
    298298                $level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels
    299                 $wpdb->query("DELETE FROM $wpdb->usermeta WHERE user_id = $id AND meta_key = '{$level_key}'");
     299                $wpdb->delete( $wpdb->usermeta , array( "user_id" => $id , "meta_key" => $level_key ) , array( '%d' , '%s' ) );
    300300        }
    301301
    302302        // allow for commit transaction
  • wp-admin/includes/ms.php

     
    8787                foreach ( (array) $drop_tables as $drop_table) {
    8888                        $wpdb->query( "DROP TABLE IF EXISTS ". current( $drop_table ) ."" );
    8989                }
    90                 $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->blogs WHERE blog_id = %d", $blog_id ) );
     90                $wpdb->delete( $wpdb->blogs , array( "blog_id" => $blog_id ) , array( '%d' ) );
    9191                $dir = apply_filters( 'wpmu_delete_blog_upload_dir', WP_CONTENT_DIR . "/blogs.dir/{$blog_id}/files/", $blog_id );
    9292                $dir = rtrim( $dir, DIRECTORY_SEPARATOR );
    9393                $top_dir = $dir;
     
    120120                }
    121121        }
    122122
    123         $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = '{$blog_prefix}autosave_draft_ids'" );
     123        $wpdb->delete( $wpdb->usermeta , array( "meta_key" => "'{$blog_prefix}autosave_draft_ids'" ) , array( '%s' ) );
    124124        $blogs = get_site_option( 'blog_list' );
    125125        if ( is_array( $blogs ) ) {
    126126                foreach ( $blogs as $n => $blog ) {
     
    166166                }
    167167        }
    168168
    169         $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->users WHERE ID = %d", $id ) );
    170         $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
     169        $wpdb->delete( $wpdb->users , array( "ID" => $id ) , array( '%d' ) );
     170        $wpdb->delete( $wpdb->usermeta , array( "user_id" => $id ) , array( '%d' ) );
    171171
    172172        clean_user_cache( $id );
    173173