Make WordPress Core

Changeset 24718


Ignore:
Timestamp:
07/16/2013 05:44:42 PM (11 years ago)
Author:
nacin
Message:

Deprecate wpdb::escape() in favor of wpdb::prepare() and esc_sql(). fixes #24774.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/formatting.php

    r24683 r24718  
    25922592
    25932593/**
    2594  * Escapes data for use in a MySQL query
    2595  *
    2596  * This is just a handy shortcut for $wpdb->escape(), for completeness' sake
     2594 * Escapes data for use in a MySQL query.
     2595 *
     2596 * Usually you should prepare queries using wpdb::prepare().
     2597 * Sometimes, spot-escaping is required or useful. One example
     2598 * is preparing an array for use in an IN clause.
    25972599 *
    25982600 * @since 2.8.0
    2599  * @param string $sql Unescaped SQL data
    2600  * @return string The cleaned $sql
    2601  */
    2602 function esc_sql( $sql ) {
     2601 * @param string $data Unescaped data
     2602 * @return string Escaped data
     2603 */
     2604function esc_sql( $data ) {
    26032605    global $wpdb;
    2604     return $wpdb->escape( $sql );
     2606    return $wpdb->_escape( $data );
    26052607}
    26062608
  • trunk/wp-includes/wp-db.php

    r24712 r24718  
    847847
    848848    /**
    849      * Weak escape, using addslashes()
    850      *
    851      * @see addslashes()
     849     * Do not use, deprecated.
     850     *
     851     * Use esc_sql() or wpdb::prepare() instead.
     852     *
    852853     * @since 2.8.0
     854     * @deprecated 3.6.0
     855     * @see wpdb::prepare
     856     * @see esc_sql()
    853857     * @access private
    854858     *
     
    857861     */
    858862    function _weak_escape( $string ) {
     863        if ( func_num_args() === 1 )
     864            _deprecated_function( __METHOD__, '3.6', 'wpdb::prepare() or esc_sql()' );
    859865        return addslashes( $string );
    860866    }
     
    877883     * Escape data. Works on arrays.
    878884     *
    879      * @uses wpdb::_escape()
    880885     * @uses wpdb::_real_escape()
    881886     * @since  2.8.0
     
    887892    function _escape( $data ) {
    888893        if ( is_array( $data ) ) {
    889             foreach ( (array) $data as $k => $v ) {
     894            foreach ( $data as $k => $v ) {
    890895                if ( is_array($v) )
    891896                    $data[$k] = $this->_escape( $v );
     
    901906
    902907    /**
    903      * Escapes content for insertion into the database using addslashes(), for security.
    904      *
    905      * Works on arrays.
    906      *
    907      * @since 0.71
    908      * @param string|array $data to escape
    909      * @return string|array escaped as query safe string
     908     * Do not use, deprecated.
     909     *
     910     * Use esc_sql() or wpdb::prepare() instead.
     911     *
     912     * @since 0.71
     913     * @deprecated 3.6.0
     914     * @see wpdb::prepare()
     915     * @see esc_sql()
     916     *
     917     * @param mixed $data
     918     * @return mixed
    910919     */
    911920    function escape( $data ) {
     921        if ( func_num_args() === 1 )
     922            _deprecated_function( __METHOD__, '3.6', 'wpdb::prepare() or esc_sql()' );
    912923        if ( is_array( $data ) ) {
    913             foreach ( (array) $data as $k => $v ) {
     924            foreach ( $data as $k => $v ) {
    914925                if ( is_array( $v ) )
    915                     $data[$k] = $this->escape( $v );
     926                    $data[$k] = $this->escape( $v, 'recursive' );
    916927                else
    917                     $data[$k] = $this->_weak_escape( $v );
     928                    $data[$k] = $this->_weak_escape( $v, 'internal' );
    918929            }
    919930        } else {
    920             $data = $this->_weak_escape( $data );
     931            $data = $this->_weak_escape( $data, 'internal' );
    921932        }
    922933
Note: See TracChangeset for help on using the changeset viewer.