Support » Plugin: Redis Object Cache » FYI: Flush button script breaks update

  • Resolved Jagster_

    (@jagster_)


    I know this is not your issue, but it is UX-way 😉

    Quite widely used script that shows flush-button at admin-bar will break updates beginning v2.

    Have you considered to do something similar? Every now and then must flush the cache and route cia settings isn’t… stylish

    And I ment this one:

    # Check: https://onexa.nl/wordpress/toolbar-link-redis-object-cache/
    /**
     * Add a link to the Admin Toolbar to easily flush the Redis cache (Redis Object Cache plugin)
     * 
     * @author Hiranthi Herlaar, onexa.nl
     * 
     * @var $wp_admin_bar > https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
    **/
    function redis_add_toolbar_link( $wp_admin_bar )
    {
    	if ( current_user_can( 'manage_options' ) && is_plugin_active( 'redis-cache/redis-cache.php' ) )
    	{
    		$RedisObjectCache = new RedisObjectCache;
    		
    		if ( $RedisObjectCache->get_redis_status() )
    		{
    			
    			$RedisPage = is_multisite() ? 'settings.php?page=redis-cache' : 'options-general.php?page=redis-cache';
    			
    			// Flush Redis Cache trough WP Rocket Admin Bar Menu
    			$args = array(
    				'id'     => 'flush-redis-cache',
    				'title'  => __( 'Flush Redis Cache' ) . '',
    				'parent' => false,
    				'href'  => wp_nonce_url( network_admin_url( add_query_arg( 'action', 'flush-cache', $RedisPage ) ), 'flush-cache' )
    			);
    			
    			$wp_admin_bar->add_node( $args );
    		
    		} // end REDIS
    	}
    } // end add_toolbar_link
    add_action( 'admin_bar_menu', 'redis_add_toolbar_link', 999 );
    • This topic was modified 2 months, 1 week ago by Jagster_.
    • This topic was modified 2 months, 1 week ago by Jagster_.
    • This topic was modified 2 months, 1 week ago by Jan Dembowski. Reason: Formatting
Viewing 7 replies - 1 through 7 (of 7 total)
  • The class RedisObjectCache does not exist in version 2.x as we switched to namespaces.

    Could you please try the following?
    Change the line
    $RedisObjectCache = new RedisObjectCache;
    … to …
    $RedisObjectCache = Rhubarb\RedisCache::instance();

    And
    'href' => wp_nonce_url( network_admin_url( add_query_arg( 'action', 'flush-cache', $RedisPage ) ), 'flush-cache' )
    … to …
    'href' => $RedisObjectCache->action_link( 'flush-cache' )

    Sadly I am unable to test it a but there is a good chance that this might just work.

    Plugin Author Till Krüss

    (@tillkruess)

    Hi @jagster_,

    is this causing your site to crash, or is the button just not working.

    Feel free to submit a pull request:
    https://github.com/rhubarbgroup/redis-cache/issues/224

    Plugin Author Till Krüss

    (@tillkruess)

    @jagster_:

    Could you try adding this snippet above your redis_add_toolbar_link() function and see if it works again?

    
    if ( ! isset( $GLOBALS[ 'redisObjectCache' ] ) ) {
        $GLOBALS[ 'redisObjectCache' ] = Rhubarb\RedisCache\Plugin::instance();
    }
    
    if ( ! class_exists( 'RedisObjectCache' ) ) :
    
    class RedisObjectCache {
        public function get_redis_status() {
            return Rhubarb\RedisCache\Plugin::instance()->get_redis_status();
        }
    }
    
    endif;
    

    I had this script in use in 14 slightly different WordPress installs and all of them crashed.

    Sure, I’ll give a try.

    It worked. Well, I don’t know what will happend with that if trying do update from 1.6.x because all of my sites use already 2.0.2.

    BTW, metrics works just fine. Did you fix that or am I just lucky 😉

    • This reply was modified 2 months, 1 week ago by Jagster_.
    Plugin Author Till Krüss

    (@tillkruess)

    The metrics worked, just some weird corner cases failed. That’s fixed in v2.0.3, which was just released.

    I’ll include an Adminbar node with the next version, you can use the snippet above until then to fix your existing code.

    Feel free to chime in here: https://github.com/rhubarbgroup/redis-cache/issues/224

    Thanks!

    I’m really bad at git and Github. But I’ll comment something there.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.