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

git-svn-id: http://svn.automattic.com/wordpress/trunk@20144 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2012-03-07 23:32:06 +00:00
parent 71eee3357d
commit 4029d120a2

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 ];