PluginProbe
Code Engine – PHP Snippets, AI Functions & Automation for WordPress / 0.3.7
Code Engine – PHP Snippets, AI Functions & Automation for WordPress v0.3.7
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 +48 -6 0.3.20.3.7 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,14 +89,17 @@
83 89 return [
84 90 //Safemode
85 91 "safe_mode_status" => "on", // on, off, whitelist
86 92 "safe_mode_whitelist" => [],
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
87 96
88 97 //LOGS
89 98 "server_debug_mode" => false,
90 99
91 100 //UI
92 - "ui_show_preview" => true,
101 + "ui_show_preview" => false,
93 102
94 103 //AI
95 104 "ai_suggestions" => false,
96 105 "ai_engine_status"=> false,
@@ -580,11 +589,14 @@
580 589
581 590 $blocked = false;
582 591 $page = isset( $_GET["page"] ) ? sanitize_text_field( $_GET["page"] ) : null;
583 592
584 - // Block on settings page for safety
593 +
585 594 if ( $page === 'mwcode_settings' ) {
586 - $blocked = true;
595 + // If we blocks global snippets like nonce_life filter, we would block the settings page so let's remove the block for this page
596 +
597 + $blocked = false;
598 + //$blocked = true;
587 599 }
588 600 // Block REST requests that aren't whitelisted
589 601 elseif ( MeowCommon_Helpers::is_rest() && !Meow_MWCODE_Core::is_white_listed_rest() ) {
590 602 $blocked = true;
@@ -648,13 +660,38 @@
648 660
649 661 $id = $atts['id'];
650 662 $target = $atts['target'];
651 663 $code = $atts['code'];
652 -
664 + $current_post = get_post();
665 +
666 + $no_js = defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML;
667 + $allow_php = $this->get_option( 'code_blocks', false );
668 + $allow_php_whitelist = $this->get_option( 'code_blocks_whitelist', [] );
669 +
653 670 // If the ID is null, it means it comes from a Guttenberg block
654 671 $is_block = empty( $id ) && !empty( $code );
655 - if( $is_block ){
656 672
673 + if( $is_block ) {
674 +
675 + if( $target !== 'js' && $target !== 'php' ) {
676 + return '<b>Code Engine:</b> Please provide a valid target (js or php).';
677 + }
678 +
679 + if ( $no_js && $target === 'js' ) {
680 + return '<b>Code Engine:</b> Code Block JS are disabled because unfiltered HTML is not allowed on your server.';
681 + }
682 +
683 + if ( $target === 'php' ) {
684 +
685 + if ( !$allow_php ) {
686 + 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.';
687 + }
688 +
689 + if ( !empty( $allow_php_whitelist ) && !in_array( $current_post->ID, $allow_php_whitelist ) ) {
690 + 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.';
691 + }
692 + }
693 +
657 694 // Because the code from Blocks are sanitized, we need to replace the &quot; with "
658 695 $code = str_replace( '&quot;', '"', $code );
659 696
660 697 if ( $target === 'js' ) {
@@ -667,8 +704,9 @@
667 704
668 705 return $output;
669 706 }
670 707
708 + // If not a block, we get the snippet by ID
671 709 // If the ID is not null, it means it comes from a shortcode
672 710 if ( empty( $id ) && empty( $code ) ) {
673 711 return '<b>Code Engine:</b> Please provide a snippet ID.';
674 712 }
@@ -680,12 +718,16 @@
680 718 }
681 719
682 720 //Check if the snippet scope is either content_php or content_js
683 721 $is_content_php = $snippet['scope'] === 'content_php';
684 - $is_content_js = $snippet['scope'] === 'content_js';
722 + $is_content_js = $snippet['scope'] === 'content_js';
685 723
686 724 if ( !$is_content_php && !$is_content_js ) {
687 725 return '<b>Code Engine:</b> The snippet is not a content snippet.';
726 + }
727 +
728 + if( $no_js && $is_content_js ) {
729 + return '<b>Code Engine:</b> Code Engine JS snippets are disabled because unfiltered HTML is not allowed on your server.';
688 730 }
689 731
690 732 //Check if the snippet is active
691 733 if ( !$snippet['active'] ) {