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.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 +43 -26 0.3.60.4.2 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
@@ -104,8 +110,11 @@
104 110 "api_token" => md5( time() . rand() ),
105 111
106 112 //MCP
107 113 "mcp_support" => false,
114 +
115 + //MAINTENANCE
116 + "clean_uninstall" => false,
108 117 ];
109 118 }
110 119
111 120 function get_all_options( ) {
@@ -119,19 +128,15 @@
119 128 return $options;
120 129 }
121 130
122 131 function update_options( $options ) {
123 - $current_options = get_option($this->option_name);
124 132
125 - if ($current_options === $options) {
126 - // $this->log('💾 The options are already the expected value.');
127 - } else {
128 - if ( !update_option( $this->option_name, $options, false ) ) {
129 - $this->log( '💾 There was an issue updating the options.' );
130 - }
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.' );
131 137 }
132 -
133 - $options = $this->sanitize_options( $options );
138 +
134 139 return $options;
135 140 }
136 141
137 142 function update_option( $option, $value ) {
@@ -174,12 +179,8 @@
174 179 // Note: We don't disable MCP support here anymore
175 180 // It will be checked at runtime in the MCP class
176 181 }
177 182
178 - if ( $options_modified ) {
179 - update_option( $this->option_name, $options, false );
180 - }
181 -
182 183 return $options;
183 184 }
184 185
185 186 private function updateAIEngineStatus( &$options ) {
@@ -279,16 +280,16 @@
279 280 $value = array_map( 'trim', $value );
280 281 }
281 282
282 283 if ( $type === 'array' ) {
283 - $value = json_encode( $value );
284 - $value = str_replace( '\\', '', $value );
284 + // Convert to PHP array format instead of JSON
285 + $value = var_export( $value, true );
285 286 }
286 287
287 288 return [ $name, $value ];
288 289 }
289 290
290 - function run_non_fn_snippet( $id, $code = null, $test = false ) {
291 + function run_non_fn_snippet( $id, $code = null, $test = false, $prefix = '' ) {
291 292 // Retrieve the snippet code from the provided code or via the snippet ID.
292 293 if ( $code ) {
293 294 $snippet = [ 'code' => $code ];
294 295 } else {
@@ -295,13 +296,17 @@
295 296 $snippet = $this->get_snippet( $id );
296 297 }
297 298
298 299 // Remove any PHP opening tag.
299 - $snippet['code'] = preg_replace( '/<\?php/', '', $snippet['code'], 1 );
300 + $snippet['code'] = $this->snippet->sanitize_code( $snippet['code'] );
300 301
301 302 if ( $test ) {
302 303 $snippet['code'] = preg_replace( '/echo\s+(.+?);/s', 'echo $1 . "\n";', $snippet['code'] );
303 304 }
305 +
306 + if( $prefix ) {
307 + $snippet['code'] = $prefix . "\n" . $snippet['code'];
308 + }
304 309
305 310 $error = null;
306 311 $output = null;
307 312
@@ -435,13 +440,14 @@
435 440 if ( $index < count( $params['args'] ) - 1 ) {
436 441 $params['code'] .= ', ';
437 442 }
438 443 }
444 +
439 445 $params['code'] .= ");\necho print_r(\$mwcode_result, true);";
440 446
441 447 $error = null;
442 448 $output = null;
443 -
449 +
444 450 try {
445 451 ob_start();
446 452 eval( $params['code'] );
447 453 $output = ob_get_clean();
@@ -591,9 +597,9 @@
591 597 $blocked = false;
592 598 //$blocked = true;
593 599 }
594 600 // Block REST requests that aren't whitelisted
595 - elseif ( MeowCommon_Helpers::is_rest() && !Meow_MWCODE_Core::is_white_listed_rest() ) {
601 + elseif ( MeowKit_MWCODE_Helpers::is_rest() && !Meow_MWCODE_Core::is_white_listed_rest() ) {
596 602 $blocked = true;
597 603 }
598 604
599 605 if ( empty( $this->snippet ) ) {
@@ -624,9 +630,9 @@
624 630 return;
625 631 }
626 632
627 633 $snippets = array_map( function ( $snippet ) use ( $blocked ) {
628 - $snippet['code'] = preg_replace( '/<\?php/', '', $snippet['code'], 1 );
634 + $snippet['code'] = $this->snippet->sanitize_code( $snippet['code'] );
629 635 $snippet['blocked'] = $blocked;
630 636
631 637 // If the snippet must be executed only in the frontend, we bypass the block
632 638 if ( !is_admin() && $snippet['scope'] === 'frontend' ) {
@@ -642,16 +648,26 @@
642 648
643 649 #endregion
644 650
645 651 #region Shortcodes
652 + function separate_mwcode_atts( $atts ) {
646 653
654 + if( array_key_exists( 'id', $atts ) ) unset( $atts['id'] );
655 + if( array_key_exists( 'target', $atts ) ) unset( $atts['target'] );
656 + if( array_key_exists( 'code', $atts ) ) unset( $atts['code'] );
657 +
658 + return $atts;
659 + }
660 +
647 661 function content_shortcode( $atts ) {
648 662
663 + $user_atts = $this->separate_mwcode_atts( $atts );
664 +
649 665 $atts = shortcode_atts( array(
650 - 'id' => null,
651 - 'target' => null,
652 - 'code' => null,
653 - ), $atts );
666 + 'id' => null,
667 + 'target' => null, // js or php
668 + 'code' => null, // For Guttenberg block usage
669 + ), $atts, 'code-engine' );
654 670
655 671 $id = $atts['id'];
656 672 $target = $atts['target'];
657 673 $code = $atts['code'];
@@ -734,9 +750,10 @@
734 750 $output = '<script>' . $snippet['code'] . '</script>';
735 751 }
736 752
737 753 if ( $is_content_php ) {
738 - $output = $this->run_non_fn_snippet( $id );
754 + $prefix = "\$mwcode_atts = unserialize( '" . serialize( $user_atts ) . "' );";
755 + $output = $this->run_non_fn_snippet( $id, null, false, $prefix );
739 756 }
740 757
741 758 return $output;
742 759 }