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
This commit is contained in:
ryan 2010-01-18 23:34:36 +00:00
parent d0e599c50b
commit e52de33dc2
4 changed files with 61 additions and 51 deletions

View File

@ -116,6 +116,45 @@ function get_broken_themes() {
return $wp_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 * Get the Page Templates available in this theme
* *

View File

@ -197,11 +197,11 @@ function edit_user( $user_id = 0 ) {
*/ */
function get_author_user_ids() { function get_author_user_ids() {
global $wpdb; global $wpdb;
if( !is_multisite() ) { if ( !is_multisite() )
$level_key = $wpdb->get_blog_prefix() . 'user_level'; $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 $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) ); 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 ); $editable = get_editable_user_ids( $user_id );
if( !$editable ) { if ( !$editable ) {
return false; return false;
} else { } else {
$editable = join(',', $editable); $editable = join(',', $editable);
@ -252,11 +252,11 @@ function get_editable_user_ids( $user_id, $exclude_zeros = true, $post_type = 'p
else else
return array(); return array();
} }
if( !is_multisite() ) {
if ( !is_multisite() )
$level_key = $wpdb->get_blog_prefix() . 'user_level'; $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 $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); $query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s", $level_key);
if ( $exclude_zeros ) if ( $exclude_zeros )
@ -302,11 +302,10 @@ function get_editable_roles() {
function get_nonauthor_user_ids() { function get_nonauthor_user_ids() {
global $wpdb; global $wpdb;
if ( !is_multisite() ) { if ( !is_multisite() )
$level_key = $wpdb->get_blog_prefix() . 'user_level'; $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 $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) ); 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'; $dir = ( 'pending' == $type ) ? 'ASC' : 'DESC';
if( !$editable ) { if ( !$editable ) {
$other_unpubs = ''; $other_unpubs = '';
} else { } else {
$editable = join(',', $editable); $editable = join(',', $editable);
@ -675,11 +674,11 @@ class WP_User_Search {
} }
$this->query_from_where = "FROM $wpdb->users"; $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 . '%'); $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"; $this->query_from_where .= " WHERE 1=1";
else { } else {
$level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels $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}'"; $this->query_from_where .= ", $wpdb->usermeta WHERE $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '{$level_key}'";
} }

View File

@ -12,30 +12,6 @@ require_once('admin.php');
if ( !current_user_can('switch_themes') ) if ( !current_user_can('switch_themes') )
wp_die( __( 'Cheatin’ uh?' ) ); 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 ( isset($_GET['action']) ) {
if ( 'activate' == $_GET['action'] ) { if ( 'activate' == $_GET['action'] ) {
check_admin_referer('switch-theme_' . $_GET['template']); check_admin_referer('switch-theme_' . $_GET['template']);
@ -85,8 +61,7 @@ if ( is_multisite() && current_user_can('edit_themes') ) {
<?php endif; ?> <?php endif; ?>
<?php <?php
if ( !is_multisite() ) $themes = get_allowed_themes();
$themes = get_themes();
$ct = current_theme_info(); $ct = current_theme_info();
unset($themes[$ct->name]); unset($themes[$ct->name]);

View File

@ -260,20 +260,17 @@ function wp_start_object_cache() {
} }
wp_cache_init(); wp_cache_init();
if ( function_exists('wp_cache_add_global_groups') ) { 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'));
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_non_persistent_groups(array( 'comment', 'counts', 'plugins' )); wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
} }
} }
function wp_not_installed() { function wp_not_installed() {
if ( is_multisite() ) { if ( is_multisite() ) {
if ( !is_blog_installed() && !defined('WP_INSTALLING') ) 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 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')) ) { } elseif ( !is_blog_installed() && (strpos($_SERVER['PHP_SELF'], 'install.php') === false && !defined('WP_INSTALLING')) ) {
if ( defined('WP_SITEURL') ) if ( defined('WP_SITEURL') )
$link = WP_SITEURL . '/wp-admin/install.php'; $link = WP_SITEURL . '/wp-admin/install.php';
@ -293,13 +290,13 @@ function wp_load_mu_plugins() {
if ( is_dir( WPMU_PLUGIN_DIR ) ) { if ( is_dir( WPMU_PLUGIN_DIR ) ) {
if ( $dh = opendir( WPMU_PLUGIN_DIR ) ) { if ( $dh = opendir( WPMU_PLUGIN_DIR ) ) {
$mu_plugins = array (); $mu_plugins = array ();
while ( ( $plugin = readdir( $dh ) ) !== false ) while ( ( $plugin = readdir( $dh ) ) !== false ) {
if ( substr( $plugin, -4 ) == '.php' ) if ( substr( $plugin, -4 ) == '.php' )
$mu_plugins[] = $plugin; $mu_plugins[] = $plugin;
}
closedir( $dh ); closedir( $dh );
if( is_multisite() ) sort( $mu_plugins );
sort( $mu_plugins ); foreach ( $mu_plugins as $mu_plugin )
foreach( $mu_plugins as $mu_plugin )
include_once( WPMU_PLUGIN_DIR . '/' . $mu_plugin ); include_once( WPMU_PLUGIN_DIR . '/' . $mu_plugin );
} }
} }