TinyMCE:
- When editing pages, add body class with the page template, or `page-template-default`. - Change the page template class when the users select another template, similarly to changing the post type class for posts. Props webmandesign. Fixes #37599. git-svn-id: https://develop.svn.wordpress.org/trunk@38803 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
d3dd6046d5
commit
79fdcbdb07
@ -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.
|
||||
|
@ -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() ) ) );
|
||||
|
Loading…
Reference in New Issue
Block a user