Skip to content

Commit 6e3ce42

Browse files
committed
Fix wp_using_ext_object_cache() return type and add early-load guard.
1 parent 051cae3 commit 6e3ce42

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

src/wp-includes/load.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -808,20 +808,31 @@ function wp_set_wpdb_vars() {
808808
* @return bool The current 'using' setting.
809809
*/
810810
function wp_using_ext_object_cache( $using = null ) {
811-
global $_wp_using_ext_object_cache;
811+
global $_wp_using_ext_object_cache;
812812

813-
// Save the current state to return later.
814-
$current_using = $_wp_using_ext_object_cache;
813+
// Save the current state to return later.
814+
$current_using = $_wp_using_ext_object_cache;
815815

816-
if ( null !== $using ) {
817-
$_wp_using_ext_object_cache = (bool) $using;
818-
}
816+
if ( null !== $using ) {
817+
$_wp_using_ext_object_cache = (bool) $using;
818+
}
819+
820+
if ( null === $_wp_using_ext_object_cache ) {
821+
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
822+
trigger_error(
823+
sprintf(
824+
'%1$s was called incorrectly. This function should not be called before the object cache is initialized. (This message was added in version 7.1.0.)',
825+
__FUNCTION__
826+
),
827+
E_USER_NOTICE
828+
);
829+
}
830+
831+
// If the global is uninitialized, the value would be null, which violates the type signature.
832+
return false;
833+
}
819834

820-
/**
821-
* Ensure the returned value is always a boolean.
822-
* If the global is uninitialized, it could be null, which violates the type signature.
823-
*/
824-
return (bool) $current_using;
835+
return (bool) $current_using;
825836
}
826837

827838
/**

0 commit comments

Comments
 (0)