| 1 | <?php
|
|---|
| 2 | /**
|
|---|
| 3 | * Plugin Name: Customize-Preview Posts
|
|---|
| 4 | * Plugin Author: Nick Halsey
|
|---|
| 5 | * Description: Opens post previews in-page with the Customizer. Experimental.
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | add_action( 'admin_enqueue_scripts', 'customize_preview_posts_enqueue' );
|
|---|
| 9 | function customize_preview_posts_enqueue() {
|
|---|
| 10 | wp_enqueue_script( 'customize-loader' ); // Opens the Customizer in a seamless full-screen iframe with an animation, rather than a pageload; closing returns to existing admin screen although any changes to options on that screen are not updated.
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | add_filter( 'preview_page_link', 'customize_preview_posts_preview_link' );
|
|---|
| 14 | add_filter( 'preview_post_link', 'customize_preview_posts_preview_link' );
|
|---|
| 15 | function customize_preview_posts_preview_link( $url ) {
|
|---|
| 16 | return add_query_arg( array( 'url' => urlencode( $url ) ), admin_url( 'customize.php' ) );
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | add_action( 'admin_footer-post-new.php', 'customize_preview_dont_feel_like_making_another_file_for_this' );
|
|---|
| 20 | add_action( 'admin_footer-post.php', 'customize_preview_dont_feel_like_making_another_file_for_this' );
|
|---|
| 21 | function customize_preview_dont_feel_like_making_another_file_for_this() {
|
|---|
| 22 | ?>
|
|---|
| 23 | <script>
|
|---|
| 24 | jQuery( document ).ready( function( $ ) {
|
|---|
| 25 | $( '#post-preview' ).addClass( 'load-customize' ) // Triggers customize-loader.js.
|
|---|
| 26 | .attr( 'target', '' ).unbind( 'click.post-preview' ); // Don't try to open in a new tab.
|
|---|
| 27 | } ); // @todo: currently seems to require manually saving the draft before it will actually preview new content. In other words, probably need to trigger the auto-save from here, or, the previewing isn't actually working.
|
|---|
| 28 | </script>
|
|---|
| 29 | <?php
|
|---|
| 30 | }
|
|---|