block-based-templates
1 month ago
styles
4 years ago
customizer-options.php
1 year ago
editor-hooks.php
1 year ago
fallback-compatibility.php
4 years ago
front-page.html
2 years ago
frontend-hooks.php
1 year ago
preview.php
4 years ago
templates-importer.php
1 year ago
templates.php
1 year ago
third-party-themes.php
1 year ago
editor-hooks.php
97 lines
| 1 | <?php |
| 2 | |
| 3 | use IlluminateAgnostic\Arr\Support\Arr; |
| 4 | |
| 5 | function kubio_hybrid_theme_post_content_placeholder( $content ) { |
| 6 | global $post; |
| 7 | if ( $post && $post->post_type === 'page' ) { |
| 8 | return '<div id="kubio-site-edit-content-holder"></div>'; |
| 9 | } |
| 10 | |
| 11 | return $content; |
| 12 | } |
| 13 | |
| 14 | function kubio_hybrid_theme_assets_holder() { |
| 15 | ?> |
| 16 | <meta style="display:none" id="kubio-site-edit-assets-holder"></meta> |
| 17 | <?php |
| 18 | } |
| 19 | |
| 20 | |
| 21 | function kubio_hybrid_theme_iframe_hide_admin_bar() { |
| 22 | show_admin_bar( false ); |
| 23 | } |
| 24 | |
| 25 | if ( kubio_is_hybdrid_theme_iframe_preview() ) { |
| 26 | add_filter( 'the_content', 'kubio_hybrid_theme_post_content_placeholder', 0, 1 ); |
| 27 | add_action( 'wp_head', 'kubio_hybrid_theme_assets_holder', 0 ); |
| 28 | add_action( 'after_setup_theme', 'kubio_hybrid_theme_iframe_hide_admin_bar' ); |
| 29 | add_action( 'template_include', 'kubio_hybrid_theme_load_template' ); |
| 30 | add_action( 'page_template', 'kubio_hybrid_theme_load_template', PHP_INT_MAX, 1 ); |
| 31 | |
| 32 | } |
| 33 | |
| 34 | function kubio_hybrid_theme_load_template( $template ) { |
| 35 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 36 | $template_id = Arr::get( $_REQUEST, '__kubio-site-edit-iframe-classic-template', false ); |
| 37 | if ( ! $template_id ) { |
| 38 | return $template; |
| 39 | } |
| 40 | |
| 41 | |
| 42 | if(!kubio_get_is_valid_classic_template_id($template_id)) { |
| 43 | return $template; |
| 44 | } |
| 45 | |
| 46 | |
| 47 | $new_template = locate_template( array( $template_id ) ); |
| 48 | if ( '' !== $new_template ) { |
| 49 | return $new_template; |
| 50 | } |
| 51 | return $template; |
| 52 | } |
| 53 | |
| 54 | function kubio_get_is_valid_classic_template_id($template_id) { |
| 55 | |
| 56 | $theme = wp_get_theme(); |
| 57 | $templates = $theme->get_page_templates(); |
| 58 | $default_templates = [ |
| 59 | 'index.php', |
| 60 | 'front-page.php', |
| 61 | 'home.php', |
| 62 | 'single.php', |
| 63 | 'page.php', |
| 64 | 'archive.php', |
| 65 | 'category.php', |
| 66 | 'tag.php', |
| 67 | 'taxonomy.php', |
| 68 | 'author.php', |
| 69 | 'date.php', |
| 70 | 'search.php', |
| 71 | 'attachment.php', |
| 72 | 'image.php', |
| 73 | 'video.php', |
| 74 | 'audio.php', |
| 75 | '404.php', |
| 76 | ]; |
| 77 | $theme_templates_values = array_keys($templates); |
| 78 | $merged_templates = array_merge($theme_templates_values, $default_templates); |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | $value = in_array(strtolower($template_id), array_map('strtolower', $merged_templates)); |
| 84 | return $value; |
| 85 | } |
| 86 | |
| 87 | function kubio_wp_redirect_maybe_add_hybrid_theme_query_param( $location ) { |
| 88 | |
| 89 | if ( kubio_is_hybdrid_theme_iframe_preview() ) { |
| 90 | $location = add_query_arg( KUBIO_3RD_PARTY_THEME_EDITOR_QUERY_PARAM, 'true', $location ); |
| 91 | } |
| 92 | |
| 93 | return $location; |
| 94 | } |
| 95 | |
| 96 | add_filter( 'wp_redirect', 'kubio_wp_redirect_maybe_add_hybrid_theme_query_param' ); |
| 97 |