bp_esc_like

Escape special characters in a SQL LIKE clause.

Description

(string) bp_esc_like( (string) $text ); 

In WordPress 4.0, like_escape() was deprecated, due to incorrect documentation and improper sanitization leading to a history of misuse. To maintain compatibility with versions of WP before 4.0, we duplicate the logic of the replacement, wpdb::esc_like().

Returns (string)

Text in the form of a LIKE phrase. Not SQL safe. Run through wpdb::prepare() before use.

Parameters (1)

0. $text (string)
The raw text to be escaped.

Usage

  1. if ( !function_exists( 'bp_esc_like' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-functions.php'; 
  3.  
  4. // The raw text to be escaped. 
  5. $text = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_esc_like($text); 
  9.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-functions.php  
  1. function bp_esc_like( $text ) { 
  2. global $wpdb; 
  3.  
  4. if ( method_exists( $wpdb, 'esc_like' ) ) { 
  5. return $wpdb->esc_like( $text ); 
  6. } else { 
  7. return addcslashes( $text, '_%\\' );