PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.4.2
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.4.2
0.5.6 0.5.5 0.5.4 0.5.3 0.5.2 0.5.1 0.5.0 0.4.9 0.4.8 0.4.7 0.4.6 trunk 0.0.1 0.0.2 0.2.8 0.2.9 0.3.0 0.3.1 0.3.2 0.3.3 0.3.4 0.3.5 0.3.6 0.3.7 0.3.8 All 32 releases
← All changes | classes/load.php +36 -4 0.3.00.4.2 View file →
@@ -4,8 +4,9 @@
4 4 add_action( 'plugins_loaded', 'mwcode_loaded', 1 );
5 5
6 6 function mwcode_loaded( ) {
7 7 global $mwcode_core, $current_mwcode_snippet;
8 + static $last_blocked_log = [];
8 9
9 10
10 11 if ( !isset( $mwcode_core ) ) {
11 12 $mwcode_core = new Meow_MWCODE_Core( );
@@ -19,9 +20,40 @@
19 20
20 21 foreach ( $snippets as $snippet ) {
21 22
22 23 if ( $snippet['blocked'] ) {
23 - $mwcode_core->log( "⚠️ Snippet is blocked: " . $snippet['name'] . " ( ID: " . $snippet['id'] . " ) Because it's not a frontend request, on a non authorized page." );
24 + // Determine the reason for blocking
25 + $page = isset( $_GET["page"] ) ? sanitize_text_field( $_GET["page"] ) : null;
26 + $is_settings_page = ( $page === 'mwcode_settings' );
27 + $is_rest = MeowKit_MWCODE_Helpers::is_rest();
28 + $is_rest_whitelisted = Meow_MWCODE_Core::is_white_listed_rest();
29 +
30 + $reason = '';
31 + if ( $is_settings_page ) {
32 + $reason = "on Code Engine settings page (disabled for safety)";
33 + } elseif ( $is_rest && !$is_rest_whitelisted ) {
34 + $requested_route = Meow_MWCODE_Core::get_requested_rest_route();
35 + $reason = "REST route not whitelisted: " . ($requested_route ?: 'unknown');
36 + } else {
37 + // Add more debugging info
38 + $debug_info = [
39 + 'is_rest' => $is_rest,
40 + 'is_whitelisted' => $is_rest_whitelisted,
41 + 'page' => $page,
42 + 'request_uri' => $_SERVER['REQUEST_URI'] ?? 'not set'
43 + ];
44 + $reason = "unknown reason (debug: " . json_encode($debug_info) . ")";
45 + }
46 +
47 + // Avoid duplicate logs within 2 seconds
48 + $log_key = $snippet['id'] . '-' . $reason;
49 + $current_time = time();
50 +
51 + if ( !isset($last_blocked_log[$log_key]) || ($current_time - $last_blocked_log[$log_key]) > 2 ) {
52 + $mwcode_core->log( "⚠️ Snippet blocked: " . $snippet['name'] . " (ID: " . $snippet['id'] . ") - " . $reason );
53 + $last_blocked_log[$log_key] = $current_time;
54 + }
55 +
24 56 continue;
25 57 }
26 58
27 59 $current_mwcode_snippet = $snippet;
@@ -29,12 +61,12 @@
29 61
30 62 ob_start( );
31 63
32 64 try {
33 - error_log( "Executing snippet: " . $snippet['name'] . " ( ID: " . $snippet['id'] . " )" );
65 + $mwcode_core->log( "Executing snippet: " . $snippet['name'] . " (ID: " . $snippet['id'] . ")" );
34 66 eval( $snippet['code'] );
35 67 } catch ( Throwable $e ) {
36 - $mwcode_core->log( "⚠️ Exception in snippet: " . $snippet['name'] . " ( ID: " . $snippet['id'] . " )" );
68 + $mwcode_core->log( "⚠️ Exception in snippet: " . $snippet['name'] . " (ID: " . $snippet['id'] . ")" );
37 69 $mwcode_core->log( $e->getMessage( ) );
38 70 $mwcode_core->update_option( 'fatal_error', "\"{$snippet["name"]}\" - " . $e->getMessage( ) );
39 71 $mwcode_core->update_option( 'thrown_snippet', $snippet );
40 72 }
@@ -56,9 +88,9 @@
56 88 }
57 89
58 90
59 91 // In admin or Rest API request ( REQUEST URI begins with '/wp-json/' )
60 -if ( is_admin( ) || MeowCommon_Helpers::is_rest( ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
92 +if ( is_admin( ) || MeowKit_MWCODE_Helpers::is_rest( ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
61 93 global $mwcode_core;
62 94 $mwcode_core = new Meow_MWCODE_Core( );
63 95 }
64 96