PluginProbe
Elementor Website Builder – more than just a page builder / 3.32.0-dev2
Elementor Website Builder – more than just a page builder v3.32.0-dev2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / modules / safe-mode / mu-plugin / elementor-safe-mode.php

elementor-safe-mode.php in Elementor Website Builder – more than just a page builder 3.32.0-dev2, at modules/safe-mode/mu-plugin/elementor-safe-mode.php

136 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Elementor Safe Mode
4 * Description: Safe Mode allows you to troubleshoot issues by only loading the editor, without loading the theme or any other plugin.
5 * Plugin URI: https://elementor.com/?utm_source=safe-mode&utm_campaign=plugin-uri&utm_medium=wp-dash
6 * Author: Elementor.com
7 * Version: 1.0.0
8 * Author URI: https://elementor.com/?utm_source=safe-mode&utm_campaign=author-uri&utm_medium=wp-dash
9 *
10 * Text Domain: elementor
11 *
12 * @package Elementor
13 * @category Safe Mode
14 *
15 * Elementor is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * any later version.
19 *
20 * Elementor is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 */
25
26 if ( ! defined( 'ABSPATH' ) ) {
27 exit; // Exit if accessed directly.
28 }
29
30 class Safe_Mode {
31
32 const OPTION_ENABLED = 'elementor_safe_mode';
33 const OPTION_TOKEN = self::OPTION_ENABLED . '_token';
34
35 public function is_enabled() {
36 return get_option( self::OPTION_ENABLED );
37 }
38
39 public function is_valid_token() {
40 $token = isset( $_COOKIE[ self::OPTION_TOKEN ] )
41 ? wp_kses_post( wp_unslash( $_COOKIE[ self::OPTION_TOKEN ] ) )
42 : null;
43
44 if ( $token && get_option( self::OPTION_TOKEN ) === $token ) {
45 return true;
46 }
47
48 return false;
49 }
50
51 public function is_requested() {
52 return ! empty( $_REQUEST['elementor-mode'] ) && 'safe' === $_REQUEST['elementor-mode'];
53 }
54
55 public function is_editor() {
56 return is_admin() && isset( $_GET['action'] ) && 'elementor' === $_GET['action'];
57 }
58
59 public function is_editor_preview() {
60 return isset( $_GET['elementor-preview'] );
61 }
62
63 public function is_editor_ajax() {
64 // PHPCS - There is already nonce verification in the Ajax Manager
65 return is_admin() && isset( $_POST['action'] ) && 'elementor_ajax' === $_POST['action']; // phpcs:ignore WordPress.Security.NonceVerification.Missing
66 }
67
68 public function add_hooks() {
69 add_filter( 'pre_option_active_plugins', function () {
70 return get_option( 'elementor_safe_mode_allowed_plugins' );
71 } );
72
73 add_filter( 'pre_option_stylesheet', function () {
74 return 'elementor-safe';
75 } );
76
77 add_filter( 'pre_option_template', function () {
78 return 'elementor-safe';
79 } );
80
81 add_action( 'elementor/init', function () {
82 do_action( 'elementor/safe_mode/init' );
83 } );
84 }
85
86 /**
87 * Plugin row meta.
88 *
89 * Adds row meta links to the plugin list table
90 *
91 * Fired by `plugin_row_meta` filter.
92 *
93 * @access public
94 *
95 * @param array $plugin_meta An array of the plugin's metadata, including
96 * the version, author, author URI, and plugin URI.
97 * @param string $plugin_file Path to the plugin file, relative to the plugins
98 * directory.
99 *
100 * @return array An array of plugin row meta links.
101 */
102 public function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) {
103 if ( basename( __FILE__ ) === $plugin_file ) {
104 $row_meta = [
105 'docs' => '<a href="https://go.elementor.com/safe-mode/" target="_blank">' . esc_html__( 'Learn More', 'elementor' ) . '</a>',
106 ];
107
108 $plugin_meta = array_merge( $plugin_meta, $row_meta );
109 }
110
111 return $plugin_meta;
112 }
113
114 public function __construct() {
115 add_filter( 'plugin_row_meta', [ $this, 'plugin_row_meta' ], 10, 4 );
116
117 $enabled_type = $this->is_enabled();
118
119 if ( ! $enabled_type || ! $this->is_valid_token() ) {
120 return;
121 }
122
123 if ( ! $this->is_requested() && 'global' !== $enabled_type ) {
124 return;
125 }
126
127 if ( ! $this->is_editor() && ! $this->is_editor_preview() && ! $this->is_editor_ajax() ) {
128 return;
129 }
130
131 $this->add_hooks();
132 }
133 }
134
135 new Safe_Mode();
136