Created
November 4, 2014 21:02
-
-
Save lgladdy/3d16dcf87c1cec4c4b6d to your computer and use it in GitHub Desktop.
ACF 5.1.1 array_key_exists() fix
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
--- a/wp-content/plugins/advanced-custom-fields-pro/api/api-helpers.php | |
+++ b/wp-content/plugins/advanced-custom-fields-pro/api/api-helpers.php | |
@@ -841,6 +841,7 @@ function acf_extract_var( &$array, $key ) { | |
// vars | |
$r = null; | |
+ if (!is_array($array)) return false; | |
// check if exists | |
if( array_key_exists($key, $array) ) { |
Thanks @lgladdy
I've taken the logic and added it to the function. Now looks like:
function acf_extract_var( &$array, $key ) {
// check if exists
if( is_array($array) && array_key_exists($key, $array) ) {
// store value
$v = $array[ $key ];
// unset
unset( $array[ $key ] );
// return
return $v;
}
// return
return null;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code is executed when ACF tries to get a field value. If the field doesn't exist on the post_id, $array will be false when it's passed into acf_extract_var. This causes the array_key_error. There's no need to try and extract a value from false (or anything but an array)