WordPress.org

Make WordPress Core

Ticket #18593: harden-cache.diff

File harden-cache.diff, 2.4 KB (added by wonderboymusic, 7 years ago)

Patch for this ticket

  • wp-includes/cache.php

     
    2424function wp_cache_add($key, $data, $flag = '', $expire = 0) {
    2525        global $wp_object_cache;
    2626
    27         return $wp_object_cache->add($key, $data, $flag, $expire);
     27    if ( !empty( $wp_object_cache ) && method_exists( $wp_object_cache , 'add' ) )
     28        return $wp_object_cache->add($key, $data, $flag, $expire);
    2829}
    2930
    3031/**
     
    5758function wp_cache_delete($id, $flag = '') {
    5859        global $wp_object_cache;
    5960
    60         return $wp_object_cache->delete($id, $flag);
     61        if ( !empty( $wp_object_cache ) && method_exists( $wp_object_cache , 'delete' ) )
     62        return $wp_object_cache->delete($id, $flag);
    6163}
    6264
    6365/**
     
    7274function wp_cache_flush() {
    7375        global $wp_object_cache;
    7476
    75         return $wp_object_cache->flush();
     77        if ( !empty( $wp_object_cache ) && method_exists( $wp_object_cache , 'flush' ) )
     78        return $wp_object_cache->flush();
    7679}
    7780
    7881/**
     
    9093function wp_cache_get($id, $flag = '') {
    9194        global $wp_object_cache;
    9295
    93         return $wp_object_cache->get($id, $flag);
     96        if ( !empty( $wp_object_cache ) )
     97        return $wp_object_cache->get($id, $flag);
    9498}
    9599
    96100/**
     
    119123function wp_cache_replace($key, $data, $flag = '', $expire = 0) {
    120124        global $wp_object_cache;
    121125
    122         return $wp_object_cache->replace($key, $data, $flag, $expire);
     126        if ( !empty( $wp_object_cache ) && method_exists( $wp_object_cache , 'replace' ) )
     127        return $wp_object_cache->replace($key, $data, $flag, $expire);
    123128}
    124129
    125130/**
     
    138143function wp_cache_set($key, $data, $flag = '', $expire = 0) {
    139144        global $wp_object_cache;
    140145
    141         return $wp_object_cache->set($key, $data, $flag, $expire);
     146        if ( !empty( $wp_object_cache ) )
     147        return $wp_object_cache->set($key, $data, $flag, $expire);
    142148}
    143149
    144150/**
     
    151157function wp_cache_add_global_groups( $groups ) {
    152158        global $wp_object_cache;
    153159
    154         return $wp_object_cache->add_global_groups($groups);
     160        if ( !empty( $wp_object_cache ) && method_exists( $wp_object_cache , 'add_global_groups' ) )
     161        return $wp_object_cache->add_global_groups($groups);
    155162}
    156163
    157164/**
     
    175182function wp_cache_reset() {
    176183        global $wp_object_cache;
    177184
    178         return $wp_object_cache->reset();
     185        if ( !empty( $wp_object_cache ) && method_exists( $wp_object_cache , 'reset' ) )
     186        return $wp_object_cache->reset();
    179187}
    180188
    181189/**