PluginProbe
WP Debugging / 2.2.0
WP Debugging v2.2.0
2.12.6 2.12.5 trunk 2.10.0 2.10.1 2.10.2 2.11.0 2.11.1 2.11.10 2.11.11 2.11.12 2.11.13 2.11.14 2.11.15 2.11.16 2.11.17 2.11.18 2.11.19 2.11.2 2.11.20 2.11.21 2.11.22 2.11.23 2.11.24 2.11.3 All 59 releases
wp-debugging / src / Bootstrap.php

Bootstrap.php in WP Debugging 2.2.0, at src/Bootstrap.php

123 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WP Debugging
4 *
5 * @package wp-debugging
6 * @author Andy Fragen
7 * @license MIT
8 */
9
10 namespace Fragen\WP_Debugging;
11
12 /**
13 * Class Bootstrap
14 */
15 class Bootstrap {
16 /**
17 * Holds main plugin file.
18 *
19 * @var $file
20 */
21 protected $file;
22
23 /**
24 * Holds main plugin directory.
25 *
26 * @var $dir
27 */
28 protected $dir;
29
30 /**
31 * Holds plugin options.
32 *
33 * @var $options
34 */
35 protected static $options;
36
37 /**
38 * Constructor.
39 *
40 * @param string $file Main plugin file.
41 * @return void
42 */
43 public function __construct( $file ) {
44 $this->file = $file;
45 $this->dir = dirname( $file );
46 self::$options = get_site_option( 'wp_debugging', [ 'wp_debug' => '1' ] );
47 @ini_set( 'display_errors', 1 );
48 }
49
50 /**
51 * Let's get going.
52 *
53 * @return void
54 */
55 public function run() {
56 require_once $this->dir . '/vendor/autoload.php';
57 $this->load_hooks();
58 ( new Settings( self::$options ) )->load_hooks();
59 \WP_Dependency_Installer::instance()->run( $this->dir );
60 }
61
62 /**
63 * Load hooks.
64 *
65 * @return void
66 */
67 public function load_hooks() {
68 add_action(
69 'init',
70 function () {
71 load_plugin_textdomain( 'wp-debugging' );
72 }
73 );
74 add_filter(
75 'wp_dependency_timeout',
76 function ( $timeout, $source ) {
77 $timeout = basename( $this->dir ) !== $source ? $timeout : 45;
78
79 return $timeout;
80 },
81 10,
82 2
83 );
84
85 register_activation_hook( $this->file, [ $this, 'activate' ] );
86 register_deactivation_hook( $this->file, [ $this, 'deactivate' ] );
87 }
88
89 /**
90 * Run on activation.
91 * Reloads constants to wp-config.php, including saved options.
92 *
93 * @return void
94 */
95 public function activate() {
96 $config_transformer = new \WPConfigTransformer( ABSPATH . 'wp-config.php' );
97 $constants = [ 'wp_debug_log', 'script_debug', 'savequeries' ];
98 $constants = array_merge( array_keys( self::$options ), $constants );
99 $config_args = [
100 'raw' => true,
101 'normalize' => true,
102 ];
103 foreach ( $constants as $constant ) {
104 $value = 'wp_debug_display' === $constant ? 'false' : 'true';
105 $config_transformer->update( 'constant', strtoupper( $constant ), $value, $config_args );
106 }
107 }
108
109 /**
110 * Run on deactivation.
111 * Removes all added constants from wp-config.php.
112 *
113 * @return void
114 */
115 public function deactivate() {
116 $config_transformer = new \WPConfigTransformer( ABSPATH . 'wp-config.php' );
117 $constants = [ 'wp_debug_log', 'script_debug', 'savequeries', 'wp_debug', 'wp_debug_display', 'wp_disable_fatal_error_handler' ];
118 foreach ( $constants as $constant ) {
119 $config_transformer->remove( 'constant', strtoupper( $constant ) );
120 }
121 }
122 }
123