PluginProbe
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score / 1.0
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score v1.0
trunk 1.0 1.0.1 1.1 1.1.1 1.1.2 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1 2.1.1 2.1.2 2.2 2.2.1 All 69 releases
powered-cache / includes / class-powered-cache-object-cache.php

class-powered-cache-object-cache.php in Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score 1.0, at includes/class-powered-cache-object-cache.php

77 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 class Powered_Cache_Object_Cache {
8
9 /**
10 * Return an instance of the current class
11 *
12 * @since 1.0
13 * @return Powered_Cache_Object_Cache
14 */
15 public static function factory() {
16
17 static $instance;
18
19 if ( ! $instance ) {
20 $instance = new self();
21 $instance->setup();
22 }
23
24 return $instance;
25 }
26
27
28 /**
29 * Setup hooks
30 *
31 * @since 1.0
32 */
33 public function setup() {
34 add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ) );
35 add_action( 'admin_post_powered_cache_purge_object_cache', array( $this, 'purge_object_cache' ) );
36 }
37
38
39 /**
40 * Add purge button on admin bar
41 *
42 * @since 1.0
43 *
44 * @param $wp_admin_bar
45 */
46 public function admin_bar_menu( $wp_admin_bar ) {
47 $wp_admin_bar->add_menu( array(
48 'id' => 'object-cache-purge',
49 'title' => __( 'Purge Object Cache', 'powered-cache' ),
50 'href' => wp_nonce_url( admin_url( 'admin-post.php?action=powered_cache_purge_object_cache' ), 'powered_cache_purge_object_cache' ),
51 'parent' => 'powered-cache',
52 ) );
53 }
54
55
56 /**
57 * Purge object cache
58 *
59 * @since 1.0
60 */
61 public function purge_object_cache() {
62 if ( ! wp_verify_nonce( $_GET['_wpnonce'], 'powered_cache_purge_object_cache' ) ) {
63 wp_nonce_ays( '' );
64 }
65
66 if ( function_exists( 'wp_cache_flush' ) ) {
67 wp_cache_flush();
68 }
69
70 Powered_Cache_Admin_Helper::set_flash_message( __( 'Object cache deleted successfully!', 'powered-cache' ) );
71
72 wp_safe_redirect( wp_get_referer() );
73 die();
74 }
75
76
77 }