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
preview.php
54 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | // function kubio_preview_third_pa |
| 5 | |
| 6 | use IlluminateAgnostic\Arr\Support\Arr; |
| 7 | |
| 8 | function kubio_third_party_theme_preview_content( $content ) { |
| 9 | $autosaved_posts = kubio_get_current_changeset_data( 'autosaves', array() ); |
| 10 | $post_id = get_the_ID(); |
| 11 | |
| 12 | foreach ( $autosaved_posts as $map ) { |
| 13 | if ( Arr::get( $map, 'parent' ) === $post_id ) { |
| 14 | $autosaved = get_post( Arr::get( $map, 'id' ) ); |
| 15 | if ( ! is_wp_error( $autosaved ) ) { |
| 16 | $content = $autosaved->post_content; |
| 17 | } |
| 18 | break; |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | return $content; |
| 23 | } |
| 24 | |
| 25 | function kubio_third_party_theme_prepare_preview_post_content( $template ) { |
| 26 | if ( kubio_is_page_preview() ) { |
| 27 | global $_wp_current_template_content, $post; |
| 28 | |
| 29 | $is_previewing_3rd_party_theme_template = kubio_3rd_party_theme_is_previewing_theme_template(); |
| 30 | |
| 31 | if ( ( ! $_wp_current_template_content || $is_previewing_3rd_party_theme_template ) && $post && $post->post_type === 'page' ) { |
| 32 | $page_id = $post ? intval( $post->ID ) : null; |
| 33 | |
| 34 | add_filter( |
| 35 | 'the_content', |
| 36 | function ( $content ) use ( $page_id ) { |
| 37 | global $kubio_third_party_theme_preview_post_content_executed; |
| 38 | $current_post = get_post(); |
| 39 | if ( ! $kubio_third_party_theme_preview_post_content_executed && $page_id === $current_post->ID ) { |
| 40 | $kubio_third_party_theme_preview_post_content_executed = true; |
| 41 | return kubio_third_party_theme_preview_content( $content ); |
| 42 | } |
| 43 | return $content; |
| 44 | }, |
| 45 | 0 |
| 46 | ); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return $template; |
| 51 | } |
| 52 | |
| 53 | add_action( 'template_include', 'kubio_third_party_theme_prepare_preview_post_content', 500 ); |
| 54 |