| 1 |
<?php |
| 2 |
namespace Elementor\Core\Frontend; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
class Widget_Content_Render_Mode { |
| 9 |
|
| 10 |
const NORMAL = 'normal'; |
| 11 |
|
| 12 |
const MARKDOWN = 'markdown'; |
| 13 |
|
| 14 |
private static $current_mode = self::NORMAL; |
| 15 |
|
| 16 |
public static function get_current(): string { |
| 17 |
return self::$current_mode; |
| 18 |
} |
| 19 |
|
| 20 |
public static function set_current( string $mode ): void { |
| 21 |
self::$current_mode = $mode; |
| 22 |
} |
| 23 |
|
| 24 |
public static function is( string $mode ): bool { |
| 25 |
return self::get_current() === $mode; |
| 26 |
} |
| 27 |
|
| 28 |
public static function execute_as( string $mode, callable $callback ) { |
| 29 |
$previous_mode = self::get_current(); |
| 30 |
$should_reset = $previous_mode !== $mode; |
| 31 |
|
| 32 |
if ( $should_reset ) { |
| 33 |
self::set_current( $mode ); |
| 34 |
} |
| 35 |
|
| 36 |
try { |
| 37 |
return $callback(); |
| 38 |
} finally { |
| 39 |
if ( $should_reset ) { |
| 40 |
self::set_current( $previous_mode ); |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|