WordPress.org

Make WordPress Core

Changeset 13441


Ignore:
Timestamp:
02/26/2010 08:12:06 PM (8 years ago)
Author:
nacin
Message:

Introduce add_editor_style() to easily register a stylesheet for the visual editor. see #11512 see #9015

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/twentyten/functions.php

    r13417 r13441  
    2828
    2929    add_custom_background();
     30
     31    // This theme styles the visual editor with editor-style.css to match the theme style.
     32    add_editor_style();
    3033
    3134    // This theme needs post thumbnails
     
    134137}
    135138endif;
    136 
    137 // Make the Visual Editor styles match the theme's styles
    138 if ( ! function_exists( 'twentyten_editor_style' ) ) :
    139 function twentyten_editor_style( $url ) {
    140     if ( ! empty( $url ) )
    141         $url .= ',';
    142 
    143     // Change the path here if using sub-directory
    144     $url .= trailingslashit( get_stylesheet_directory_uri() ) . 'editor-style.css';
    145 
    146     return $url;
    147 }
    148 endif;
    149 add_filter( 'mce_css', 'twentyten_editor_style' );
    150139
    151140// Remove inline styles on gallery shortcode
  • trunk/wp-includes/theme.php

    r13417 r13441  
    14481448
    14491449/**
     1450 * Add callback for a custom TinyMCE editor stylesheet.
     1451 *
     1452 * The parameter $stylesheet is the name of the stylesheet, relative to
     1453 * the theme root. It is optional and defaults to 'editor-style.css'.
     1454 *
     1455 * @since 3.0.0
     1456 *
     1457 * @param callback $stylesheet Name of stylesheet relative to theme root.
     1458 */
     1459function add_editor_style( $stylesheet = 'editor-style.css' ) {
     1460    if ( isset( $GLOBALS['editor_style'] ) )
     1461        return;
     1462
     1463    add_theme_support( 'editor-style' );
     1464
     1465    if ( ! is_admin() )
     1466        return;
     1467
     1468    $GLOBALS['editor_style'] = $stylesheet;
     1469    add_filter( 'mce_css', '_editor_style_cb' );
     1470}
     1471
     1472/**
     1473 * Callback for custom editor stylesheet.
     1474 *
     1475 * @since 3.0.0
     1476 * @see add_editor_style()
     1477 * @access protected
     1478 */
     1479function _editor_style_cb( $url ) {
     1480    global $editor_style;
     1481    if ( ! empty( $url ) )
     1482        $url .= ',';
     1483    return $url . get_stylesheet_directory_uri() . "/$editor_style";
     1484}
     1485
     1486/**
    14501487 * Allows a theme to register its support of a certain feature
    14511488 *
Note: See TracChangeset for help on using the changeset viewer.