General: Move wp_array_get()
from a separate file to wp-includes/functions.php
, for consistency.
Add missing `@since` tag, adjust the DocBlock per the documentation standards. Follow-up to [49135]. Props isabel_brison, ocean90. Fixes #51461. git-svn-id: https://develop.svn.wordpress.org/trunk@49143 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
de89e7292e
commit
f3f53fb4e4
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Array API: WordPress array utilities.
|
||||
*
|
||||
* @package WordPress
|
||||
* @since 5.6.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Accesses an array in depth based on a path of keys.
|
||||
* It is the PHP equivalent of JavaScript's lodash.get, and mirroring it may help other components
|
||||
* retain some symmetry between client and server implementations.
|
||||
*
|
||||
* @param array $array An array from which we want to retrieve some information.
|
||||
* @param array $path An array of keys describing the path with which to retrieve information.
|
||||
* @param array $default The return value if the path is not set on the array or if the types of array and path are not arrays.
|
||||
*
|
||||
* @return array An array matching the path specified.
|
||||
*/
|
||||
function wp_array_get( $array, $path, $default = array() ) {
|
||||
// Confirm input values are expected type to avoid notice warnings.
|
||||
if ( ! is_array( $array ) || ! is_array( $path ) ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$path_length = count( $path );
|
||||
for ( $i = 0; $i < $path_length; ++$i ) {
|
||||
if ( ! isset( $array[ $path[ $i ] ] ) ) {
|
||||
return $default;
|
||||
}
|
||||
$array = $array[ $path[ $i ] ];
|
||||
}
|
||||
return $array;
|
||||
}
|
@ -4526,6 +4526,38 @@ function wp_is_numeric_array( $data ) {
|
||||
return count( $string_keys ) === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accesses an array in depth based on a path of keys.
|
||||
*
|
||||
* It is the PHP equivalent of JavaScript's lodash.get, and mirroring it may help other components
|
||||
* retain some symmetry between client and server implementations.
|
||||
*
|
||||
* @since 5.6.0
|
||||
*
|
||||
* @param array $array An array from which we want to retrieve some information.
|
||||
* @param array $path An array of keys describing the path with which to retrieve information.
|
||||
* @param array $default The return value if the path is not set on the array,
|
||||
* or if the types of array and path are not arrays.
|
||||
* @return array An array matching the path specified.
|
||||
*/
|
||||
function wp_array_get( $array, $path, $default = array() ) {
|
||||
// Confirm input values are expected type to avoid notice warnings.
|
||||
if ( ! is_array( $array ) || ! is_array( $path ) ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$path_length = count( $path );
|
||||
|
||||
for ( $i = 0; $i < $path_length; ++$i ) {
|
||||
if ( ! isset( $array[ $path[ $i ] ] ) ) {
|
||||
return $default;
|
||||
}
|
||||
$array = $array[ $path[ $i ] ];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters a list of objects, based on a set of key => value arguments.
|
||||
*
|
||||
|
@ -179,7 +179,6 @@ require ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php';
|
||||
require ABSPATH . WPINC . '/class-wp-metadata-lazyloader.php';
|
||||
require ABSPATH . WPINC . '/general-template.php';
|
||||
require ABSPATH . WPINC . '/link-template.php';
|
||||
require ABSPATH . WPINC . '/array.php';
|
||||
require ABSPATH . WPINC . '/author-template.php';
|
||||
require ABSPATH . WPINC . '/post.php';
|
||||
require ABSPATH . WPINC . '/class-walker-page.php';
|
||||
|
Loading…
Reference in New Issue
Block a user