API
3 weeks ago
Admin
3 weeks ago
Ajax
3 weeks ago
ExportImport
3 weeks ago
FormValidator
2 months ago
Frontend
3 weeks ago
Manager
3 weeks ago
API.php
3 weeks ago
Admin.php
2 months ago
Ajax.php
3 weeks ago
Apps.php
3 weeks ago
ContentManager.php
2 months ago
DbQueryUtils.php
2 months ago
ElementVisibilityConditions.php
2 months ago
Frontend.php
2 months ago
HelperFunctions.php
3 weeks ago
KirkiBase.php
3 weeks ago
PostsQueryUtils.php
2 months ago
Staging.php
3 weeks ago
View.php
1 month ago
Frontend.php
77 lines
| 1 | <?php |
| 2 | /** |
| 3 | * This class act like controller for Editor, Iframe, Frontend |
| 4 | * |
| 5 | * @package kirki |
| 6 | */ |
| 7 | |
| 8 | namespace Kirki; |
| 9 | |
| 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | exit; // Exit if accessed directly. |
| 12 | } |
| 13 | |
| 14 | use Kirki\Frontend\Editor; |
| 15 | use Kirki\Frontend\Iframe; |
| 16 | use Kirki\Frontend\TheFrontend; |
| 17 | use Kirki\Manager\TemplateRedirection; |
| 18 | |
| 19 | /** |
| 20 | * Frontend handler class |
| 21 | */ |
| 22 | class Frontend { |
| 23 | |
| 24 | /** |
| 25 | * Initialize the class |
| 26 | * |
| 27 | * @return void |
| 28 | */ |
| 29 | public function __construct() { |
| 30 | new TemplateRedirection(); |
| 31 | $this->plugin_editor_page_or_iframe_or_the_content(); |
| 32 | } |
| 33 | |
| 34 | |
| 35 | /** |
| 36 | * This action trigger when post data loaded done |
| 37 | * |
| 38 | * @param object $post WordPress post object. |
| 39 | * @return void |
| 40 | */ |
| 41 | public function post_loaded( $post ) { |
| 42 | if ( ! HelperFunctions::user_has_editor_access() ) { |
| 43 | //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 44 | wp_die( __( 'Sorry, you are not allowed to access this page.', 'kirki' ) ); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Render the plugin editor page |
| 50 | * |
| 51 | * @return void |
| 52 | */ |
| 53 | public function plugin_editor_page_or_iframe_or_the_content() { |
| 54 | //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 55 | $action = HelperFunctions::sanitize_text( isset( $_GET['action'] ) ? $_GET['action'] : '' ); |
| 56 | $staging_version = isset( $_GET['staging_version'] ) ? intval( HelperFunctions::sanitize_text( $_GET['staging_version'] ) ) : false; |
| 57 | $nonce = HelperFunctions::sanitize_text( isset( $_GET['nonce'] ) ? $_GET['nonce'] : 'false' ); |
| 58 | $preview_staging_version = ( $staging_version && wp_verify_nonce( $nonce, 'kirki_preview_staging_nonce' ) ) ? $staging_version : false; |
| 59 | |
| 60 | if ( $action === KIRKI_EDITOR_ACTION ) { |
| 61 | add_action( 'the_post', array( $this, 'post_loaded' ) ); |
| 62 | |
| 63 | //phpcs:ignore WordPress.Security.NonceVerification.Missing,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 64 | $load_for = HelperFunctions::sanitize_text( isset( $_GET['load_for'] ) ? $_GET['load_for'] : '' ); |
| 65 | if ( $load_for === 'kirki-iframe' ) { |
| 66 | new Iframe( $staging_version ); |
| 67 | } elseif ( $load_for === 'migration' ) { |
| 68 | new TheFrontend( 'migration' ); |
| 69 | } else { |
| 70 | new Editor(); |
| 71 | } |
| 72 | } else { |
| 73 | new TheFrontend( null, $preview_staging_version ); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 |