-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
23r9i0
committed
Sep 16, 2016
1 parent
69626b2
commit 5899810
Showing
3 changed files
with
6 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
<?php | ||
/** | ||
* Like wp_parse_args but supports recursivity | ||
* Additionally converts the returned type based on the $args and $defaults | ||
* By default converts the returned type based on the $args and $defaults | ||
* | ||
* Inspired by NestedArray::mergeDeepArray ( Drupal ) | ||
* | ||
* @author Drupal | ||
* @author Sergio P.A. (23r9i0) <[email protected]> | ||
* | ||
* @license https://www.gnu.org/licenses/gpl-2.0.html GPL2 or later | ||
* | ||
* @version 1.0 | ||
* | ||
* @param array|object $args Values to merge with $defaults | ||
* @param array|object $defaults Array or Object that serves as the defaults. | ||
* @param boolean $preserve_type Optional. Convert output array into object if $args or $defaults if it is. Default true | ||
* @param boolean $preserve_integer_keys Optional. If given, integer keys will be preserved and merged instead of appended. Default false. | ||
* | ||
* @return array|object $output Merged user defined values with defaults. | ||
*/ | ||
if ( ! function_exists( 'wp_parse_args_recursive' ) ) { | ||
function wp_parse_args_recursive( $args, $defaults, $preserve_integer_keys = false ) { | ||
function wp_parse_args_recursive( $args, $defaults, $preserve_type = true, $preserve_integer_keys = false ) { | ||
$output = array(); | ||
|
||
foreach ( array( $defaults, $args ) as $list ) { | ||
|
@@ -38,6 +35,6 @@ function wp_parse_args_recursive( $args, $defaults, $preserve_integer_keys = fal | |
} | ||
} | ||
|
||
return ( is_object( $args ) || is_object( $defaults ) ) ? (object) $output : $output; | ||
return ( $preserve_type && ( is_object( $args ) || is_object( $defaults ) ) ) ? (object) $output : $output; | ||
} | ||
} |