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

git-svn-id: https://develop.svn.wordpress.org/trunk@20144 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2012-03-07 23:32:06 +00:00
parent 8ae9285c2a
commit 68bc832f61
1 changed files with 66 additions and 6 deletions

View File

@ -1082,8 +1082,33 @@ final class WP_Theme implements ArrayAccess {
*/
public static function get_allowed_on_network() {
static $allowed_themes;
if ( ! isset( $allowed_themes ) )
$allowed_themes = (array) get_site_option( 'allowedthemes' );
if ( isset( $allowed_themes ) )
return $allowed_themes;
$allowed_themes = get_site_option( 'allowedthemes' );
// This is all super old MU back compat joy.
// 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
if ( false === $allowed_themes ) {
$allowed_themes = get_site_option( 'allowed_themes' );
if ( ! is_array( $allowed_themes ) || empty( $allowed_themes ) ) {
$allowed_themes = array();
} else {
$converted = array();
$themes = wp_get_themes();
foreach ( $themes as $stylesheet => $theme_data ) {
if ( isset( $allowed_themes[ $theme_data->get('Name') ] ) )
$converted[ $stylesheet ] = true;
}
$allowed_themes = $converted;
}
// Set the option so we never have to go through this pain again.
if ( is_admin() ) {
update_site_option( 'allowedthemes', $allowed_themes );
delete_site_option( 'allowed_themes' );
}
}
return $allowed_themes;
}
@ -1098,14 +1123,49 @@ final class WP_Theme implements ArrayAccess {
*/
public static function get_allowed_on_site( $blog_id = null ) {
static $allowed_themes = array();
if ( ! $blog_id )
$blog_id = get_current_blog_id();
if ( ! isset( $allowed_themes[ $blog_id ] ) ) {
if ( $blog_id == get_current_blog_id() )
$allowed_themes[ $blog_id ] = (array) get_option( 'allowedthemes' );
if ( isset( $allowed_themes[ $blog_id ] ) )
return $allowed_themes[ $blog_id ];
$current = $blog_id == get_current_blog_id();
if ( $current )
$allowed_themes[ $blog_id ] = get_option( 'allowedthemes' );
else
$allowed_themes[ $blog_id ] = get_blog_option( $blog_id, 'allowedthemes' );
// This is all super old MU back compat joy.
// 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name.
if ( false === $allowed_themes[ $blog_id ] ) {
if ( $current )
$allowed_themes[ $blog_id ] = get_option( 'allowed_themes' );
else
$allowed_themes[ $blog_id ] = (array) get_blog_option( $blog_id, 'allowedthemes' );
$allowed_themes[ $blog_id ] = get_blog_option( $blog_id, 'allowed_themes' );
if ( ! is_array( $allowed_themes[ $blog_id ] ) || empty( $allowed_themes[ $blog_id ] ) ) {
$allowed_themes[ $blog_id ] = array();
} else {
$converted = array();
$themes = wp_get_themes();
foreach ( $themes as $stylesheet => $theme_data ) {
if ( isset( $allowed_themes[ $blog_id ][ $theme_data->get('Name') ] ) )
$converted[ $stylesheet ] = true;
}
$allowed_themes[ $blog_id ] = $converted;
}
// Set the option so we never have to go through this pain again.
if ( is_admin() ) {
if ( $current ) {
update_option( 'allowedthemes', $allowed_themes[ $blog_id ] );
delete_option( 'allowed_themes' );
} else {
update_blog_option( $blog_id, 'allowedthemes', $allowed_themes[ $blog_id ] );
delete_blog_option( $blog_id, 'allowed_themes' );
}
}
}
return $allowed_themes[ $blog_id ];