Skip to content

Commit

Permalink
_has and _get return default values
Browse files Browse the repository at this point in the history
  • Loading branch information
adampatterson committed Jan 9, 2022
1 parent eb549a1 commit e4f9e72
Showing 1 changed file with 14 additions and 35 deletions.
49 changes: 14 additions & 35 deletions src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,57 +524,36 @@ function make_slug($string)
/*
* Helpers for working with ACF data objects
*/
if (class_exists('Arr')) {
if ( ! function_exists('_get')) {
/**
* @param $haystack
* @param $needle
* @param null $default
*
* @return mixed
*/
function _get($haystack, $needle, $default = null)
{
return Arr::get($haystack, $needle, $default);
}
}

if ( ! function_exists('_has')) {
/**
* @param $haystack
* @param $needle
* @param false $default
*
* @return bool|mixed
*/
function _has($haystack, $needle, $default = false)
{
if (Arr::get($haystack, $needle, false)) {
return true;
}

return $default;
}
}
} else {
if ( ! function_exists('_get')) {
/**
* @param $haystack
* @param $needle
* @param null $default
*
* @return mixed
*/
function _get($haystack, $needle, $default = null)
{
echo "Run composer install";
return Arr::get($haystack, $needle, $default);
}
}

if ( ! function_exists('_has')) {
/**
* @param $haystack
* @param $needle
* @param null $default
* @param false $default
*
* @return bool|mixed
*/
function _has($haystack, $needle, $default = false)
{
echo "Run composer install";
if (Arr::has($haystack, $needle, false) && Arr::get($haystack, $needle, false) !== '') {
return true;
}

return $default;
}
}

Expand Down

0 comments on commit e4f9e72

Please sign in to comment.