Facades
3 days ago
Canvas.php
3 weeks ago
CollectionItem.php
3 weeks ago
ContentManager.php
3 weeks ago
DateTime.php
3 weeks ago
EditorPreview.php
3 days ago
FileHandler.php
3 days ago
FilterHooks.php
3 days ago
PageUrl.php
3 days ago
Role.php
3 weeks ago
Template.php
3 days ago
EditorPreview.php
41 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kirki\App\Supports; |
| 4 | |
| 5 | defined('ABSPATH') || exit; |
| 6 | |
| 7 | use Kirki\App\Constants\GlobalDataKeys; |
| 8 | use Kirki\App\Supports\Facades\GlobalData; |
| 9 | |
| 10 | use function Kirki\App\get_request_header; |
| 11 | use function Kirki\App\is_falsy; |
| 12 | |
| 13 | class EditorPreview |
| 14 | { |
| 15 | protected static function has_token() |
| 16 | { |
| 17 | return !empty(static::get_token_from_header()); |
| 18 | } |
| 19 | |
| 20 | public static function has_valid_token() |
| 21 | { |
| 22 | if (!static::has_token()) { |
| 23 | return false; |
| 24 | } |
| 25 | |
| 26 | $status = GlobalData::get(GlobalDataKeys::EDITOR_READ_ONLY_ACCESS_STATUS); |
| 27 | |
| 28 | if (is_falsy($status)) { |
| 29 | return false; |
| 30 | } |
| 31 | |
| 32 | $editor_read_only_access_token = GlobalData::get(GlobalDataKeys::EDITOR_READ_ONLY_ACCESS_TOKEN); |
| 33 | |
| 34 | return $editor_read_only_access_token && $editor_read_only_access_token === static::get_token_from_header(); |
| 35 | } |
| 36 | |
| 37 | public static function get_token_from_header() |
| 38 | { |
| 39 | return get_request_header('Editor-Preview-Token'); |
| 40 | } |
| 41 | } |