From e52de33dc29b41b4fb6cf97fccaa066fa3f6b734 Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 18 Jan 2010 23:34:36 +0000 Subject: [PATCH] Multisite and formatting cleanups. Introduce get_allowed_themes(). see #11644 git-svn-id: http://svn.automattic.com/wordpress/trunk@12755 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/theme.php | 39 +++++++++++++++++++++++++++++++++++++ wp-admin/includes/user.php | 27 +++++++++++++------------ wp-admin/themes.php | 27 +------------------------ wp-includes/load.php | 19 ++++++++---------- 4 files changed, 61 insertions(+), 51 deletions(-) diff --git a/wp-admin/includes/theme.php b/wp-admin/includes/theme.php index 1f4fbefad..67f2e6f90 100644 --- a/wp-admin/includes/theme.php +++ b/wp-admin/includes/theme.php @@ -116,6 +116,45 @@ function get_broken_themes() { return $wp_broken_themes; } +/** + * Get the allowed themes for the current blog. + * + * @since 3.0 + * + * @uses get_themes() + * @uses current_theme_info() + * @uses get_site_allowed_themes() + * @uses wpmu_get_blog_allowedthemes + * + * @return array $themes Array of allowed themes. + */ +function get_allowed_themes() { + if ( !is_multisite() ) + return get_themes(); + + $themes = get_themes(); + $ct = current_theme_info(); + $allowed_themes = apply_filters("allowed_themes", get_site_allowed_themes() ); + if ( $allowed_themes == false ) + $allowed_themes = array(); + + $blog_allowed_themes = wpmu_get_blog_allowedthemes(); + if ( is_array( $blog_allowed_themes ) ) + $allowed_themes = array_merge( $allowed_themes, $blog_allowed_themes ); + + if ( isset( $allowed_themes[ wp_specialchars( $ct->stylesheet ) ] ) == false ) + $allowed_themes[ wp_specialchars( $ct->stylesheet ) ] = true; + + reset( $themes ); + foreach ( $themes as $key => $theme ) { + if ( isset( $allowed_themes[ wp_specialchars( $theme[ 'Stylesheet' ] ) ] ) == false ) + unset( $themes[ $key ] ); + } + reset( $themes ); + + return $themes; +} + /** * Get the Page Templates available in this theme * diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php index a70b0bb81..448efee65 100644 --- a/wp-admin/includes/user.php +++ b/wp-admin/includes/user.php @@ -197,11 +197,11 @@ function edit_user( $user_id = 0 ) { */ function get_author_user_ids() { global $wpdb; - if( !is_multisite() ) { + if ( !is_multisite() ) $level_key = $wpdb->get_blog_prefix() . 'user_level'; - } else { + else $level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels - } + return $wpdb->get_col( $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s AND meta_value != '0'", $level_key) ); } @@ -220,7 +220,7 @@ function get_editable_authors( $user_id ) { $editable = get_editable_user_ids( $user_id ); - if( !$editable ) { + if ( !$editable ) { return false; } else { $editable = join(',', $editable); @@ -252,11 +252,11 @@ function get_editable_user_ids( $user_id, $exclude_zeros = true, $post_type = 'p else return array(); } - if( !is_multisite() ) { + + if ( !is_multisite() ) $level_key = $wpdb->get_blog_prefix() . 'user_level'; - } else { + else $level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels - } $query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s", $level_key); if ( $exclude_zeros ) @@ -302,11 +302,10 @@ function get_editable_roles() { function get_nonauthor_user_ids() { global $wpdb; - if ( !is_multisite() ) { + if ( !is_multisite() ) $level_key = $wpdb->get_blog_prefix() . 'user_level'; - } else { + else $level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels - } return $wpdb->get_col( $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s AND meta_value = '0'", $level_key) ); } @@ -332,7 +331,7 @@ function get_others_unpublished_posts($user_id, $type='any') { $dir = ( 'pending' == $type ) ? 'ASC' : 'DESC'; - if( !$editable ) { + if ( !$editable ) { $other_unpubs = ''; } else { $editable = join(',', $editable); @@ -675,11 +674,11 @@ class WP_User_Search { } $this->query_from_where = "FROM $wpdb->users"; - if ( $this->role ) + if ( $this->role ) { $this->query_from_where .= $wpdb->prepare(" INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id WHERE $wpdb->usermeta.meta_key = '{$wpdb->prefix}capabilities' AND $wpdb->usermeta.meta_value LIKE %s", '%' . $this->role . '%'); - elseif ( !is_multisite() ) + } elseif ( !is_multisite() ) { $this->query_from_where .= " WHERE 1=1"; - else { + } else { $level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels $this->query_from_where .= ", $wpdb->usermeta WHERE $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '{$level_key}'"; } diff --git a/wp-admin/themes.php b/wp-admin/themes.php index bdb50c7f7..8aba22d64 100644 --- a/wp-admin/themes.php +++ b/wp-admin/themes.php @@ -12,30 +12,6 @@ require_once('admin.php'); if ( !current_user_can('switch_themes') ) wp_die( __( 'Cheatin’ uh?' ) ); -if ( is_multisite() ) { - $themes = get_themes(); - $ct = current_theme_info(); - $allowed_themes = apply_filters("allowed_themes", get_site_allowed_themes() ); - if ( $allowed_themes == false ) - $allowed_themes = array(); - - $blog_allowed_themes = wpmu_get_blog_allowedthemes(); - if ( is_array( $blog_allowed_themes ) ) - $allowed_themes = array_merge( $allowed_themes, $blog_allowed_themes ); - if ( $blog_id != 1 ) - unset( $allowed_themes[ "h3" ] ); - - if ( isset( $allowed_themes[ wp_specialchars( $ct->stylesheet ) ] ) == false ) - $allowed_themes[ wp_specialchars( $ct->stylesheet ) ] = true; - - reset( $themes ); - foreach ( $themes as $key => $theme ) { - if ( isset( $allowed_themes[ wp_specialchars( $theme[ 'Stylesheet' ] ) ] ) == false ) { - unset( $themes[ $key ] ); - } - } - reset( $themes ); -} if ( isset($_GET['action']) ) { if ( 'activate' == $_GET['action'] ) { check_admin_referer('switch-theme_' . $_GET['template']); @@ -85,8 +61,7 @@ if ( is_multisite() && current_user_can('edit_themes') ) { name]); diff --git a/wp-includes/load.php b/wp-includes/load.php index 2db9e2c6e..4b4ae6ceb 100644 --- a/wp-includes/load.php +++ b/wp-includes/load.php @@ -260,20 +260,17 @@ function wp_start_object_cache() { } wp_cache_init(); + if ( function_exists('wp_cache_add_global_groups') ) { - if( is_multisite() ) { - wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss')); - } else { - wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta', 'site-transient')); - } + wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss')); wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' )); } } function wp_not_installed() { if ( is_multisite() ) { - if ( !is_blog_installed() && !defined('WP_INSTALLING') ) - die( __( 'The blog you have requested is not installed properly. Please contact the system administrator.' ) ); // have to die here ~ Mark + if ( !is_blog_installed() && !defined('WP_INSTALLING') ) + die( __( 'The blog you have requested is not installed properly. Please contact the system administrator.' ) ); // have to die here } elseif ( !is_blog_installed() && (strpos($_SERVER['PHP_SELF'], 'install.php') === false && !defined('WP_INSTALLING')) ) { if ( defined('WP_SITEURL') ) $link = WP_SITEURL . '/wp-admin/install.php'; @@ -293,13 +290,13 @@ function wp_load_mu_plugins() { if ( is_dir( WPMU_PLUGIN_DIR ) ) { if ( $dh = opendir( WPMU_PLUGIN_DIR ) ) { $mu_plugins = array (); - while ( ( $plugin = readdir( $dh ) ) !== false ) + while ( ( $plugin = readdir( $dh ) ) !== false ) { if ( substr( $plugin, -4 ) == '.php' ) $mu_plugins[] = $plugin; + } closedir( $dh ); - if( is_multisite() ) - sort( $mu_plugins ); - foreach( $mu_plugins as $mu_plugin ) + sort( $mu_plugins ); + foreach ( $mu_plugins as $mu_plugin ) include_once( WPMU_PLUGIN_DIR . '/' . $mu_plugin ); } }