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.
Built from https://develop.svn.wordpress.org/trunk@49143


git-svn-id: http://core.svn.wordpress.org/trunk@48905 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-10-14 02:10:04 +00:00
parent a706c4505e
commit 620c069fe8
4 changed files with 33 additions and 36 deletions

View File

@ -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;
}

View File

@ -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.
*

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.6-alpha-49142';
$wp_version = '5.6-alpha-49143';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -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';