PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.4.0
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.4.0
0.5.7 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 All 33 releases
← All changes | classes/core.php +35 -22 0.3.40.4.0 View file →
@@ -12,8 +12,9 @@
12 12 public $is_rest = false;
13 13 public $is_cli = false;
14 14 public $site_url = null;
15 15 public $mwcode = null;
16 + public $licenser = null;
16 17
17 18 private $option_name = 'mwcode_options';
18 19
19 20 public function __construct() {
@@ -19,9 +20,9 @@
19 20 public function __construct() {
20 21 global $mwcode;
21 22
22 23 $this->site_url = get_site_url();
23 - $this->is_rest = MeowCommon_Helpers::is_rest();
24 + $this->is_rest = MeowKit_MWCODE_Helpers::is_rest();
24 25 $this->is_cli = defined( 'WP_CLI' ) && WP_CLI;
25 26
26 27 // Snippets
27 28 $snippet = new Meow_MWCODE_Modules_Snippet( $this );
@@ -37,8 +38,13 @@
37 38 add_action( 'plugins_loaded', array( $this, 'init' ) );
38 39 }
39 40
40 41 function init() {
42 + // Initialize the licenser for Pro version
43 + if ( class_exists( 'MeowKitPro_MWCODE_Licenser' ) ) {
44 + $this->licenser = new MeowKitPro_MWCODE_Licenser( MWCODE_PREFIX, MWCODE_ENTRY, MWCODE_DOMAIN, MWCODE_ITEM_ID, MWCODE_VERSION );
45 + }
46 +
41 47 // Part of the core, settings and stuff
42 48 $this->admin = new Meow_MWCODE_Admin( $this );
43 49
44 50 // Only for REST
@@ -83,9 +89,11 @@
83 89 return [
84 90 //Safemode
85 91 "safe_mode_status" => "on", // on, off, whitelist
86 92 "safe_mode_whitelist" => [],
87 - "disallow_block_php" => true, // Do not allow PHP code to be execute through Blocks "code" parameter
93 + //"disallow_block_php" => true, // Do not allow PHP code to be execute through Blocks "code" parameter
94 + "code_blocks" => false,
95 + "code_blocks_whitelist" => [], // Whitelist for code blocks, if empty, all code blocks are allowed
88 96
89 97 //LOGS
90 98 "server_debug_mode" => false,
91 99
@@ -102,8 +110,11 @@
102 110 "api_token" => md5( time() . rand() ),
103 111
104 112 //MCP
105 113 "mcp_support" => false,
114 +
115 + //MAINTENANCE
116 + "clean_uninstall" => false,
106 117 ];
107 118 }
108 119
109 120 function get_all_options( ) {
@@ -117,19 +128,15 @@
117 128 return $options;
118 129 }
119 130
120 131 function update_options( $options ) {
121 - $current_options = get_option($this->option_name);
122 132
123 - if ($current_options === $options) {
124 - // $this->log('💾 The options are already the expected value.');
125 - } else {
126 - if ( !update_option( $this->option_name, $options, false ) ) {
127 - $this->log( '💾 There was an issue updating the options.' );
128 - }
133 + $options = $this->sanitize_options( $options );
134 +
135 + if ( !update_option( $this->option_name, $options, false ) ) {
136 + $this->log( '💾 There was an issue updating the options.' );
129 137 }
130 -
131 - $options = $this->sanitize_options( $options );
138 +
132 139 return $options;
133 140 }
134 141
135 142 function update_option( $option, $value ) {
@@ -172,12 +179,8 @@
172 179 // Note: We don't disable MCP support here anymore
173 180 // It will be checked at runtime in the MCP class
174 181 }
175 182
176 - if ( $options_modified ) {
177 - update_option( $this->option_name, $options, false );
178 - }
179 -
180 183 return $options;
181 184 }
182 185
183 186 private function updateAIEngineStatus( &$options ) {
@@ -277,10 +280,10 @@
277 280 $value = array_map( 'trim', $value );
278 281 }
279 282
280 283 if ( $type === 'array' ) {
281 - $value = json_encode( $value );
282 - $value = str_replace( '\\', '', $value );
284 + // Convert to PHP array format instead of JSON
285 + $value = var_export( $value, true );
283 286 }
284 287
285 288 return [ $name, $value ];
286 289 }
@@ -433,13 +436,14 @@
433 436 if ( $index < count( $params['args'] ) - 1 ) {
434 437 $params['code'] .= ', ';
435 438 }
436 439 }
440 +
437 441 $params['code'] .= ");\necho print_r(\$mwcode_result, true);";
438 442
439 443 $error = null;
440 444 $output = null;
441 -
445 +
442 446 try {
443 447 ob_start();
444 448 eval( $params['code'] );
445 449 $output = ob_get_clean();
@@ -589,9 +593,9 @@
589 593 $blocked = false;
590 594 //$blocked = true;
591 595 }
592 596 // Block REST requests that aren't whitelisted
593 - elseif ( MeowCommon_Helpers::is_rest() && !Meow_MWCODE_Core::is_white_listed_rest() ) {
597 + elseif ( MeowKit_MWCODE_Helpers::is_rest() && !Meow_MWCODE_Core::is_white_listed_rest() ) {
594 598 $blocked = true;
595 599 }
596 600
597 601 if ( empty( $this->snippet ) ) {
@@ -652,11 +656,13 @@
652 656
653 657 $id = $atts['id'];
654 658 $target = $atts['target'];
655 659 $code = $atts['code'];
660 + $current_post = get_post();
656 661
657 662 $no_js = defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML;
658 - $no_php = $this->get_option( 'disallow_block_php', true );
663 + $allow_php = $this->get_option( 'code_blocks', false );
664 + $allow_php_whitelist = $this->get_option( 'code_blocks_whitelist', [] );
659 665
660 666 // If the ID is null, it means it comes from a Guttenberg block
661 667 $is_block = empty( $id ) && !empty( $code );
662 668
@@ -669,10 +675,17 @@
669 675 if ( $no_js && $target === 'js' ) {
670 676 return '<b>Code Engine:</b> Code Block JS are disabled because unfiltered HTML is not allowed on your server.';
671 677 }
672 678
673 - if ( $no_php && $target === 'php' ) {
674 - return '<b>Code Engine:</b> Code Block PHP are disabled. If you are an administrator, you can enable it in the settings, this is not recommended. Please use a Content Snippet ( PHP ) instead.';
679 + if ( $target === 'php' ) {
680 +
681 + if ( !$allow_php ) {
682 + return '<b>Code Engine:</b> Code Block PHP are disabled. If you are an administrator, you can enable it in the settings, this is not recommended. Please use a Content Snippet ( PHP ) instead.';
683 + }
684 +
685 + if ( !empty( $allow_php_whitelist ) && !in_array( $current_post->ID, $allow_php_whitelist ) ) {
686 + return '<b>Code Engine:</b> Code Block PHP are disabled for this post. If you are an administrator, you can enable it in the settings, this is not recommended. Please use a Content Snippet ( PHP ) instead.';
687 + }
675 688 }
676 689
677 690 // Because the code from Blocks are sanitized, we need to replace the &quot; with "
678 691 $code = str_replace( '&quot;', '"', $code );