WordPress.org

Make WordPress Core

Changeset 23555


Ignore:
Timestamp:
03/01/2013 04:34:48 PM (6 years ago)
Author:
ryan
Message:

Introduce wp_slash() and wp_unslash(). This will be used to cleanup the myriad calls to addslashes*, add_magic_quotes, stripslashes*. see #21767

File:
1 edited

Legend:

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

    r23554 r23555  
    33433343    return apply_filters( 'sanitize_trackback_urls', $urls_to_ping, $to_ping );
    33443344}
     3345
     3346/**
     3347 * Add slashes to a string or array of strings.
     3348 *
     3349 * This should be used when preparing data for core API that expects slashed data.
     3350 * This should not be used to escape data going directly into an SQL query.
     3351 *
     3352 * @since 3.6.0
     3353 *
     3354 * @param string|array $value String or array of strings to slash.
     3355 * @return string|array Slashed $value
     3356 */
     3357function wp_slash( $value ) {
     3358    if ( is_array( $value ) ) {
     3359        foreach ( $value as $k => $v ) {
     3360            if ( is_array( $v ) ) {
     3361                $value[$k] = wp_slash( $v );
     3362            } else {
     3363                $value[$k] = addslashes( $v );
     3364            }
     3365        }
     3366    } else {
     3367        $value = addslashes( $value );
     3368    }
     3369
     3370    return $value;
     3371}
     3372
     3373/**
     3374 * Remove slashes from a string or array of strings.
     3375 *
     3376 * This should be used to remove slashes from data passed to core API that
     3377 * expects data to be unslashed.
     3378 *
     3379 * @since 3.6.0
     3380 *
     3381 * @param string|array $value String or array of strings to unslash.
     3382 * @return string|array Unslashed $value
     3383 */
     3384function wp_unslash( $value ) {
     3385    return stripslashes_deep( $value );
     3386}
Note: See TracChangeset for help on using the changeset viewer.