PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.3.9
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.3.9
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 +25 -7 0.3.50.3.9 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() {
@@ -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( 'MeowCommonPro_Licenser' ) ) {
44 + $this->licenser = new MeowCommonPro_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
@@ -277,10 +285,10 @@
277 285 $value = array_map( 'trim', $value );
278 286 }
279 287
280 288 if ( $type === 'array' ) {
281 - $value = json_encode( $value );
282 - $value = str_replace( '\\', '', $value );
289 + // Convert to PHP array format instead of JSON
290 + $value = var_export( $value, true );
283 291 }
284 292
285 293 return [ $name, $value ];
286 294 }
@@ -433,13 +441,14 @@
433 441 if ( $index < count( $params['args'] ) - 1 ) {
434 442 $params['code'] .= ', ';
435 443 }
436 444 }
445 +
437 446 $params['code'] .= ");\necho print_r(\$mwcode_result, true);";
438 447
439 448 $error = null;
440 449 $output = null;
441 -
450 +
442 451 try {
443 452 ob_start();
444 453 eval( $params['code'] );
445 454 $output = ob_get_clean();
@@ -652,11 +661,13 @@
652 661
653 662 $id = $atts['id'];
654 663 $target = $atts['target'];
655 664 $code = $atts['code'];
665 + $current_post = get_post();
656 666
657 667 $no_js = defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML;
658 - $no_php = $this->get_option( 'disallow_block_php', true );
668 + $allow_php = $this->get_option( 'code_blocks', false );
669 + $allow_php_whitelist = $this->get_option( 'code_blocks_whitelist', [] );
659 670
660 671 // If the ID is null, it means it comes from a Guttenberg block
661 672 $is_block = empty( $id ) && !empty( $code );
662 673
@@ -669,10 +680,17 @@
669 680 if ( $no_js && $target === 'js' ) {
670 681 return '<b>Code Engine:</b> Code Block JS are disabled because unfiltered HTML is not allowed on your server.';
671 682 }
672 683
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.';
684 + if ( $target === 'php' ) {
685 +
686 + if ( !$allow_php ) {
687 + 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.';
688 + }
689 +
690 + if ( !empty( $allow_php_whitelist ) && !in_array( $current_post->ID, $allow_php_whitelist ) ) {
691 + 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.';
692 + }
675 693 }
676 694
677 695 // Because the code from Blocks are sanitized, we need to replace the &quot; with "
678 696 $code = str_replace( '&quot;', '"', $code );