| @@ -83,9 +83,11 @@ | ||
| 83 | 83 | return [ |
| 84 | 84 | //Safemode |
| 85 | 85 | "safe_mode_status" => "on", // on, off, whitelist |
| 86 | 86 | "safe_mode_whitelist" => [], |
| 87 | - "disallow_block_php" => true, // Do not allow PHP code to be execute through Blocks "code" parameter | |
| 87 | + //"disallow_block_php" => true, // Do not allow PHP code to be execute through Blocks "code" parameter | |
| 88 | + "code_blocks" => false, | |
| 89 | + "code_blocks_whitelist" => [], // Whitelist for code blocks, if empty, all code blocks are allowed | |
| 88 | 90 | |
| 89 | 91 | //LOGS |
| 90 | 92 | "server_debug_mode" => false, |
| 91 | 93 | |
| @@ -652,11 +654,13 @@ | ||
| 652 | 654 | |
| 653 | 655 | $id = $atts['id']; |
| 654 | 656 | $target = $atts['target']; |
| 655 | 657 | $code = $atts['code']; |
| 658 | + $current_post = get_post(); | |
| 656 | 659 | |
| 657 | 660 | $no_js = defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML; |
| 658 | - $no_php = $this->get_option( 'disallow_block_php', true ); | |
| 661 | + $allow_php = $this->get_option( 'code_blocks', false ); | |
| 662 | + $allow_php_whitelist = $this->get_option( 'code_blocks_whitelist', [] ); | |
| 659 | 663 | |
| 660 | 664 | // If the ID is null, it means it comes from a Guttenberg block |
| 661 | 665 | $is_block = empty( $id ) && !empty( $code ); |
| 662 | 666 | |
| @@ -669,10 +673,17 @@ | ||
| 669 | 673 | if ( $no_js && $target === 'js' ) { |
| 670 | 674 | return '<b>Code Engine:</b> Code Block JS are disabled because unfiltered HTML is not allowed on your server.'; |
| 671 | 675 | } |
| 672 | 676 | |
| 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.'; | |
| 677 | + if ( $target === 'php' ) { | |
| 678 | + | |
| 679 | + if ( !$allow_php ) { | |
| 680 | + 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.'; | |
| 681 | + } | |
| 682 | + | |
| 683 | + if ( !empty( $allow_php_whitelist ) && !in_array( $current_post->ID, $allow_php_whitelist ) ) { | |
| 684 | + 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.'; | |
| 685 | + } | |
| 675 | 686 | } |
| 676 | 687 | |
| 677 | 688 | // Because the code from Blocks are sanitized, we need to replace the " with " |
| 678 | 689 | $code = str_replace( '"', '"', $code ); |