diff --git a/src/wp-admin/js/post.js b/src/wp-admin/js/post.js index b5424599d9..dfbc6dbb13 100644 --- a/src/wp-admin/js/post.js +++ b/src/wp-admin/js/post.js @@ -1167,6 +1167,23 @@ jQuery(document).ready( function($) { $( document ).trigger( 'editor-classchange' ); } }); + + // When changing page template, change the editor body class + $( '#page_template' ).on( 'change.set-editor-class', function() { + var editor, body, pageTemplate = $( this ).val() || ''; + + pageTemplate = pageTemplate.substr( pageTemplate.lastIndexOf( '/' ) + 1, pageTemplate.length ) + .replace( /\.php$/, '' ) + .replace( /\./g, '-' ); + + if ( pageTemplate && ( editor = tinymce.get( 'content' ) ) ) { + body = editor.getBody(); + body.className = body.className.replace( /\bpage-template-[^ ]+/, '' ); + editor.dom.addClass( body, 'page-template-' + pageTemplate ); + $( document ).trigger( 'editor-classchange' ); + } + }); + } // Save on pressing [ctrl]/[command] + [s] in the Text editor. diff --git a/src/wp-includes/class-wp-editor.php b/src/wp-includes/class-wp-editor.php index ab97513203..c7267c0c05 100644 --- a/src/wp-includes/class-wp-editor.php +++ b/src/wp-includes/class-wp-editor.php @@ -663,6 +663,7 @@ final class _WP_Editors { if ( $post = get_post() ) { $body_class .= ' post-type-' . sanitize_html_class( $post->post_type ) . ' post-status-' . sanitize_html_class( $post->post_status ); + if ( post_type_supports( $post->post_type, 'post-formats' ) ) { $post_format = get_post_format( $post ); if ( $post_format && ! is_wp_error( $post_format ) ) @@ -670,6 +671,11 @@ final class _WP_Editors { else $body_class .= ' post-format-standard'; } + + if ( $page_template = get_page_template_slug( $post ) ) { + $page_template = str_replace( '.', '-', basename( $page_template, '.php' ) ); + $body_class .= ' page-template-' . sanitize_html_class( $page_template ); + } } $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );