Make WordPress Core


Ignore:
Timestamp:
05/20/2008 05:19:33 PM (16 years ago)
Author:
ryan
Message:

Theme preview and thickbox CSS cleanup. Props azaozz. see #5486

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/theme.php

    r7921 r7961  
    480480}
    481481
     482function preview_theme() {
     483    if ( ! (isset($_GET['template']) && isset($_GET['preview'])) )
     484        return;
     485
     486    if ( !current_user_can( 'switch_themes' ) )
     487        return;
     488
     489    $_GET[template] = preg_replace('|[^a-z0-9]|i', '', $_GET[template]);
     490
     491    add_filter('template', create_function('', "return '$_GET[template]';") );
     492
     493    if ( isset($_GET['stylesheet']) ) {
     494        $_GET[stylesheet] = preg_replace('|[^a-z0-9]|i', '', $_GET[stylesheet]);
     495        add_filter('stylesheet', create_function('', "return '$_GET[stylesheet]';") );
     496    }
     497
     498    ob_start( 'preview_theme_ob_filter' );
     499}
     500add_action('setup_theme', 'preview_theme');
     501
     502function preview_theme_ob_filter( $content ) {
     503    return preg_replace_callback( "|(<a.*?href=([\"']))(.*?)([\"'].*?>)|", 'preview_theme_ob_filter_callback', $content );
     504}
     505
     506function preview_theme_ob_filter_callback( $matches ) {
     507    if (
     508        ( false !== strpos($matches[3], '/wp-admin/') )
     509    ||
     510        ( false !== strpos($matches[3], '://') && 0 !== strpos($matches[3], get_option('home')) )
     511    ||
     512        ( false !== strpos($matches[3], '/feed/') )
     513    ||
     514        ( false !== strpos($matches[3], '/trackback/') )
     515    )
     516        return $matches[1] . "#$matches[2] onclick=$matches[2]return false;" . $matches[4];
     517
     518    $link = add_query_arg( array('preview' => 1, 'template' => $_GET['template'], 'stylesheet' => @$_GET['stylesheet'] ), $matches[3] );
     519    if ( 0 === strpos($link, 'preview=1') )
     520        $link = "?$link";
     521    return $matches[1] . attribute_escape( $link ) . $matches[4];
     522}
     523
    482524function switch_theme($template, $stylesheet) {
    483525    update_option('template', $template);
Note: See TracChangeset for help on using the changeset viewer.