WordPress.org

Make WordPress Core

Ticket #20569: addslashes-deep.diff

File addslashes-deep.diff, 1.1 KB (added by alexkingorg, 6 years ago)

addslashes_deep()

  • wp-includes/formatting.php

     
    13111311}
    13121312
    13131313/**
     1314 * Navigates through an array and adds slashes to the values.
     1315 *
     1316 * If an array is passed, the array_map() function causes a callback to pass the
     1317 * value back to the function. Slashes will be added to this value.
     1318 *
     1319 * @since 3.4.0
     1320 *
     1321 * @param array|string $value The array or string to be slashed.
     1322 * @return array|string Slashed array (or string in the callback).
     1323 */
     1324function addslashes_deep($value) {
     1325        if ( is_array($value) ) {
     1326                $value = array_map('addslashes_deep', $value);
     1327        } elseif ( is_object($value) ) {
     1328                $vars = get_object_vars( $value );
     1329                foreach ($vars as $key=>$data) {
     1330                        $value->{$key} = addslashes_deep( $data );
     1331                }
     1332        } else {
     1333                $value = addslashes($value);
     1334        }
     1335
     1336        return $value;
     1337}
     1338
     1339/**
    13141340 * Navigates through an array and removes slashes from the values.
    13151341 *
    13161342 * If an array is passed, the array_map() function causes a callback to pass the