@@ -556,100 +556,132 @@ private function get_cache_file_path( $key, $group ) {
556556/**
557557 * Core cache functions implementation.
558558 */
559- if ( function_exists ( 'wp_cache_init ' ) ) {
560- // Should not happen except in PHPUnit tests.
561- return ;
562- }
563559
564560// phpcs:disable NeutronStandard.Globals.DisallowGlobalFunctions.GlobalFunctions
565561// phpcs:disable Squiz.Commenting.FunctionComment.Missing
566562// phpcs:ignore PHPCompatibility.Constants.NewConstants.phpstan_configFound
567563
568- function wp_cache_init () { // phpcs:ignore Universal.Files.SeparateFunctionsFromOO.Mixed
569- $ GLOBALS ['wp_object_cache ' ] = Object_Cache_Annihilator::instance ();
570- wp_using_ext_object_cache ( true );
564+ if ( ! function_exists ( 'wp_cache_init ' ) ) {
565+ function wp_cache_init () { // phpcs:ignore Universal.Files.SeparateFunctionsFromOO.Mixed
566+ $ GLOBALS ['wp_object_cache ' ] = Object_Cache_Annihilator::instance ();
567+ wp_using_ext_object_cache ( true );
568+ }
571569}
572570
573- function wp_cache_add ( $ key , $ data , $ group = '' , $ expire = 0 ) {
574- global $ wp_object_cache ;
575- return $ wp_object_cache ->add ( $ key , $ data , $ group , $ expire );
571+ if ( ! function_exists ( 'wp_cache_add ' ) ) {
572+ function wp_cache_add ( $ key , $ data , $ group = '' , $ expire = 0 ) {
573+ global $ wp_object_cache ;
574+ return $ wp_object_cache ->add ( $ key , $ data , $ group , $ expire );
575+ }
576576}
577577
578- function wp_cache_add_global_groups ( $ groups ) {
579- global $ wp_object_cache ;
580- $ wp_object_cache ->add_global_groups ( $ groups );
578+ if ( ! function_exists ( 'wp_cache_add_global_groups ' ) ) {
579+ function wp_cache_add_global_groups ( $ groups ) {
580+ global $ wp_object_cache ;
581+ $ wp_object_cache ->add_global_groups ( $ groups );
582+ }
581583}
582584
583- function wp_cache_add_non_persistent_groups ( $ groups ) {
584- global $ wp_object_cache ;
585- $ wp_object_cache ->add_non_persistent_groups ( $ groups );
585+ if ( ! function_exists ( 'wp_cache_add_non_persistent_groups ' ) ) {
586+ function wp_cache_add_non_persistent_groups ( $ groups ) {
587+ global $ wp_object_cache ;
588+ $ wp_object_cache ->add_non_persistent_groups ( $ groups );
589+ }
586590}
587591
588- function wp_cache_incr ( $ key , $ offset = 1 , $ group = '' ) {
589- global $ wp_object_cache ;
590- return $ wp_object_cache ->incr ( $ key , $ offset , $ group );
592+ if ( ! function_exists ( 'wp_cache_incr ' ) ) {
593+ function wp_cache_incr ( $ key , $ offset = 1 , $ group = '' ) {
594+ global $ wp_object_cache ;
595+ return $ wp_object_cache ->incr ( $ key , $ offset , $ group );
596+ }
591597}
592598
593- function wp_cache_decr ( $ key , $ offset = 1 , $ group = '' ) {
594- global $ wp_object_cache ;
595- return $ wp_object_cache ->decr ( $ key , $ offset , $ group );
599+ if ( ! function_exists ( 'wp_cache_decr ' ) ) {
600+ function wp_cache_decr ( $ key , $ offset = 1 , $ group = '' ) {
601+ global $ wp_object_cache ;
602+ return $ wp_object_cache ->decr ( $ key , $ offset , $ group );
603+ }
596604}
597605
598- function wp_cache_switch_to_blog ( $ blog_id ) {
599- global $ wp_object_cache ;
600- $ wp_object_cache ->switch_to_blog ( $ blog_id );
606+ if ( ! function_exists ( 'wp_cache_switch_to_blog ' ) ) {
607+ function wp_cache_switch_to_blog ( $ blog_id ) {
608+ global $ wp_object_cache ;
609+ $ wp_object_cache ->switch_to_blog ( $ blog_id );
610+ }
601611}
602612
603- function wp_cache_get ( $ key , $ group = '' , $ force = false , &$ found = null ) {
604- global $ wp_object_cache ;
605- return $ wp_object_cache ->get ( $ key , $ group , $ force , $ found );
613+ if ( ! function_exists ( 'wp_cache_get ' ) ) {
614+ function wp_cache_get ( $ key , $ group = '' , $ force = false , &$ found = null ) {
615+ global $ wp_object_cache ;
616+ return $ wp_object_cache ->get ( $ key , $ group , $ force , $ found );
617+ }
606618}
607619
608- function wp_cache_get_multiple ( $ keys , $ group = '' , $ force = false ) {
609- global $ wp_object_cache ;
610- return $ wp_object_cache ->get_multiple ( $ keys , $ group , $ force );
620+ if ( ! function_exists ( 'wp_cache_get_multiple ' ) ) {
621+ function wp_cache_get_multiple ( $ keys , $ group = '' , $ force = false ) {
622+ global $ wp_object_cache ;
623+ return $ wp_object_cache ->get_multiple ( $ keys , $ group , $ force );
624+ }
611625}
612626
613- function wp_cache_set ( $ key , $ data , $ group = '' , $ expire = 0 ) {
614- global $ wp_object_cache ;
615- return $ wp_object_cache ->set ( $ key , $ data , $ group , $ expire );
627+ if ( ! function_exists ( 'wp_cache_set ' ) ) {
628+ function wp_cache_set ( $ key , $ data , $ group = '' , $ expire = 0 ) {
629+ global $ wp_object_cache ;
630+ return $ wp_object_cache ->set ( $ key , $ data , $ group , $ expire );
631+ }
616632}
617633
618- function wp_cache_set_multiple ( $ items , $ group = '' , $ expire = 0 ) {
619- global $ wp_object_cache ;
620- return $ wp_object_cache ->set_multiple ( $ items , $ group , $ expire );
634+ if ( ! function_exists ( 'wp_cache_set_multiple ' ) ) {
635+ function wp_cache_set_multiple ( $ items , $ group = '' , $ expire = 0 ) {
636+ global $ wp_object_cache ;
637+ return $ wp_object_cache ->set_multiple ( $ items , $ group , $ expire );
638+ }
621639}
622640
623- function wp_cache_delete ( $ key , $ group = '' ) {
624- global $ wp_object_cache ;
625- return $ wp_object_cache ->delete ( $ key , $ group );
641+ if ( ! function_exists ( 'wp_cache_delete ' ) ) {
642+ function wp_cache_delete ( $ key , $ group = '' ) {
643+ global $ wp_object_cache ;
644+ return $ wp_object_cache ->delete ( $ key , $ group );
645+ }
626646}
627647
628- function wp_cache_delete_multiple ( $ keys , $ group = '' ) {
629- global $ wp_object_cache ;
630- return $ wp_object_cache ->delete_multiple ( $ keys , $ group );
648+ if ( ! function_exists ( 'wp_cache_delete_multiple ' ) ) {
649+ function wp_cache_delete_multiple ( $ keys , $ group = '' ) {
650+ global $ wp_object_cache ;
651+ return $ wp_object_cache ->delete_multiple ( $ keys , $ group );
652+ }
631653}
632654
633- function wp_cache_add_multiple ( $ items , $ group = '' , $ expire = 0 ) {
634- global $ wp_object_cache ;
635- return $ wp_object_cache ->add_multiple ( $ items , $ group , $ expire );
655+ if ( ! function_exists ( 'wp_cache_add_multiple ' ) ) {
656+ function wp_cache_add_multiple ( $ items , $ group = '' , $ expire = 0 ) {
657+ global $ wp_object_cache ;
658+ return $ wp_object_cache ->add_multiple ( $ items , $ group , $ expire );
659+ }
636660}
637661
638- function wp_cache_flush_runtime () {
639- global $ wp_object_cache ;
640- return $ wp_object_cache ->flush_runtime ();
662+ if ( ! function_exists ( 'wp_cache_flush_runtime ' ) ) {
663+ function wp_cache_flush_runtime () {
664+ global $ wp_object_cache ;
665+ return $ wp_object_cache ->flush_runtime ();
666+ }
641667}
642668
643- function wp_cache_flush_group ( $ group ) {
644- global $ wp_object_cache ;
645- return $ wp_object_cache ->flush_group ( $ group );
669+ if ( ! function_exists ( 'wp_cache_flush_group ' ) ) {
670+ function wp_cache_flush_group ( $ group ) {
671+ global $ wp_object_cache ;
672+ return $ wp_object_cache ->flush_group ( $ group );
673+ }
646674}
647675
648- function wp_cache_close () {
649- return true ;
676+ if ( ! function_exists ( 'wp_cache_close ' ) ) {
677+ function wp_cache_close () {
678+ return true ;
679+ }
650680}
651681
652- function wp_cache_flush () {
653- global $ wp_object_cache ;
654- return $ wp_object_cache ->flush ();
682+ if ( ! function_exists ( 'wp_cache_flush ' ) ) {
683+ function wp_cache_flush () {
684+ global $ wp_object_cache ;
685+ return $ wp_object_cache ->flush ();
686+ }
655687}
0 commit comments