| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: WP Safe Mode |
| 4 |
Version: 1.3 |
| 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: Pixelite |
| 8 |
Author URI: http://pixelite.com |
| 9 |
Text Domain: wp-safe-mode |
| 10 |
Network: true |
| 11 |
*/ |
| 12 |
|
| 13 |
/* |
| 14 |
Copyright (c) 2022, 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.3'); |
| 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_Safe_Mode_Admin::toggle_loader_install( true ); |
| 73 |
} |
| 74 |
register_activation_hook( __FILE__, 'wp_safe_mode_activation' ); |
| 75 |
|
| 76 |
/** |
| 77 |
* Deactivation hook which deletes the bootstrap file and removes the custom Must-Use plugins folder constant from wp-config.php |
| 78 |
*/ |
| 79 |
function wp_safe_mode_deactivation(){ |
| 80 |
include_once('wp-safe-mode-admin.php'); |
| 81 |
WP_Safe_Mode_Admin::toggle_loader_install( false ); |
| 82 |
} |
| 83 |
register_deactivation_hook( __FILE__, 'wp_safe_mode_deactivation' ); |
| 84 |
|
| 85 |
/** |
| 86 |
* Uninstallation hook, deletes all WP Safe Mode settings, including sites in a MultiSite Network. |
| 87 |
*/ |
| 88 |
function wp_safe_mode_uninstall(){ |
| 89 |
//delete settings |
| 90 |
if( is_multisite() ){ |
| 91 |
delete_site_option('wp_safe_mode_settings'); //delete network options |
| 92 |
//delete options from all sites |
| 93 |
foreach( get_sites( array('fields'=>'ids') ) as $site_id ){ |
| 94 |
delete_blog_option( $site_id, 'wp_safe_mode_settings' ); |
| 95 |
} |
| 96 |
}else{ |
| 97 |
delete_option('wp_safe_mode_settings'); |
| 98 |
} |
| 99 |
} |
| 100 |
register_uninstall_hook(__FILE__, 'wp_safe_mode_uninstall'); |