PluginProbe
Elementor Website Builder – more than just a page builder / 3.1.3
Elementor Website Builder – more than just a page builder v3.1.3
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
← All changes | core/logger/manager.php +22 -52 4.2.43.1.3 View file →
@@ -2,18 +2,16 @@
2 2 namespace Elementor\Core\Logger;
3 3
4 4 use Elementor\Core\Base\Module as BaseModule;
5 5 use Elementor\Core\Common\Modules\Ajax\Module;
6 -use Elementor\Core\Editor\Editor;
7 6 use Elementor\Core\Logger\Loggers\Logger_Interface;
8 7 use Elementor\Core\Logger\Items\PHP;
9 8 use Elementor\Core\Logger\Items\JS;
10 9 use Elementor\Plugin;
11 10 use Elementor\Modules\System_Info\Module as System_Info;
12 -use Elementor\Utils;
13 11
14 12 if ( ! defined( 'ABSPATH' ) ) {
15 - exit; // Exit if accessed directly.
13 + exit; // Exit if accessed directly
16 14 }
17 15
18 16 class Manager extends BaseModule {
19 17
@@ -24,9 +22,9 @@
24 22 public function get_name() {
25 23 return 'log';
26 24 }
27 25
28 - public function shutdown( $last_error = null, $should_exit = false ) {
26 + public function shutdown( $last_error = null ) {
29 27 if ( ! $last_error ) {
30 28 $last_error = error_get_last();
31 29 }
32 30
@@ -37,9 +35,13 @@
37 35 if ( empty( $last_error['file'] ) ) {
38 36 return;
39 37 }
40 38
41 - if ( ! Utils::is_elementor_path( $last_error['file'] ) ) {
39 + $error_path = ( wp_normalize_path( $last_error['file'] ) );
40 + // `untrailingslashit` in order to include other plugins prefixed with elementor.
41 + $elementor_path = untrailingslashit( wp_normalize_path( ELEMENTOR_PATH ) );
42 +
43 + if ( false === strpos( $error_path, $elementor_path ) ) {
42 44 return;
43 45 }
44 46
45 47 $last_error['type'] = $this->get_log_type_from_php_error( $last_error['type'] );
@@ -47,20 +49,11 @@
47 49
48 50 $item = new PHP( $last_error );
49 51
50 52 $this->get_logger()->log( $item );
51 -
52 - if ( $should_exit ) {
53 - exit;
54 - }
55 53 }
56 54
57 55 public function rest_error_handler( $error_number, $error_message, $error_file, $error_line ) {
58 - // Temporary solution until all PHP notices will be fixed in the core and pro.
59 - if ( Utils::is_wp_cli() ) {
60 - return null;
61 - }
62 -
63 56 $error = new \WP_Error( $error_number, $error_message, [
64 57 'type' => $error_number,
65 58 'message' => $error_message,
66 59 'file' => $error_file,
@@ -66,30 +59,16 @@
66 59 'file' => $error_file,
67 60 'line' => $error_line,
68 61 ] );
69 62
70 - if ( ! Utils::is_elementor_path( $error_file ) ) {
71 - // Do execute PHP internal error handler.
72 - return false;
73 - }
74 -
75 - $is_an_error = in_array( // It can be notice or warning
76 - $error_number,
77 - [ E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR ],
78 - true
79 - );
80 -
81 - $error_data = $error->get_error_data();
82 -
83 - // TODO: This part should be modular, temporary hard-coded.
84 63 // Notify $e.data.
85 - if ( $is_an_error && ! headers_sent() ) {
64 + if ( ! headers_sent() ) {
86 65 header( 'Content-Type: application/json; charset=UTF-8' );
87 66
88 67 http_response_code( 500 );
89 68
90 69 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
91 - echo wp_json_encode( $error_data );
70 + echo wp_json_encode( $error->get_error_data() );
92 71 } else {
93 72 echo wp_json_encode( [
94 73 'message' => 'Server error, see Elementor => System Info',
95 74 ] );
@@ -95,13 +74,11 @@
95 74 ] );
96 75 }
97 76 }
98 77
99 - $this->shutdown( $error_data, $is_an_error );
100 - }
78 + $this->shutdown( $error->get_error_data() );
101 79
102 - public function register_error_handler() {
103 - set_error_handler( [ $this, 'rest_error_handler' ], E_ALL );
80 + exit;
104 81 }
105 82
106 83 public function add_system_info_report() {
107 84 System_Info::add_report(
@@ -117,31 +94,23 @@
117 94 *
118 95 * Log Elementor errors and save them in the database.
119 96 *
120 97 * Fired by `wp_ajax_elementor_js_log` action.
98 + *
121 99 */
122 100 public function js_log() {
123 101 /** @var Module $ajax */
124 102 $ajax = Plugin::$instance->common->get_component( 'ajax' );
125 103
126 - // PHPCS ignore is added throughout this method because nonce verification happens in the $ajax->verify_request_nonce() method.
127 - if ( ! $ajax->verify_request_nonce() || empty( $_POST['data'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
104 + if ( ! $ajax->verify_request_nonce() || empty( $_POST['data'] ) ) {
128 105 wp_send_json_error();
129 106 }
130 107
131 - if ( ! current_user_can( Editor::EDITING_CAPABILITY ) ) {
132 - wp_send_json_error( 'Permission denied' );
133 - }
134 -
135 - // PHPCS - See comment above.
136 - $data = Utils::get_super_global_value( $_POST, 'data' ) ?? []; // phpcs:ignore WordPress.Security.NonceVerification.Missing
137 -
138 - array_walk_recursive( $data, function( &$value ) {
108 + array_walk_recursive( $_POST['data'], function( &$value ) {
139 109 $value = sanitize_text_field( $value );
140 110 } );
141 111
142 - // PHPCS - See comment above.
143 - foreach ( $data as $error ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
112 + foreach ( $_POST['data'] as $error ) {
144 113 $error['type'] = Logger_Interface::LEVEL_ERROR;
145 114
146 115 if ( ! empty( $error['customFields'] ) ) {
147 116 $error['meta'] = $error['customFields'];
@@ -153,10 +122,10 @@
153 122
154 123 wp_send_json_success();
155 124 }
156 125
157 - public function register_logger( $name, $class_name ) {
158 - $this->loggers[ $name ] = $class_name;
126 + public function register_logger( $name, $class ) {
127 + $this->loggers[ $name ] = $class;
159 128 }
160 129
161 130 public function set_default_logger( $name ) {
162 131 if ( ! empty( $this->loggers[ $name ] ) ) {
@@ -199,9 +168,9 @@
199 168 }
200 169
201 170 /**
202 171 * @param string $message
203 - * @param array $args
172 + * @param array $args
204 173 *
205 174 * @return void
206 175 */
207 176 public function info( $message, $args = [] ) {
@@ -209,9 +178,9 @@
209 178 }
210 179
211 180 /**
212 181 * @param string $message
213 - * @param array $args
182 + * @param array $args
214 183 *
215 184 * @return void
216 185 */
217 186 public function notice( $message, $args = [] ) {
@@ -219,9 +188,9 @@
219 188 }
220 189
221 190 /**
222 191 * @param string $message
223 - * @param array $args
192 + * @param array $args
224 193 *
225 194 * @return void
226 195 */
227 196 public function warning( $message, $args = [] ) {
@@ -229,9 +198,9 @@
229 198 }
230 199
231 200 /**
232 201 * @param string $message
233 - * @param array $args
202 + * @param array $args
234 203 *
235 204 * @return void
236 205 */
237 206 public function error( $message, $args = [] ) {
@@ -245,8 +214,9 @@
245 214 E_USER_ERROR => Logger_Interface::LEVEL_ERROR,
246 215 E_COMPILE_ERROR => Logger_Interface::LEVEL_ERROR,
247 216 E_RECOVERABLE_ERROR => Logger_Interface::LEVEL_ERROR,
248 217 E_PARSE => Logger_Interface::LEVEL_ERROR,
218 + E_STRICT => Logger_Interface::LEVEL_ERROR,
249 219
250 220 E_WARNING => Logger_Interface::LEVEL_WARNING,
251 221 E_USER_WARNING => Logger_Interface::LEVEL_WARNING,
252 222 E_CORE_WARNING => Logger_Interface::LEVEL_WARNING,