Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/19/2014 01:36:57 AM (11 years ago)
Author:
boonebgorges
Message:

Refactor all uses of like_escape() to use bp_esc_like()

WordPress 4.0 will deprecate like_escape(), due to a history of inconsistent
documentation and usage. Its replacement is a new method, $wpdb->esc_like(),
which will be available only in WP 4.0. For this reason, and because the
return value of $wpdb->esc_like() will not always be identical to that of
like_escape(), BP cannot do a straight swap of the old function for the new
one. Instead, we introduce a wrapper function that uses the core method if
available, and otherwise reproduces the logic of that method (for earlier
versions of WordPress).

Fixes #5701
slightly different syntax in some cases

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-functions.php

    r8511 r8541  
    263263    $order = strtoupper( trim( $order ) );
    264264    return 'DESC' === $order ? 'DESC' : 'ASC';
     265}
     266
     267/**
     268 * Escape special characters in a SQL LIKE clause.
     269 *
     270 * In WordPress 4.0, like_escape() was deprecated, due to incorrect
     271 * documentation and improper sanitization leading to a history of misuse. To
     272 * maintain compatibility with versions of WP before 4.0, we duplicate the
     273 * logic of the replacement, wpdb::esc_like().
     274 *
     275 * @since BuddyPress (2.1.0)
     276 *
     277 * @see wpdb::esc_like() for more details on proper use.
     278 *
     279 * @param string $text The raw text to be escaped.
     280 * @return string Text in the form of a LIKE phrase. Not SQL safe. Run through
     281 *         wpdb::prepare() before use.
     282 */
     283function bp_esc_like( $text ) {
     284    global $wpdb;
     285
     286    if ( method_exists( $wpdb, 'esc_like' ) ) {
     287        return $wpdb->esc_like( $text );
     288    } else {
     289        return addcslashes( $text, '_%\\' );
     290    }
    265291}
    266292
Note: See TracChangeset for help on using the changeset viewer.