diff --git a/src/wp-admin/menu.php b/src/wp-admin/menu.php index b63e925d799d..a9b89f3fcdeb 100644 --- a/src/wp-admin/menu.php +++ b/src/wp-admin/menu.php @@ -308,7 +308,14 @@ $submenu['backups.php'][15] = array( __( 'Create New' ), 'backup', 'backup-new.php' ); } -$_wp_last_utility_menu = 85; // The index of the last top-level menu in the utility menu group. +if ( ! is_multisite() ) { + $menu[90] = array( __( 'Debug tools' ), 'safe_mode', 'safe-mode.php', '', 'menu-top menu-icon-settings', 'menu-settings', 'dashicons-database' ); + if ( \calmpress\calmpress\Safe_Mode::current_user_in_safe_mode() ) { + $submenu['safe-mode.php'][10] = array( __( 'Safe Mode' ), 'safe_mode', 'safe-mode.php' ); + } +} + +$_wp_last_utility_menu = 90; // The index of the last top-level menu in the utility menu group. $menu[999] = array( '', 'read', 'separator-last', '', 'wp-menu-separator' ); diff --git a/src/wp-admin/safe-mode.php b/src/wp-admin/safe-mode.php new file mode 100644 index 000000000000..087345004f07 --- /dev/null +++ b/src/wp-admin/safe-mode.php @@ -0,0 +1,154 @@ +add_help_tab( + array( + 'id' => 'overview', + 'title' => __( 'Overview' ), + 'content' => + '
' . esc_html__( 'The safe mode enables you to investigate why your normal login fails while ptentially keeping the site running.' ) . '
', + ) +); + +require ABSPATH . 'wp-admin/admin-header.php'; + +?> + + + __DIR__ . '/object-cache/class-file.php', 'calmpress\object_cache\Null_Cache' => __DIR__ . '/object-cache/class-null-cache.php', 'calmpress\calmpress\Maintenance_Mode' => __DIR__ . '/calmpress/class-maintenance-mode.php', + 'calmpress\calmpress\Safe_Mode' => __DIR__ . '/calmpress/class-safe-mode.php', 'Psr\SimpleCache\CacheInterface' => ABSPATH . 'wp-includes/Psr/SimpleCache/CacheInterface.php', 'Psr\SimpleCache\CacheException' => ABSPATH . 'wp-includes/Psr/SimpleCache/CacheException.php', 'Psr\SimpleCache\InvalidArgumentException' => ABSPATH . 'wp-includes/Psr/SimpleCache/InvalidArgumentException.php', diff --git a/src/wp-includes/calmpress/calmpress/class-safe-mode.php b/src/wp-includes/calmpress/calmpress/class-safe-mode.php new file mode 100644 index 000000000000..e33e2dd36b36 --- /dev/null +++ b/src/wp-includes/calmpress/calmpress/class-safe-mode.php @@ -0,0 +1,185 @@ +' . __( 'You need additional permission.' ) . '' . + '' . __( 'Sorry, you are not allowed to manage safe mode for this site.' ) . '
', + 403 + ); + } + check_admin_referer( $action ); + } + + /** + * Handles the form post regarding content related maintenance page changes. Updates the + * post holding the content data. + * + * Used as a hook on admin-post. + * + * @since 1.0.0 + */ + public static function handle_content_change_post() { + $errors = []; + static::verify_post_request( 'maintenance_mode_content' ); + + if ( ! isset( $_POST['page_title'] ) || ! isset( $_POST['text_title'] ) || ! isset( $_POST['message_text'] ) ) { + $errors[] = esc_html__( 'Something went wrong, please try again' ); + } else { + static::set_page_title( wp_unslash( $_POST['page_title'] ) ); + static::set_text_title( wp_unslash( $_POST['text_title'] ) ); + static::set_content( wp_unslash( $_POST['message_text'] ) ); + static::set_use_theme_frame( isset( $_POST['theme_page'] ) ); + } + + set_transient( 'maintenance_mode_errors', $errors, 30 ); + + // Redirect back to the settings page that was submitted. + $goback = add_query_arg( 'settings-updated', 'true', wp_get_referer() ); + wp_redirect( $goback ); + exit; + } + + /** + * Handle the form post regarding maintenance mode (de)activation. Updates the activation state + * and/or the interval till expected end of it. + * + * Used as a hook on admin-post. + * + * @since 1.0.0 + */ + public static function handle_status_change_post() { + $errors = []; + static::verify_post_request( 'maintenance_mode_status' ); + + // Check basic validity. + if ( ! isset( $_POST['hours'] ) || ! isset( $_POST['minutes'] ) ) { + $errors[] = esc_html__( 'Something went wrong, please try again' ); + } else { + // Not putting much effort in validating the values as out of expected range + // values can not do any harm. + $hours = (int) wp_unslash( $_POST['hours'] ); + $minutes = (int) wp_unslash( $_POST['minutes'] ); + $end_time = time() + ( 60 * $hours + $minutes ) * 60; + static::set_projected_end_time( $end_time ); + + if ( isset( $_POST['enter'] ) ) { + static::activate(); + } + + if ( isset( $_POST['exit'] ) ) { + static::deactivate(); + } + } + + set_transient( 'maintenance_mode_errors', $errors, 30 ); + + // Redirect back to the settings page that was submitted. + $goback = add_query_arg( 'settings-updated', 'true', wp_get_referer() ); + wp_redirect( $goback ); + exit; + } +}