<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[49580] trunk/src/wp-includes: General: Convert `wp_array_get()` to a "private" function and add tests.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/49580">49580</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/49580","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>johnbillion</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2020-11-12 20:18:08 +0000 (Thu, 12 Nov 2020)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>General: Convert `wp_array_get()` to a "private" function and add tests.
This function may be promoted in the future if it's deemed useful enough.
Props dd32, jorgefilipecosta, Hareesh Pillai
Fixes <a href="https://core.trac.wordpress.org/ticket/51720">#51720</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocksupportsalignphp">trunk/src/wp-includes/block-supports/align.php</a></li>
<li><a href="#trunksrcwpincludesblocksupportscolorsphp">trunk/src/wp-includes/block-supports/colors.php</a></li>
<li><a href="#trunksrcwpincludesblocksupportscustomclassnamephp">trunk/src/wp-includes/block-supports/custom-classname.php</a></li>
<li><a href="#trunksrcwpincludesblocksupportsgeneratedclassnamephp">trunk/src/wp-includes/block-supports/generated-classname.php</a></li>
<li><a href="#trunksrcwpincludesblocksupportstypographyphp">trunk/src/wp-includes/block-supports/typography.php</a></li>
<li><a href="#trunksrcwpincludesfunctionsphp">trunk/src/wp-includes/functions.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblocksupportsalignphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/block-supports/align.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-supports/align.php 2020-11-12 19:34:55 UTC (rev 49579)
+++ trunk/src/wp-includes/block-supports/align.php 2020-11-12 20:18:08 UTC (rev 49580)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -15,7 +15,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_register_alignment_support( $block_type ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $has_align_support = false;
</span><span class="cx" style="display: block; padding: 0 10px"> if ( property_exists( $block_type, 'supports' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $has_align_support = wp_array_get( $block_type->supports, array( 'align' ), false );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $has_align_support = _wp_array_get( $block_type->supports, array( 'align' ), false );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $has_align_support ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $block_type->attributes ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -46,7 +46,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $attributes = array();
</span><span class="cx" style="display: block; padding: 0 10px"> $has_align_support = false;
</span><span class="cx" style="display: block; padding: 0 10px"> if ( property_exists( $block_type, 'supports' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $has_align_support = wp_array_get( $block_type->supports, array( 'align' ), false );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $has_align_support = _wp_array_get( $block_type->supports, array( 'align' ), false );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $has_align_support ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $has_block_alignment = array_key_exists( 'align', $block_attributes );
</span></span></pre></div>
<a id="trunksrcwpincludesblocksupportscolorsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/block-supports/colors.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-supports/colors.php 2020-11-12 19:34:55 UTC (rev 49579)
+++ trunk/src/wp-includes/block-supports/colors.php 2020-11-12 20:18:08 UTC (rev 49580)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -15,11 +15,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_register_colors_support( $block_type ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $color_support = false;
</span><span class="cx" style="display: block; padding: 0 10px"> if ( property_exists( $block_type, 'supports' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $color_support = wp_array_get( $block_type->supports, array( '__experimentalColor' ), false );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $color_support = _wp_array_get( $block_type->supports, array( '__experimentalColor' ), false );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $has_text_colors_support = true === $color_support || ( is_array( $color_support ) && wp_array_get( $color_support, array( 'text' ), true ) );
- $has_background_colors_support = true === $color_support || ( is_array( $color_support ) && wp_array_get( $color_support, array( 'background' ), true ) );
- $has_gradients_support = wp_array_get( $color_support, array( 'gradients' ), false );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $has_text_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'text' ), true ) );
+ $has_background_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'background' ), true ) );
+ $has_gradients_support = _wp_array_get( $color_support, array( 'gradients' ), false );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $block_type->attributes ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $block_type->attributes = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -63,11 +63,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array Colors CSS classes and inline styles.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_apply_colors_support( $block_type, $block_attributes ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $color_support = wp_array_get( $block_type->supports, array( '__experimentalColor' ), false );
- $has_text_colors_support = true === $color_support || ( is_array( $color_support ) && wp_array_get( $color_support, array( 'text' ), true ) );
- $has_background_colors_support = true === $color_support || ( is_array( $color_support ) && wp_array_get( $color_support, array( 'background' ), true ) );
- $has_link_colors_support = wp_array_get( $color_support, array( 'linkColor' ), false );
- $has_gradients_support = wp_array_get( $color_support, array( 'gradients' ), false );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $color_support = _wp_array_get( $block_type->supports, array( '__experimentalColor' ), false );
+ $has_text_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'text' ), true ) );
+ $has_background_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'background' ), true ) );
+ $has_link_colors_support = _wp_array_get( $color_support, array( 'linkColor' ), false );
+ $has_gradients_support = _wp_array_get( $color_support, array( 'gradients' ), false );
</ins><span class="cx" style="display: block; padding: 0 10px"> $classes = array();
</span><span class="cx" style="display: block; padding: 0 10px"> $styles = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwpincludesblocksupportscustomclassnamephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/block-supports/custom-classname.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-supports/custom-classname.php 2020-11-12 19:34:55 UTC (rev 49579)
+++ trunk/src/wp-includes/block-supports/custom-classname.php 2020-11-12 20:18:08 UTC (rev 49580)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -15,7 +15,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_register_custom_classname_support( $block_type ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $has_custom_classname_support = true;
</span><span class="cx" style="display: block; padding: 0 10px"> if ( property_exists( $block_type, 'supports' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $has_custom_classname_support = wp_array_get( $block_type->supports, array( 'customClassName' ), true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $has_custom_classname_support = _wp_array_get( $block_type->supports, array( 'customClassName' ), true );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $has_custom_classname_support ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $block_type->attributes ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -44,7 +44,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $has_custom_classname_support = true;
</span><span class="cx" style="display: block; padding: 0 10px"> $attributes = array();
</span><span class="cx" style="display: block; padding: 0 10px"> if ( property_exists( $block_type, 'supports' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $has_custom_classname_support = wp_array_get( $block_type->supports, array( 'customClassName' ), true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $has_custom_classname_support = _wp_array_get( $block_type->supports, array( 'customClassName' ), true );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $has_custom_classname_support ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $has_custom_classnames = array_key_exists( 'className', $block_attributes );
</span></span></pre></div>
<a id="trunksrcwpincludesblocksupportsgeneratedclassnamephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/block-supports/generated-classname.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-supports/generated-classname.php 2020-11-12 19:34:55 UTC (rev 49579)
+++ trunk/src/wp-includes/block-supports/generated-classname.php 2020-11-12 20:18:08 UTC (rev 49580)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -47,7 +47,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $has_generated_classname_support = true;
</span><span class="cx" style="display: block; padding: 0 10px"> $attributes = array();
</span><span class="cx" style="display: block; padding: 0 10px"> if ( property_exists( $block_type, 'supports' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $has_generated_classname_support = wp_array_get( $block_type->supports, array( 'className' ), true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $has_generated_classname_support = _wp_array_get( $block_type->supports, array( 'className' ), true );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $has_generated_classname_support ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $block_classname = wp_get_block_default_classname( $block_type->name );
</span></span></pre></div>
<a id="trunksrcwpincludesblocksupportstypographyphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/block-supports/typography.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-supports/typography.php 2020-11-12 19:34:55 UTC (rev 49579)
+++ trunk/src/wp-includes/block-supports/typography.php 2020-11-12 20:18:08 UTC (rev 49580)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -15,12 +15,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_register_typography_support( $block_type ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $has_font_size_support = false;
</span><span class="cx" style="display: block; padding: 0 10px"> if ( property_exists( $block_type, 'supports' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $has_font_size_support = wp_array_get( $block_type->supports, array( '__experimentalFontSize' ), false );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $has_font_size_support = _wp_array_get( $block_type->supports, array( '__experimentalFontSize' ), false );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $has_line_height_support = false;
</span><span class="cx" style="display: block; padding: 0 10px"> if ( property_exists( $block_type, 'supports' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $has_line_height_support = wp_array_get( $block_type->supports, array( '__experimentalLineHeight' ), false );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $has_line_height_support = _wp_array_get( $block_type->supports, array( '__experimentalLineHeight' ), false );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $block_type->attributes ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -56,12 +56,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $classes = array();
</span><span class="cx" style="display: block; padding: 0 10px"> $styles = array();
</span><span class="cx" style="display: block; padding: 0 10px"> if ( property_exists( $block_type, 'supports' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $has_font_size_support = wp_array_get( $block_type->supports, array( 'fontSize' ), false );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $has_font_size_support = _wp_array_get( $block_type->supports, array( 'fontSize' ), false );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $has_line_height_support = false;
</span><span class="cx" style="display: block; padding: 0 10px"> if ( property_exists( $block_type, 'supports' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $has_line_height_support = wp_array_get( $block_type->supports, array( 'lineHeight' ), false );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $has_line_height_support = _wp_array_get( $block_type->supports, array( 'lineHeight' ), false );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Font Size.
</span></span></pre></div>
<a id="trunksrcwpincludesfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/functions.php 2020-11-12 19:34:55 UTC (rev 49579)
+++ trunk/src/wp-includes/functions.php 2020-11-12 20:18:08 UTC (rev 49580)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4528,30 +4528,46 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Accesses an array in depth based on a path of keys.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * It is the PHP equivalent of JavaScript's lodash.get, and mirroring it may help other components
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * It is the PHP equivalent of JavaScript's `lodash.get()` and mirroring it may help other components
</ins><span class="cx" style="display: block; padding: 0 10px"> * retain some symmetry between client and server implementations.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Example usage:
+ *
+ * $array = array(
+ * 'a' => array(
+ * 'b' => array(
+ * 'c' => 1,
+ * ),
+ * ),
+ * );
+ * _wp_array_get( $array, array( 'a', 'b', 'c' );
+ *
+ * @internal
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @since 5.6.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @access private
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $array An array from which we want to retrieve some information.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $path An array of keys describing the path with which to retrieve information.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @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.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param mixed $default The return value if the path does not exist within the array,
+ * or if `$array` or `$path` are not arrays.
+ * @return mixed The value from the path specified.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-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 ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function _wp_array_get( $array, $path, $default = null ) {
+ // Confirm $path is valid.
+ if ( ! is_array( $path ) || 0 === count( $path ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return $default;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $path_length = count( $path );
-
- for ( $i = 0; $i < $path_length; ++$i ) {
- if ( ! isset( $array[ $path[ $i ] ] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ foreach ( $path as $path_element ) {
+ if (
+ ! is_array( $array ) ||
+ ( ! is_string( $path_element ) && ! is_integer( $path_element ) && ! is_null( $path_element ) ) ||
+ ! array_key_exists( $path_element, $array )
+ ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return $default;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $array = $array[ $path[ $i ] ];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $array = $array[ $path_element ];
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $array;
</span></span></pre>
</div>
</div>
</body>
</html>