PluginProbe
Elementor Website Builder – more than just a page builder / 3.25.5
Elementor Website Builder – more than just a page builder v3.25.5
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.25.5, at modules/safe-mode/mu-plugin/elementor-safe-mode.php

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