PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.3.1
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.3.1
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 +5 -39 trunk0.3.1 View file →
@@ -4,9 +4,8 @@
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 = [];
9 8
10 9
11 10 if ( !isset( $mwcode_core ) ) {
12 11 $mwcode_core = new Meow_MWCODE_Core( );
@@ -20,55 +19,22 @@
20 19
21 20 foreach ( $snippets as $snippet ) {
22 21
23 22 if ( $snippet['blocked'] ) {
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 -
23 + $mwcode_core->log( "⚠️ Snippet is blocked: " . $snippet['name'] . " ( ID: " . $snippet['id'] . " ) Because it's not a frontend request, on a non authorized page." );
56 24 continue;
57 25 }
58 26
59 27 $current_mwcode_snippet = $snippet;
28 +
60 29
61 - // Remember we ran this global so load_global_snippets() won't run it a second time.
62 - $mwcode_core->loaded_global_ids[] = $snippet['id'];
63 -
64 30 ob_start( );
65 31
66 32 try {
67 - $mwcode_core->log( "Executing snippet: " . $snippet['name'] . " (ID: " . $snippet['id'] . ")" );
33 + error_log( "Executing snippet: " . $snippet['name'] . " ( ID: " . $snippet['id'] . " )" );
68 34 eval( $snippet['code'] );
69 35 } catch ( Throwable $e ) {
70 - $mwcode_core->log( "⚠️ Exception in snippet: " . $snippet['name'] . " (ID: " . $snippet['id'] . ")" );
36 + $mwcode_core->log( "⚠️ Exception in snippet: " . $snippet['name'] . " ( ID: " . $snippet['id'] . " )" );
71 37 $mwcode_core->log( $e->getMessage( ) );
72 38 $mwcode_core->update_option( 'fatal_error', "\"{$snippet["name"]}\" - " . $e->getMessage( ) );
73 39 $mwcode_core->update_option( 'thrown_snippet', $snippet );
74 40 }
@@ -90,9 +56,9 @@
90 56 }
91 57
92 58
93 59 // In admin or Rest API request ( REQUEST URI begins with '/wp-json/' )
94 -if ( is_admin( ) || MeowKit_MWCODE_Helpers::is_rest( ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
60 +if ( is_admin( ) || MeowCommon_Helpers::is_rest( ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
95 61 global $mwcode_core;
96 62 $mwcode_core = new Meow_MWCODE_Core( );
97 63 }
98 64