* @return void */ public function maybe_update_dropin() { if ( defined( 'WP_REDIS_DISABLE_DROPIN_AUTOUPDATE' ) && WP_REDIS_DISABLE_DROPIN_AUTOUPDATE ) { return; } if ( $this->object_cache_dropin_outdated() ) { add_action( 'shutdown', [ $this, 'update_dropin' ] ); } } /** * Redirects to the plugin settings if the plugin was just activated * * @return void */ public function maybe_redirect() { if ( ! get_transient( '_rediscache_activation_redirect' ) ) { return; } if ( ! $this->current_user_can_manage_redis() ) { return; } delete_transient( '_rediscache_activation_redirect' ); wp_safe_redirect( network_admin_url( $this->page ) ); } /** * Updates the `object-cache.php` drop-in * * @return void */ public function update_dropin() { global $wp_filesystem; if ( ! $this->validate_object_cache_dropin() ) { return; } if ( $this->initialize_filesystem( '', true ) ) { $result = $wp_filesystem->copy( WP_REDIS_PLUGIN_PATH . '/includes/object-cache.php', WP_CONTENT_DIR . '/object-cache.php', true, FS_CHMOD_FILE ); /** * Fires on cache enable event * * @since 1.3.5 * @param bool $result Whether the filesystem event (copy of the `object-cache.php` file) was successful. */ do_action( 'redis_object_cache_update_dropin', $result ); } } /** * Plugin activation hook * * @return void */ public static function on_activation() { set_transient( '_rediscache_activation_redirect', 1, 30 ); } /** * Plugin deactivation hook * * @param string $plugin Plugin basename. * @return void */ public function on_deactivation( $plugin ) { global $wp_filesystem; ob_start(); if ( $plugin === WP_REDIS_BASENAME ) { $timestamp = wp_next_scheduled( 'rediscache_discard_metrics' ); if ( $timestamp ) { wp_unschedule_event( $timestamp, 'rediscache_discard_metrics' ); } (new Predis)->flush(); if ( $this->validate_object_cache_dropin() && $this->initialize_filesystem( '', true ) ) { $wp_filesystem->delete( WP_CONTENT_DIR . '/object-cache.php' ); } } ob_end_clean(); } /** * Helper method to retrieve a nonced plugin action link * * @param string $action The action to be executed once the link is followed. * @return string */ public function action_link( $action ) { if ( ! in_array( $action, $this->actions, true ) ) { return ''; } return wp_nonce_url( network_admin_url( add_query_arg( 'action', $action, $this->page ) ), $action ); } /** * Obscure `password` URL parameter. * * @param string $url * @return string */ public function obscure_url_secrets( $url ) { return preg_replace( '/password=[^&]+/', 'password=*****', (string) $url ); } /** * The capability required to manage Redis. * * @return string */ public function manage_redis_capability() { return is_multisite() ? 'manage_network_options' : 'manage_options'; } /** * Does the current user have the capability to manage Redis? * * @return bool */ public function current_user_can_manage_redis() { return current_user_can( $this->manage_redis_capability() ); } /** * Prevent LiteSpeed Cache from overwriting the `object-cache.php` drop-in. * * @return void */ public function litespeed_disable_objectcache() { if ( isset( $_POST['LSCWP_CTRL'], $_POST['LSCWP_NONCE'], $_POST['object'] ) ) { $_POST['object'] = '0'; } } /** * Returns `true` if the plugin was installed by AccelerateWP from CloudLinux. * * @param bool $ignore_banner_constant * @return bool */ public static function acceleratewp_install( $ignore_banner_constant = false ) { $path = defined( 'WP_REDIS_PATH' ) ? WP_REDIS_PATH : null; $scheme = defined( 'WP_REDIS_SCHEME' ) ? WP_REDIS_SCHEME : null; if ( $scheme === 'unix' && strpos( (string) $path, '.clwpos/redis.sock' ) !== false ) { if ( $ignore_banner_constant ) { return true; } else { return defined( 'WP_REDIS_DISABLE_BANNERS' ) && WP_REDIS_DISABLE_BANNERS; } } return false; } }