Skip to content

Commit 1720cf2

Browse files
committed
Fixes type error in /includes/class-acf-data.php
* Updated `_key()` to first verify that the provided key is a string or integer before accessing aliases. * Updated `get()` to verify the derived key is valid before accessing the data array. Signed-off-by: mavrokordato <info@wordpress-premium.net>
1 parent 2be073e commit 1720cf2

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

includes/class-acf-data.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,17 @@ function prop( $name = '', $value = null ) {
9393
* @return type Description.
9494
*/
9595
function _key( $name = '' ) {
96-
return isset( $this->aliases[ $name ] ) ? $this->aliases[ $name ] : $name;
96+
// Check if $name is a valid array key type
97+
if (!is_string($name) && !is_int($name)) {
98+
return $name;
99+
}
100+
101+
// Check if aliases property is an array and the key exists
102+
if (is_array($this->aliases) && isset($this->aliases[$name])) {
103+
return $this->aliases[$name];
104+
}
105+
106+
return $name;
97107
}
98108

99109
/**
@@ -139,16 +149,20 @@ function is( $key = '' ) {
139149
* @return mixed
140150
*/
141151
function get( $name = false ) {
142-
143152
// Get all.
144153
if ( $name === false ) {
145154
return $this->data;
155+
}
146156

147-
// Get specific.
148-
} else {
149-
$key = $this->_key( $name );
150-
return isset( $this->data[ $key ] ) ? $this->data[ $key ] : null;
157+
// Get specific.
158+
$key = $this->_key( $name );
159+
160+
// Check if $key is a valid array key type and data exists
161+
if ((is_string($key) || is_int($key)) && is_array($this->data) && isset($this->data[$key])) {
162+
return $this->data[$key];
151163
}
164+
165+
return null;
152166
}
153167

154168
/**

0 commit comments

Comments
 (0)