site-themes.php cleanup. Props PeteMall. see #14897
git-svn-id: http://svn.automattic.com/wordpress/trunk@16242 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
39c1f5dc43
commit
d08a1970de
|
@ -8,6 +8,9 @@
|
|||
*/
|
||||
class WP_MS_Themes_List_Table extends WP_List_Table {
|
||||
|
||||
var $site_id;
|
||||
var $is_site_themes;
|
||||
|
||||
function WP_MS_Themes_List_Table() {
|
||||
global $status, $page;
|
||||
|
||||
|
@ -37,8 +40,10 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
|
|||
}
|
||||
}
|
||||
|
||||
if ( !current_user_can('manage_network_themes') )
|
||||
if ( $this->is_site_themes && !current_user_can('manage_sites') )
|
||||
wp_die( __( 'You do not have sufficient permissions to manage themes for this site.' ) );
|
||||
else if ( !$this->is_site_themes && !current_user_can('manage_network_themes') )
|
||||
wp_die( __( 'You do not have sufficient permissions to manage network themes.' ) );
|
||||
}
|
||||
|
||||
function prepare_items() {
|
||||
|
@ -54,11 +59,17 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
|
|||
'upgrade' => array()
|
||||
);
|
||||
|
||||
$allowed_themes = get_site_allowed_themes();
|
||||
$site_allowed_themes = get_site_allowed_themes();
|
||||
if ( !$this->is_site_themes )
|
||||
$allowed_themes = $site_allowed_themes;
|
||||
else
|
||||
$allowed_themes = wpmu_get_blog_allowedthemes( $this->site_id );
|
||||
|
||||
$current = get_site_transient( 'update_themes' );
|
||||
|
||||
foreach ( (array) $themes['all'] as $key => $theme ) {
|
||||
$theme_key = esc_html( $theme['Stylesheet'] );
|
||||
|
||||
if ( isset( $allowed_themes [ $theme_key ] ) ) {
|
||||
$themes['all'][$key]['enabled'] = true;
|
||||
$themes['enabled'][$key] = $themes['all'][$key];
|
||||
|
@ -69,6 +80,12 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
|
|||
}
|
||||
if ( isset( $current->response[ $theme['Template'] ] ) )
|
||||
$themes['upgrade'][$key] = $themes['all'][$key];
|
||||
|
||||
if ( $this->is_site_themes && isset( $site_allowed_themes[$theme_key] ) ) {
|
||||
unset( $themes['all'][$key] );
|
||||
unset( $themes['enabled'][$key] );
|
||||
unset( $themes['disabled'][$key] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !current_user_can( 'update_themes' ) )
|
||||
|
@ -188,8 +205,13 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
|
|||
break;
|
||||
}
|
||||
|
||||
if ( $this->is_site_themes )
|
||||
$url = 'site-themes.php?id=' . $this->site_id;
|
||||
else
|
||||
$url = 'themes.php';
|
||||
|
||||
$status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
|
||||
add_query_arg('theme_status', $type, 'themes.php'),
|
||||
add_query_arg('theme_status', $type, $url),
|
||||
( $type == $status ) ? ' class="current"' : '',
|
||||
sprintf( $text, number_format_i18n( $count ) )
|
||||
);
|
||||
|
@ -203,9 +225,9 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
|
|||
|
||||
$actions = array();
|
||||
if ( 'enabled' != $status )
|
||||
$actions['network-enable-selected'] = __( 'Enable' );
|
||||
$actions['enable-selected'] = __( 'Enable' );
|
||||
if ( 'disabled' != $status )
|
||||
$actions['network-disable-selected'] = __( 'Disable' );
|
||||
$actions['disable-selected'] = __( 'Disable' );
|
||||
if ( current_user_can( 'update_themes' ) )
|
||||
$actions['update-selected'] = __( 'Update' );
|
||||
|
||||
|
@ -226,23 +248,25 @@ class WP_MS_Themes_List_Table extends WP_List_Table {
|
|||
|
||||
$context = $status;
|
||||
|
||||
if ( $this->is_site_themes )
|
||||
$url = "site-themes.php?id={$this->site_id}&";
|
||||
else
|
||||
$url = 'themes.php?';
|
||||
|
||||
foreach ( $this->items as $key => $theme ) {
|
||||
// preorder
|
||||
$actions = array(
|
||||
'network_enable' => '',
|
||||
'network_disable' => '',
|
||||
'enable' => '',
|
||||
'disable' => '',
|
||||
'edit' => ''
|
||||
);
|
||||
|
||||
$theme_key = esc_html( $theme['Stylesheet'] );
|
||||
|
||||
if ( empty( $theme['enabled'] ) ) {
|
||||
if ( current_user_can( 'manage_network_themes' ) )
|
||||
$actions['network_enable'] = '<a href="' . wp_nonce_url('themes.php?action=network-enable&theme=' . $theme_key . '&paged=' . $page . '&s=' . $s, 'enable-theme_' . $theme_key) . '" title="' . __('Enable this theme for all sites in this network') . '" class="edit">' . __('Enable') . '</a>';
|
||||
} else {
|
||||
if ( current_user_can( 'manage_network_themes' ) )
|
||||
$actions['network_disable'] = '<a href="' . wp_nonce_url('themes.php?action=network-disable&theme=' . $theme_key . '&paged=' . $page . '&s=' . $s, 'disable-theme_' . $theme_key) . '" title="' . __('Disable this theme') . '">' . __('Disable') . '</a>';
|
||||
}
|
||||
if ( empty( $theme['enabled'] ) )
|
||||
$actions['enable'] = '<a href="' . wp_nonce_url($url . 'action=enable&theme=' . $theme_key . '&paged=' . $page . '&s=' . $s, 'enable-theme_' . $theme_key) . '" title="' . __('Enable this theme') . '" class="edit">' . __('Enable') . '</a>';
|
||||
else
|
||||
$actions['disable'] = '<a href="' . wp_nonce_url($url . 'action=disable&theme=' . $theme_key . '&paged=' . $page . '&s=' . $s, 'disable-theme_' . $theme_key) . '" title="' . __('Disable this theme') . '">' . __('Disable') . '</a>';
|
||||
|
||||
if ( current_user_can('edit_themes') )
|
||||
$actions['edit'] = '<a href="theme-editor.php?theme=' . $theme['Name'] . '" title="' . __('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>';
|
||||
|
|
|
@ -1,55 +1,85 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Edit Site Themes Administration Screen
|
||||
* Multisite themes administration panel.
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Administration
|
||||
* @subpackage Multisite
|
||||
* @since 3.1.0
|
||||
*/
|
||||
|
||||
/** Load WordPress Administration Bootstrap */
|
||||
require_once('./admin.php');
|
||||
require_once( './admin.php' );
|
||||
|
||||
if ( ! is_multisite() )
|
||||
wp_die( __( 'Multisite support is not enabled.' ) );
|
||||
$wp_list_table = get_list_table('WP_MS_Themes_List_Table');
|
||||
$wp_list_table->check_permissions();
|
||||
|
||||
if ( ! current_user_can('manage_sites') )
|
||||
wp_die(__('You do not have sufficient permissions to edit this site.'));
|
||||
$action = $wp_list_table->current_action();
|
||||
|
||||
$s = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
|
||||
|
||||
// Clean up request URI from temporary args for screen options/paging uri's to work as expected.
|
||||
$_SERVER['REQUEST_URI'] = remove_query_arg(array('network-enable', 'network-disable', 'network-enable-selected', 'network-disable-selected'), $_SERVER['REQUEST_URI']);
|
||||
|
||||
$id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
|
||||
|
||||
if ( ! $id )
|
||||
wp_die( __('Invalid site ID.') );
|
||||
|
||||
$wp_list_table->site_id = $id;
|
||||
$wp_list_table->is_site_themes = true;
|
||||
$wp_list_table->prepare_items();
|
||||
|
||||
$details = get_blog_details( $id );
|
||||
if ( $details->site_id != $wpdb->siteid )
|
||||
wp_die( __( 'You do not have permission to access this page.' ) );
|
||||
|
||||
$is_main_site = is_main_site( $id );
|
||||
|
||||
if ( isset($_REQUEST['action']) && 'update-site' == $_REQUEST['action'] ) {
|
||||
check_admin_referer( 'edit-site' );
|
||||
|
||||
if ( $action ) {
|
||||
switch_to_blog( $id );
|
||||
$allowed_themes = get_option( 'allowedthemes' );
|
||||
|
||||
$allowedthemes = array();
|
||||
if ( isset($_POST['theme']) && is_array( $_POST['theme'] ) ) {
|
||||
foreach ( $_POST['theme'] as $theme => $val ) {
|
||||
if ( 'on' == $val )
|
||||
$allowedthemes[$theme] = true;
|
||||
}
|
||||
switch ( $action ) {
|
||||
case 'enable':
|
||||
$theme = $_GET['theme'];
|
||||
if ( !$allowed_themes )
|
||||
$allowed_themes = array( $theme => true );
|
||||
else
|
||||
$allowed_themes[$theme] = true;
|
||||
break;
|
||||
case 'disable':
|
||||
$theme = $_GET['theme'];
|
||||
if ( !$allowed_themes )
|
||||
$allowed_themes = array();
|
||||
else
|
||||
unset( $allowed_themes[$theme] );
|
||||
break;
|
||||
case 'enable-selected':
|
||||
$themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
|
||||
if ( empty($themes) ) {
|
||||
restore_current_blog();
|
||||
wp_redirect( wp_get_referer() );
|
||||
exit;
|
||||
}
|
||||
foreach( (array) $themes as $theme )
|
||||
$allowed_themes[ $theme ] = true;
|
||||
break;
|
||||
case 'disable-selected':
|
||||
$themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
|
||||
if ( empty($themes) ) {
|
||||
restore_current_blog();
|
||||
wp_redirect( wp_get_referer() );
|
||||
exit;
|
||||
}
|
||||
foreach( (array) $themes as $theme )
|
||||
unset( $allowed_themes[ $theme ] );
|
||||
break;
|
||||
}
|
||||
update_option( 'allowedthemes', $allowedthemes );
|
||||
|
||||
update_option( 'allowedthemes', $allowed_themes );
|
||||
restore_current_blog();
|
||||
wp_redirect( add_query_arg( array( 'update' => 'updated', 'id' => $id ), 'site-themes.php') );
|
||||
}
|
||||
|
||||
if ( isset($_GET['update']) ) {
|
||||
$messages = array();
|
||||
if ( 'updated' == $_GET['update'] )
|
||||
$messages[] = __('Site users updated.');
|
||||
wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message
|
||||
exit;
|
||||
}
|
||||
|
||||
$title = sprintf( __('Edit Site: %s'), get_blogaddress_by_id($id));
|
||||
|
@ -58,6 +88,11 @@ $submenu_file = 'sites.php';
|
|||
|
||||
require('../admin-header.php');
|
||||
|
||||
add_thickbox();
|
||||
|
||||
add_screen_option( 'per_page', array('label' => _x( 'Themes', 'themes per page (screen options)' ), 'default' => 999) );
|
||||
|
||||
require_once(ABSPATH . 'wp-admin/admin-header.php');
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
|
@ -73,48 +108,22 @@ foreach ( $tabs as $tab_id => $tab ) {
|
|||
}
|
||||
?>
|
||||
</h3>
|
||||
<p class="description"><?php _e( 'Network enabled themes are not shown on this screen.' ) ?></p>
|
||||
<?php
|
||||
if ( ! empty( $messages ) ) {
|
||||
foreach ( $messages as $msg )
|
||||
echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
|
||||
} ?>
|
||||
}
|
||||
|
||||
$wp_list_table->views(); ?>
|
||||
|
||||
<form method="post" action="site-themes.php?action=update-site">
|
||||
<?php wp_nonce_field( 'edit-site' ); ?>
|
||||
<input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
|
||||
<?php
|
||||
$themes = get_themes();
|
||||
$blog_allowed_themes = wpmu_get_blog_allowedthemes( $id );
|
||||
$allowed_themes = get_site_option( 'allowedthemes' );
|
||||
|
||||
if ( ! $allowed_themes )
|
||||
$allowed_themes = array_keys( $themes );
|
||||
<?php $wp_list_table->display(); ?>
|
||||
|
||||
$out = '';
|
||||
foreach ( $themes as $key => $theme ) {
|
||||
$theme_key = esc_html( $theme['Stylesheet'] );
|
||||
if ( ! isset( $allowed_themes[$theme_key] ) ) {
|
||||
$checked = isset( $blog_allowed_themes[ $theme_key ] ) ? 'checked="checked"' : '';
|
||||
$out .= '<tr class="form-field form-required">
|
||||
<th title="' . esc_attr( $theme["Description"] ).'" scope="row">' . esc_html( $key ) . '</th>
|
||||
<td><label><input name="theme[' . esc_attr( $theme_key ) . ']" type="checkbox" style="width:20px;" value="on" '.$checked.'/> ' . __( 'Active' ) . '</label></td>
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
|
||||
if ( $out != '' ) {
|
||||
?>
|
||||
<p class="description"><?php _e( 'Activate the themename of an existing theme and hit "Update Options" to allow the theme for this site.' ) ?></p>
|
||||
<table class="form-table">
|
||||
<?php echo $out; ?>
|
||||
</table>
|
||||
<?php
|
||||
submit_button();
|
||||
} else {
|
||||
_e('All themes are allowed.');
|
||||
}
|
||||
?>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
require('../admin-footer.php');
|
||||
<?php include(ABSPATH . 'wp-admin/admin-footer.php'); ?>
|
|
@ -17,24 +17,24 @@ $action = $wp_list_table->current_action();
|
|||
$s = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
|
||||
|
||||
// Clean up request URI from temporary args for screen options/paging uri's to work as expected.
|
||||
$_SERVER['REQUEST_URI'] = remove_query_arg(array('network-enable', 'network-disable', 'network-enable-selected', 'network-disable-selected'), $_SERVER['REQUEST_URI']);
|
||||
$_SERVER['REQUEST_URI'] = remove_query_arg(array('enable', 'disable', 'enable-selected', 'disable-selected'), $_SERVER['REQUEST_URI']);
|
||||
|
||||
if ( $action ) {
|
||||
$allowed_themes = get_site_option( 'allowedthemes' );
|
||||
switch ( $action ) {
|
||||
case 'network-enable':
|
||||
case 'enable':
|
||||
$allowed_themes[ $_GET['theme'] ] = true;
|
||||
update_site_option( 'allowedthemes', $allowed_themes );
|
||||
wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message
|
||||
exit;
|
||||
break;
|
||||
case 'network-disable':
|
||||
case 'disable':
|
||||
unset( $allowed_themes[ $_GET['theme'] ] );
|
||||
update_site_option( 'allowedthemes', $allowed_themes );
|
||||
wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message
|
||||
exit;
|
||||
break;
|
||||
case 'network-enable-selected':
|
||||
case 'enable-selected':
|
||||
$themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
|
||||
if ( empty($themes) ) {
|
||||
wp_redirect( wp_get_referer() );
|
||||
|
@ -44,7 +44,7 @@ if ( $action ) {
|
|||
$allowed_themes[ $theme ] = true;
|
||||
update_site_option( 'allowedthemes', $allowed_themes );
|
||||
break;
|
||||
case 'network-disable-selected':
|
||||
case 'disable-selected':
|
||||
$themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
|
||||
if ( empty($themes) ) {
|
||||
wp_redirect( wp_get_referer() );
|
||||
|
@ -81,7 +81,6 @@ require_once(ABSPATH . 'wp-admin/admin-header.php');
|
|||
<div class="wrap">
|
||||
<?php screen_icon('themes'); ?>
|
||||
<h2><?php echo esc_html( $title ); if ( current_user_can('install_themes') ) { ?> <a href="theme-install.php" class="button add-new-h2"><?php echo esc_html_x('Add New', 'theme'); ?></a><?php } ?></h2>
|
||||
<p><?php _e( 'Themes must be enabled for your network before they will be available to individual sites.' ) ?></p>
|
||||
|
||||
<form method="get" action="">
|
||||
<p class="search-box">
|
||||
|
|
Loading…
Reference in New Issue