-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug_bar_cache_lookup.php
87 lines (77 loc) · 2.74 KB
/
debug_bar_cache_lookup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Plugin Name: Debug Bar Cache Lookup
* Plugin URI: https://wordpress.org/plugins/debug-bar-cache-lookup/
* Description: Look up items in object cache. Requires Debug Bar Plugin.
* Version: 0.1.1
* Author: Allan Collins
* Author URI: http://www.allancollins.net/
* License: GPLv2+
* Text Domain: dbcl
* Domain Path: /languages
*/
/**
* Copyright (c) 2015 Allan Collins (email : [email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 or, at
* your discretion, any later version, as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Built using grunt-wp-plugin
* Copyright (c) 2013 10up, LLC
* https://github.com/10up/grunt-wp-plugin
*/
// Useful global constants
define( 'DBCL_VERSION', '0.1.0' );
define( 'DBCL_URL', plugin_dir_url( __FILE__ ) );
define( 'DBCL_PATH', dirname( __FILE__ ) . '/' );
/**
* Add the panel to the Debug Bar.
*
* @param array $panels Array of panel objects.
*
* @return array Array of panel objects.
*/
function dbcl_add_panel( $panels ) {
require DBCL_PATH . 'includes/class-debug-bar-cache-lookup.php';
array_push( $panels, new Debug_Bar_Cache_Lookup() );
return $panels;
}
add_filter( 'debug_bar_panels', 'dbcl_add_panel' );
/**
* Enqueue JavaScript, localization and stylesheet.
*/
function dbcl_enqueue() {
wp_enqueue_style( 'dbcl-css', DBCL_URL . 'assets/css/dbcl.css', array(), '20150113' );
wp_enqueue_script( 'dbcl-js', DBCL_URL . 'assets/js/dbcl.js', array( 'jquery' ), '20150113' );
wp_localize_script( 'dbcl-js', 'dbcl', array( 'security' => wp_create_nonce( "dbcl_security" ) ) );
}
add_action( 'debug_bar_enqueue_scripts', 'dbcl_enqueue' );
/**
* Ajax callback that retrieves the cache object information.
*/
function dbcl_ajax() {
check_ajax_referer( 'dbcl_security', 'security' );
$dbcl_key = filter_input( INPUT_POST, 'dbcl_key', FILTER_SANITIZE_STRING );
$dbcl_group = filter_input( INPUT_POST, 'dbcl_group', FILTER_SANITIZE_STRING );
$cache = wp_cache_get( $dbcl_key, $dbcl_group );
if ( ! $cache ) {
return wp_send_json_error();
}
ob_start();
print_r( $cache );
$cache = esc_html( ob_get_clean() );
return wp_send_json_success( array( 'cache' => $cache ) );
}
add_action( 'wp_ajax_dbcl', 'dbcl_ajax' );