Make WordPress Core

Ticket #29071: customize-preview-posts.php

File customize-preview-posts.php, 1.6 KB (added by celloexpressions, 12 years ago)

Experimental plugin that opens the Customizer via customize-loader when previewing posts, for demo purposes.

Line 
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
8add_action( 'admin_enqueue_scripts', 'customize_preview_posts_enqueue' );
9function 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
13add_filter( 'preview_page_link', 'customize_preview_posts_preview_link' );
14add_filter( 'preview_post_link', 'customize_preview_posts_preview_link' );
15function customize_preview_posts_preview_link( $url ) {
16 return add_query_arg( array( 'url' => urlencode( $url ) ), admin_url( 'customize.php' ) );
17}
18
19add_action( 'admin_footer-post-new.php', 'customize_preview_dont_feel_like_making_another_file_for_this' );
20add_action( 'admin_footer-post.php', 'customize_preview_dont_feel_like_making_another_file_for_this' );
21function 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}