-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug-tools.php
52 lines (39 loc) · 1.23 KB
/
debug-tools.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
<?php
/*
Plugin Name: Debug tools
Description: Lightweight debug/tuning tools intended for use on production servers.
Version: 1.0
Author: Jeff Brand
*/
if ( !function_exists( 'get_option' ) )
die( 'No direct access!' );
// Conditional loader. Don't load code unless we're active.
DFDebug_Loader::setup();
class DFDebug_Loader {
static function setup() {
define( 'DFDEBUG_DIR', dirname( __FILE__ ) );
define( 'DFDEBUG_URL', plugins_url( '', __FILE__ ) );
define( 'DFDEBUG_PARAM', apply_filters( 'dfdebug_param', 'DFDEBUG' ) );
add_action( 'plugins_loaded', array( __CLASS__, 'plugins_loaded' ), 1 );
}
static function plugins_loaded() {
if ( self::is_enabled() )
self::load();
}
static function is_enabled() {
// Enable for admins
$enabled = current_user_can( 'manage_options' );
//Enable if opted in
$uid = get_current_user_id();
if ( !$enabled && $uid != 0 )
$enabled = get_user_meta( $uid, 'dfdebug_enabled', true );
return apply_filters( 'dfdebug_enabled', $enabled );
}
static function load() {
global $dfdebug;
require( DFDEBUG_DIR . '/core.php' );
do_action( 'dfdebug_preinit' );
$dfdebug = new DFDebug();
do_action( 'dfdebug_init' );
}
}