WordPress.org

WordPress MU

Changeset 936


Ignore:
Timestamp:
03/26/07 15:46:27 (7 years ago)
Author:
donncha
Message:

Index allowed_themes by stylesheet path instead of name. (fixes #284)
Important! Make sure you visit and save wp-admin/wpmu-themes.php to update the list!

Location:
trunk/wp-admin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-db.php

    r933 r936  
    628628} 
    629629 
     630function wpmu_get_blog_allowedthemes( $blog_id = 0 ) { 
     631    $themes = get_themes(); 
     632    if( $blog_id == 0 ) 
     633        $blog_allowed_themes = get_option( "allowedthemes" ); 
     634    else  
     635        $blog_allowed_themes = get_blog_option( $blog_id, "allowedthemes" ); 
     636    if( !is_array( $blog_allowed_themes ) || empty( $blog_allowed_themes ) ) { // convert old allowed_themes to new allowedthemes 
     637        if( $blog_id == 0 ) 
     638            $blog_allowed_themes = get_option( "allowed_themes" ); 
     639        else  
     640            $blog_allowed_themes = get_blog_option( $blog_id, "allowed_themes" ); 
     641        if( is_array( $blog_allowed_themes ) ) { 
     642            foreach( $themes as $key => $theme ) { 
     643                $theme_key = wp_specialchars( $theme[ 'Stylesheet' ] ); 
     644                if( isset( $blog_allowed_themes[ $key ] ) == true ) { 
     645                    $blog_allowedthemes[ $theme_key ] = 1; 
     646                } 
     647            } 
     648            $blog_allowed_themes = $blog_allowedthemes; 
     649            if( $blog_id == 0 ) { 
     650                add_option( "allowedthemes", $blog_allowed_themes ); 
     651                delete_option( "allowed_themes" ); 
     652            } else { 
     653                add_blog_option( $blog_id, "allowedthemes", $blog_allowed_themes ); 
     654                delete_blog_option( $blog_id, "allowed_themes" ); 
     655            } 
     656        } 
     657    } 
     658 
     659    return $blog_allowed_themes; 
     660} 
     661 
    630662?> 
  • trunk/wp-admin/themes.php

    r909 r936  
    44$themes = get_themes(); 
    55$ct = current_theme_info(); 
    6 $allowed_themes = get_site_option( "allowed_themes" ); 
    7 if( $allowed_themes == false ) { 
    8     $allowed_themes = array(); 
    9     if( $blog_id != 1 ) 
    10         unset( $allowed_themes[ "WordPress MU Home Default" ] ); 
    11 } 
    12 $blog_allowed_themes = get_option( "allowed_themes" ); 
     6$allowed_themes = get_site_option( "allowedthemes" ); 
     7if( $allowed_themes == false ) 
     8    $allowed_themes = array(); 
    139 
     10$blog_allowed_themes = wpmu_get_blog_allowedthemes(); 
    1411if( is_array( $blog_allowed_themes ) ) 
    1512    $allowed_themes = array_merge( $allowed_themes, $blog_allowed_themes ); 
     13if( $blog_id != 1 ) 
     14    unset( $allowed_themes[ "h3" ] ); 
    1615 
    17 if( isset( $allowed_themes[ $ct->title ] ) == false ) { 
    18     $allowed_themes[ $ct->title ] = true; 
    19 } 
     16if( isset( $allowed_themes[ wp_specialchars( $ct->stylesheet ) ] ) == false ) 
     17    $allowed_themes[ wp_specialchars( $ct->stylesheet ) ] = true; 
     18 
    2019reset( $themes ); 
    21 while( list( $key, $val ) = each( $themes ) ) {  
    22     if( isset( $allowed_themes[ $key ] ) == false ) { 
    23     unset( $themes[ $key ] ); 
     20foreach( $themes as $key => $theme ) { 
     21    if( isset( $allowed_themes[ wp_specialchars( $theme[ 'Stylesheet' ] ) ] ) == false ) { 
     22        unset( $themes[ $key ] ); 
    2423    } 
    2524} 
     
    7675</div> 
    7776 
     77<br style="clear: both" /> 
    7878<h2><?php _e('Available Themes'); ?></h2> 
    7979<?php if ( 1 < count($themes) ) { ?> 
     
    119119?> 
    120120 
    121 <h2><?php _e('Broken Themes'); ?></h2> 
     121<h2><?php _e('Broken Themes'); ?> (Site admin only)</h2> 
    122122<p><?php _e('The following themes are installed but incomplete.  Themes must have a stylesheet and a template.'); ?></p> 
    123123 
  • trunk/wp-admin/wpmu-blogs.php

    r915 r936  
    1414switch( $_GET[ 'action' ] ) { 
    1515    case "editblog": 
    16     $options_table_name = $wpmuBaseTablePrefix . $_GET[ 'id' ] ."_options"; 
    17     $options = $wpdb->get_results( "SELECT * FROM {$options_table_name} WHERE option_name NOT LIKE 'rss%' AND option_name NOT LIKE '%user_roles'", ARRAY_A ); 
    18     $details = $wpdb->get_row( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = '{$_GET[ 'id' ]}'", ARRAY_A ); 
    19  
    20     print "<h2>" . __('Edit Blog') . "</h2>"; 
    21     print "<a href='http://{$details[ 'domain' ]}/'>{$details[ 'domain' ]}</a>"; 
     16        $id = intval( $_GET[ 'id' ] ); 
     17        $options_table_name = "$wpmuBaseTablePrefix{$id}_options"; 
     18        $options = $wpdb->get_results( "SELECT * FROM {$options_table_name} WHERE option_name NOT LIKE 'rss%' AND option_name NOT LIKE '%user_roles'", ARRAY_A ); 
     19        $details = $wpdb->get_row( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = '{$_GET[ 'id' ]}'", ARRAY_A ); 
     20 
     21        print "<h2>" . __('Edit Blog') . "</h2>"; 
     22        print "<a href='http://{$details[ 'domain' ]}/'>{$details[ 'domain' ]}</a>"; 
    2223    ?> 
    2324    <form name="form1" method="post" action="wpmu-edit.php?action=updateblog">  
     
    104105    <td valign='top'> 
    105106    <?php 
    106     $themes = get_themes(); 
    107     $query = "SELECT option_value 
    108               FROM   ".$options_table_name." 
    109           WHERE  option_name = 'allowed_themes'"; 
    110     $blog_allowed_themes = $wpdb->get_var( $query ); 
    111     if( $blog_allowed_themes != false ) 
    112     $blog_allowed_themes = unserialize( $blog_allowed_themes ); 
    113     $allowed_themes = get_site_option( "allowed_themes" ); 
    114     if( $allowed_themes == false ) { 
    115     $allowed_themes = array_keys( $themes ); 
    116     } 
    117     $out = ''; 
    118     while( list( $key, $val ) = each( $themes ) ) {  
    119     if( isset( $allowed_themes[ $key ] ) == false ) { 
    120         if( isset( $blog_allowed_themes[ $key ] ) == true ) { 
    121         $checked = 'checked '; 
    122         } else { 
    123         $checked = ''; 
    124         } 
    125  
    126         $out .= ' 
    127         <tr valign="top">  
    128         <th title="' . htmlspecialchars( $val[ "Description" ] ) . '" scope="row">'.$key.'</th>  
    129         <td><input name="theme['.$key.']" type="checkbox" id="'.$key.'" value="on" '.$checked.'/></td>  
    130         </tr> '; 
     107    $themes = get_themes(); 
     108    $blog_allowed_themes = wpmu_get_blog_allowedthemes( $id ); 
     109    $allowed_themes = get_site_option( "allowedthemes" ); 
     110    if( $allowed_themes == false ) { 
     111        $allowed_themes = array_keys( $themes ); 
    131112    } 
     113    $out = ''; 
     114    foreach( $themes as $key => $theme ) { 
     115        $theme_key = wp_specialchars( $theme[ 'Stylesheet' ] ); 
     116        if( isset( $allowed_themes[ $theme_key ] ) == false ) { 
     117            if( isset( $blog_allowed_themes[ $theme_key ] ) == true ) { 
     118                $checked = 'checked '; 
     119            } else { 
     120                $checked = ''; 
     121            } 
     122 
     123            $out .= ' 
     124            <tr valign="top">  
     125            <th title="' . htmlspecialchars( $theme[ "Description" ] ) . '" scope="row">'.$key.'</th>  
     126            <td><input name="theme['.$theme_key.']" type="checkbox" id="'.$key.'" value="on" '.$checked.'/></td>  
     127            </tr> '; 
     128        } 
    132129    } 
    133130    if( $out != '' ) { 
    134     print "<div class='wrap'><h3>" . __('Blog Themes') . "</h3>"; 
    135     print '<table width="100%" border="0" cellspacing="2" cellpadding="5" class="editform">'; 
    136     print '<tr><th>' . __('Theme') . '</th><th>' . __('Enable') . '</th></tr>'; 
    137     print $out; 
    138     print "</table></div>"; 
    139     } 
     131        print "<div class='wrap'><h3>" . __('Blog Themes') . "</h3>"; 
     132        print '<table width="100%" border="0" cellspacing="2" cellpadding="5" class="editform">'; 
     133        print '<tr><th>' . __('Theme') . '</th><th>' . __('Enable') . '</th></tr>'; 
     134        print $out; 
     135        print "</table></div>"; 
     136    } 
    140137    $blogusers = get_users_of_blog( $_GET[ 'id' ] ); 
    141138    print '<div class="wrap"><h3>' . __('Blog Users') . '</h3>'; 
  • trunk/wp-admin/wpmu-edit.php

    r897 r936  
    159159        if( is_array( $_POST[ 'theme' ] ) ) { 
    160160            $allowed_themes = $_POST[ 'theme' ]; 
    161             $_POST[ 'option' ][ 'allowed_themes' ] = $_POST[ 'theme' ]; 
     161            $_POST[ 'option' ][ 'allowedthemes' ] = $_POST[ 'theme' ]; 
    162162        } else { 
    163             $_POST[ 'option' ][ 'allowed_themes' ] = ''; 
     163            $_POST[ 'option' ][ 'allowedthemes' ] = ''; 
    164164        } 
    165165        if( is_array( $_POST[ 'option' ] ) ) { 
     
    383383    break; 
    384384        case "updatethemes": 
    385         if( is_site_admin() == false ) { 
    386             die( __('<p>You do not have permission to access this page.</p>') ); 
    387         } 
     385        if( is_site_admin() == false ) 
     386            die( __('<p>You do not have permission to access this page.</p>') ); 
     387 
    388388            if( is_array( $_POST[ 'theme' ] ) ) { 
    389             $themes = array_flip( array_keys( get_themes() ) ); 
     389            $themes = get_themes(); 
    390390            reset( $themes ); 
    391             while( list( $key, $val ) = each( $themes ) )  
    392             { 
    393                 if( $_POST[ 'theme' ][ addslashes( $key ) ] == 'enabled' ) 
    394                     $allowed_themes[ $key ] = true; 
    395             } 
    396             update_site_option( 'allowed_themes', $allowed_themes ); 
     391            foreach( $themes as $key => $theme ) { 
     392                if( $_POST[ 'theme' ][ wp_specialchars( $theme[ 'Stylesheet' ] ) ] == 'enabled' ) 
     393                    $allowed_themes[ wp_specialchars( $theme[ 'Stylesheet' ] ) ] = true; 
     394            } 
     395            update_site_option( 'allowedthemes', $allowed_themes ); 
    397396        } 
    398397        wp_redirect( add_query_arg( "updated", "themesupdated", $_SERVER[ 'HTTP_REFERER' ] ) ); 
Note: See TracChangeset for help on using the changeset viewer.