| @@ -2,12 +2,10 @@ | ||
| 2 | 2 | namespace Elementor\Modules\MarkdownRender; |
| 3 | 3 | |
| 4 | 4 | use Elementor\Core\Base\Module as BaseModule; |
| 5 | 5 | use Elementor\Core\Experiments\Manager as Experiments_Manager; |
| 6 | -use Elementor\Core\Frontend\Widget_Content_Render_Mode; | |
| 7 | 6 | use Elementor\Plugin; |
| 8 | 7 | use Elementor\Settings; |
| 9 | -use Elementor\Utils; | |
| 10 | 8 | |
| 11 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | 10 | exit; |
| 13 | 11 | } |
| @@ -16,24 +14,8 @@ | ||
| 16 | 14 | |
| 17 | 15 | const EXPERIMENT_NAME = 'markdown_rendering'; |
| 18 | 16 | const CACHE_META_KEY = '_elementor_markdown_cache'; |
| 19 | 17 | |
| 20 | - public static function is_rendering_markdown(): bool { | |
| 21 | - return Widget_Content_Render_Mode::is( Widget_Content_Render_Mode::MARKDOWN ); | |
| 22 | - } | |
| 23 | - | |
| 24 | - public static function set_rendering_markdown( bool $is_rendering ): void { | |
| 25 | - Widget_Content_Render_Mode::set_current( | |
| 26 | - $is_rendering ? Widget_Content_Render_Mode::MARKDOWN : Widget_Content_Render_Mode::NORMAL | |
| 27 | - ); | |
| 28 | - } | |
| 29 | - | |
| 30 | - public static function execute_while_rendering_markdown( callable $callback ) { | |
| 31 | - // Markdown rendering must not enqueue editor CSS or parse post stylesheets. | |
| 32 | - // The render mode lets CSS and document cache layers skip those side effects while widgets render. | |
| 33 | - return Widget_Content_Render_Mode::execute_as( Widget_Content_Render_Mode::MARKDOWN, $callback ); | |
| 34 | - } | |
| 35 | - | |
| 36 | 18 | public function get_name() { |
| 37 | 19 | return 'markdown-render'; |
| 38 | 20 | } |
| 39 | 21 | |
| @@ -104,27 +86,25 @@ | ||
| 104 | 86 | if ( ! $document || ! $document->is_built_with_elementor() ) { |
| 105 | 87 | return; |
| 106 | 88 | } |
| 107 | 89 | |
| 108 | - self::execute_while_rendering_markdown( function () use ( $is_preview, $document, $post_id ) { | |
| 109 | - if ( $is_preview ) { | |
| 90 | + if ( $is_preview ) { | |
| 91 | + $markdown = ( new Markdown_Renderer() )->render( $document ); | |
| 92 | + } else { | |
| 93 | + $markdown = $this->get_cached_markdown( $post_id ); | |
| 94 | + | |
| 95 | + if ( false === $markdown ) { | |
| 110 | 96 | $markdown = ( new Markdown_Renderer() )->render( $document ); |
| 111 | - } else { | |
| 112 | - $markdown = $this->get_cached_markdown( $post_id ); | |
| 113 | - | |
| 114 | - if ( false === $markdown ) { | |
| 115 | - $markdown = ( new Markdown_Renderer() )->render( $document ); | |
| 116 | - $this->set_cached_markdown( $post_id, $markdown ); | |
| 117 | - } | |
| 97 | + $this->set_cached_markdown( $post_id, $markdown ); | |
| 118 | 98 | } |
| 99 | + } | |
| 119 | 100 | |
| 120 | - Utils::do_not_cache(); | |
| 121 | - status_header( 200 ); | |
| 122 | - header( 'Content-Type: text/markdown; charset=utf-8' ); | |
| 123 | - header( 'X-Content-Type-Options: nosniff' ); | |
| 124 | - Utils::print_unescaped_internal_string( $markdown ); | |
| 125 | - exit; | |
| 126 | - } ); | |
| 101 | + nocache_headers(); | |
| 102 | + status_header( 200 ); | |
| 103 | + header( 'Content-Type: text/markdown; charset=utf-8' ); | |
| 104 | + header( 'X-Content-Type-Options: nosniff' ); | |
| 105 | + echo $markdown; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 106 | + exit; | |
| 127 | 107 | } |
| 128 | 108 | |
| 129 | 109 | private function is_valid_preview_request( int $post_id ): bool { |
| 130 | 110 | if ( ! is_preview() ) { |