function test_map_deep_should_map_each_object_property_of_an_object() {
		$this->assertEquals( (object)array( 'var0' => 'ababa', 'var1' => (object)array( 'xbaba' ) ),
			map_deep( array( $this, 'append_baba' ), (object)array( 'var0' => 'a', 'var1' => (object)array( 'x' ) ) ) );
	}
Exemple #2
0
/**
 * Navigates through an array, object, or scalar, and sanitizes content for
 * allowed HTML tags for post content.
 *
 * @since 4.4.2
 *
 * @param mixed $value The array or string to filter.
 * @return mixed $value The filtered content.
 */
function wp_kses_post_deep($data)
{
    return map_deep($data, 'wp_kses_post');
}
/**
 * Maps a function to all non-iterable elements of an array or an object.
 *
 * This is similar to `array_walk_recursive()` but acts upon objects too.
 *
 * @since 4.4.0
 *
 * @param mixed    $value    The array, object, or scalar.
 * @param callable $callback The function to map onto $value.
 * @return The value with the callback applied to all non-arrays and non-objects inside it.
 */
function map_deep($value, $callback)
{
    if (is_array($value) || is_object($value)) {
        foreach ($value as &$item) {
            $item = map_deep($item, $callback);
        }
        return $value;
    } else {
        return call_user_func($callback, $value);
    }
}
/**
 * Maps a function to all non-iterable elements of an array or an object.
 *
 * This is similar to `array_walk_recursive()` but acts upon objects too.
 *
 * @since 4.4.0
 *
 * @param mixed    $value    The array, object, or scalar.
 * @param callable $callback The function to map onto $value.
 * @return The value with the callback applied to all non-arrays and non-objects inside it.
 */
function map_deep( $value, $callback ) {
	if ( is_array( $value ) ) {
		foreach ( $value as $index => $item ) {
			$value[ $index ] = map_deep( $item, $callback );
		}
	} elseif ( is_object( $value ) ) {
		$object_vars = get_object_vars( $value );
		foreach ( $object_vars as $property_name => $property_value ) {
			$value->$property_name = map_deep( $property_value, $callback );
		}
	} else {
		$value = call_user_func( $callback, $value );
	}

	return $value;
}
 /**
  * @ticket 35058
  */
 public function test_map_deep_should_map_array_elements_passed_by_reference()
 {
     $array_a = array('var0' => 'a');
     $array_b = array('var0' => &$array_a['var0'], 'var1' => 'x');
     $this->assertEquals(array('var0' => 'ababa', 'var1' => 'xbaba'), map_deep($array_b, array($this, 'append_baba')));
 }
/**
 * Maps a function to all non-iterable elements of an array or an object.
 *
 * @see map_deep() This is an alias of the WP core function `map_deep()`, added in 4.4. Here for legacy purposes.
 * @since 1.16.3
 *
 * @param mixed    $value    The array, object, or scalar.
 * @param callable $callback The function to map onto $value.
 *
 * @return mixed The value with the callback applied to all non-arrays and non-objects inside it.
 */
function gv_map_deep($value, $callback)
{
    // Use the original function, if exists.
    // Requires WP 4.4+
    if (function_exists('map_deep')) {
        return map_deep($value, $callback);
    }
    // Exact copy of map_deep() code below:
    if (is_array($value)) {
        foreach ($value as $index => $item) {
            $value[$index] = gv_map_deep($item, $callback);
        }
    } elseif (is_object($value)) {
        $object_vars = get_object_vars($value);
        foreach ($object_vars as $property_name => $property_value) {
            $value->{$property_name} = gv_map_deep($property_value, $callback);
        }
    } else {
        $value = call_user_func($callback, $value);
    }
    return $value;
}
 /**
  * Sanitizes and saves term meta data when a term is altered.
  *
  * @since 2.7.0
  *
  * @param int $term_id     Term ID.
  * @param int $tt_id       Term Taxonomy ID.
  * @param string $taxonomy Taxonomy Slug
  * @return void Early on AJAX call.
  */
 public function update_term_meta($term_id, $tt_id, $taxonomy = '')
 {
     if (defined('DOING_AJAX') && DOING_AJAX) {
         return;
     }
     //* Check again against ambiguous injection.
     if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'update-tag_' . $term_id)) {
         $data = isset($_POST['autodescription-meta']) ? (array) map_deep($_POST['autodescription-meta'], 'esc_attr') : array();
         $data = wp_parse_args($data, $this->get_term_meta_defaults());
         update_term_meta($term_id, THE_SEO_FRAMEWORK_TERM_OPTIONS, $data);
     }
 }