PluginProbe
WP Safe Mode / 1.0
WP Safe Mode v1.0
trunk 1.0 1.1 1.2 1.3
wp-safe-mode / wp-safe-mode.php

wp-safe-mode.php in WP Safe Mode 1.0, at wp-safe-mode.php

107 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WP Safe Mode
4 Version: 1.0
5 Plugin URI: http://wordpress.org/plugins/wp-safe-mode/
6 Description: Safe mode for debugging WordPress issues, without destroying your site for other visitors.
7 Author: Marcus Sykes
8 Author URI: http://msyk.es
9 Text Domain: wp-safe-mode
10 Network: true
11 */
12
13 /*
14 Copyright (c) 2018, Marcus Sykes
15
16 This program is free software; you can redistribute it and/or
17 modify it under the terms of the GNU General Public License
18 as published by the Free Software Foundation; either version 2
19 of the License, or (at your option) any later version.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 */
30 /**
31 *
32 */
33 define('WP_SAFE_MODE_VERSION', '1.0');
34
35 if( is_admin() ){
36 include_once('wp-safe-mode-admin.php');
37 }
38
39 /**
40 * Add safe mode menu item to admin bar.
41 * @param WP_Admin_Bar $wp_admin_bar
42 */
43 function wp_safe_mode_settings_admin_bar_menu( $wp_admin_bar ){
44 //Settings Link
45 if( class_exists('WP_Safe_Mode') && WP_Safe_Mode::can_user_enable() ){
46 $settings_url = is_network_admin() || !WP_Safe_Mode::$multisite_single_site ? network_admin_url('admin.php?page=wp-safe-mode') : admin_url('admin.php?page=wp-safe-mode');
47 $wp_admin_bar->add_node( array(
48 'id' => 'wp-safe-mode-settings',
49 'parent' => 'wp-safe-mode',
50 'title' => esc_html__('Safe Mode Settings', 'wp-safe-mode'),
51 'href' => $settings_url,
52 ) );
53 if( is_multisite() ){
54 $wp_admin_bar->add_menu( array(
55 'parent' => 'network-admin',
56 'id' => 'network-admin-wp-safe-mode',
57 'title' => esc_html__('Safe Mode Settings', 'wp-safe-mode'),
58 'href' => network_admin_url('admin.php?page=wp-safe-mode'),
59 ) );
60 }
61 }
62 }
63 add_action('admin_bar_menu', 'wp_safe_mode_settings_admin_bar_menu', 9999, 1);
64
65 function wp_safe_mode_activation() {
66 if( !class_exists('WP_Safe_Mode_Admin') ){
67 include('wp-safe-mode-admin.php');
68 }
69 //install default settings
70 WP_Safe_Mode_Admin::install_default_settings();
71 //try to install the loader
72 $wp_config = WP_Safe_Mode_Admin::toggle_wp_config( true );
73 $file = WP_Safe_Mode_Admin::toggle_file( true );
74 if( !$wp_config || !$file ){
75 $settings = get_site_option('wp_safe_mode_settings', array());
76 $settings['installation_error'] = true;
77 update_site_option('wp_safe_mode_settings', $settings);
78 }
79 }
80 register_activation_hook( __FILE__, 'wp_safe_mode_activation' );
81
82 /**
83 * Deactivation hook which deletes the bootstrap file and removes the custom Must-Use plugins folder constant from wp-config.php
84 */
85 function wp_safe_mode_deactivation(){
86 include_once('wp-safe-mode-admin.php');
87 WP_Safe_Mode_Admin::toggle_file( false );
88 WP_Safe_Mode_Admin::toggle_wp_config( false );
89 }
90 register_deactivation_hook( __FILE__, 'wp_safe_mode_deactivation' );
91
92 /**
93 * Uninstallation hook, deletes all WP Safe Mode settings, including sites in a MultiSite Network.
94 */
95 function wp_safe_mode_uninstall(){
96 //delete settings
97 if( is_multisite() ){
98 delete_site_option('wp_safe_mode_settings'); //delete network options
99 //delete options from all sites
100 foreach( get_sites( array('fields'=>'ids') ) as $site_id ){
101 delete_blog_option( $site_id, 'wp_safe_mode_settings' );
102 }
103 }else{
104 delete_option('wp_safe_mode_settings');
105 }
106 }
107 register_uninstall_hook(__FILE__, 'wp_safe_mode_uninstall');