WordPress.org

Make WordPress Core

Changeset 20144


Ignore:
Timestamp:
03/07/2012 11:32:06 PM (10 years ago)
Author:
nacin
Message:

Provide back compat for allowed_themes option keys, which were from the early days of WordPress MU. see #20103. Curses.

File:
1 edited

Legend:

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

    r20132 r20144  
    10831083    public static function get_allowed_on_network() {
    10841084        static $allowed_themes;
    1085         if ( ! isset( $allowed_themes ) )
    1086             $allowed_themes = (array) get_site_option( 'allowedthemes' );
     1085        if ( isset( $allowed_themes ) )
     1086            return $allowed_themes;
     1087
     1088        $allowed_themes = get_site_option( 'allowedthemes' );
     1089
     1090        // This is all super old MU back compat joy.
     1091        // 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
     1092        if ( false === $allowed_themes ) {
     1093            $allowed_themes = get_site_option( 'allowed_themes' );
     1094            if ( ! is_array( $allowed_themes ) || empty( $allowed_themes ) ) {
     1095                $allowed_themes = array();
     1096            } else {
     1097                $converted = array();
     1098                $themes = wp_get_themes();
     1099                foreach ( $themes as $stylesheet => $theme_data ) {
     1100                    if ( isset( $allowed_themes[ $theme_data->get('Name') ] ) )
     1101                        $converted[ $stylesheet ] = true;
     1102                }
     1103                $allowed_themes = $converted;
     1104            }
     1105            // Set the option so we never have to go through this pain again.
     1106            if ( is_admin() ) {
     1107                update_site_option( 'allowedthemes', $allowed_themes );
     1108                delete_site_option( 'allowed_themes' );
     1109            }
     1110        }
     1111
    10871112        return $allowed_themes;
    10881113    }
     
    10991124    public static function get_allowed_on_site( $blog_id = null ) {
    11001125        static $allowed_themes = array();
     1126
    11011127        if ( ! $blog_id )
    11021128            $blog_id = get_current_blog_id();
    11031129
    1104         if ( ! isset( $allowed_themes[ $blog_id ] ) ) {
    1105             if ( $blog_id == get_current_blog_id() )
    1106                 $allowed_themes[ $blog_id ] = (array) get_option( 'allowedthemes' );
     1130        if ( isset( $allowed_themes[ $blog_id ] ) )
     1131            return $allowed_themes[ $blog_id ];
     1132
     1133        $current = $blog_id == get_current_blog_id();
     1134
     1135        if ( $current )
     1136            $allowed_themes[ $blog_id ] = get_option( 'allowedthemes' );
     1137        else
     1138            $allowed_themes[ $blog_id ] = get_blog_option( $blog_id, 'allowedthemes' );
     1139
     1140        // This is all super old MU back compat joy.
     1141        // 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
     1142        if ( false === $allowed_themes[ $blog_id ] ) {
     1143            if ( $current )
     1144                $allowed_themes[ $blog_id ] = get_option( 'allowed_themes' );
    11071145            else
    1108                 $allowed_themes[ $blog_id ] = (array) get_blog_option( $blog_id, 'allowedthemes' );
     1146                $allowed_themes[ $blog_id ] = get_blog_option( $blog_id, 'allowed_themes' );
     1147
     1148            if ( ! is_array( $allowed_themes[ $blog_id ] ) || empty( $allowed_themes[ $blog_id ] ) ) {
     1149                $allowed_themes[ $blog_id ] = array();
     1150            } else {
     1151                $converted = array();
     1152                $themes = wp_get_themes();
     1153                foreach ( $themes as $stylesheet => $theme_data ) {
     1154                    if ( isset( $allowed_themes[ $blog_id ][ $theme_data->get('Name') ] ) )
     1155                        $converted[ $stylesheet ] = true;
     1156                }
     1157                $allowed_themes[ $blog_id ] = $converted;
     1158            }
     1159            // Set the option so we never have to go through this pain again.
     1160            if ( is_admin() ) {
     1161                if ( $current ) {
     1162                    update_option( 'allowedthemes', $allowed_themes[ $blog_id ] );
     1163                    delete_option( 'allowed_themes' );
     1164                } else {
     1165                    update_blog_option( $blog_id, 'allowedthemes', $allowed_themes[ $blog_id ] );
     1166                    delete_blog_option( $blog_id, 'allowed_themes' );
     1167                }
     1168            }
    11091169        }
    11101170
Note: See TracChangeset for help on using the changeset viewer.