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

134 lines 3.7 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 ] ) ? $_COOKIE[ self::OPTION_TOKEN ] : null;
42
43 if ( $token && get_option( self::OPTION_TOKEN ) === $token ) {
44 return true;
45 }
46
47 return false;
48 }
49
50 public function is_requested() {
51 return ! empty( $_REQUEST['elementor-mode'] ) && 'safe' === $_REQUEST['elementor-mode'];
52 }
53
54 public function is_editor() {
55 return is_admin() && isset( $_GET['action'] ) && 'elementor' === $_GET['action'];
56 }
57
58 public function is_editor_preview() {
59 return isset( $_GET['elementor-preview'] );
60 }
61
62 public function is_editor_ajax() {
63 return is_admin() && isset( $_POST['action'] ) && 'elementor_ajax' === $_POST['action'];
64 }
65
66 public function add_hooks() {
67 add_filter( 'pre_option_active_plugins', function () {
68 return get_option( 'elementor_safe_mode_allowed_plugins' );
69 } );
70
71 add_filter( 'pre_option_stylesheet', function () {
72 return 'elementor-safe';
73 } );
74
75 add_filter( 'pre_option_template', function () {
76 return 'elementor-safe';
77 } );
78
79 add_action( 'elementor/init', function () {
80 do_action( 'elementor/safe_mode/init' );
81 } );
82 }
83
84 /**
85 * Plugin row meta.
86 *
87 * Adds row meta links to the plugin list table
88 *
89 * Fired by `plugin_row_meta` filter.
90 *
91 * @access public
92 *
93 * @param array $plugin_meta An array of the plugin's metadata, including
94 * the version, author, author URI, and plugin URI.
95 * @param string $plugin_file Path to the plugin file, relative to the plugins
96 * directory.
97 *
98 * @return array An array of plugin row meta links.
99 */
100 public function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) {
101 if ( basename( __FILE__ ) === $plugin_file ) {
102 $row_meta = [
103 'docs' => '<a href="https://go.elementor.com/safe-mode/" aria-label="' . esc_attr( __( 'Learn More', 'elementor' ) ) . '" target="_blank">' . __( 'Learn More', 'elementor' ) . '</a>',
104 ];
105
106 $plugin_meta = array_merge( $plugin_meta, $row_meta );
107 }
108
109 return $plugin_meta;
110 }
111
112 public function __construct() {
113 add_filter( 'plugin_row_meta', [ $this, 'plugin_row_meta' ], 10, 4 );
114
115 $enabled_type = $this->is_enabled();
116
117 if ( ! $enabled_type || ! $this->is_valid_token() ) {
118 return;
119 }
120
121 if ( ! $this->is_requested() && 'global' !== $enabled_type ) {
122 return;
123 }
124
125 if ( ! $this->is_editor() && ! $this->is_editor_preview() && ! $this->is_editor_ajax() ) {
126 return;
127 }
128
129 $this->add_hooks();
130 }
131 }
132
133 new Safe_Mode();
134