Skip to content

Ability to choose a network default theme #8679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/wp-admin/includes/class-wp-ms-themes-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function prepare_items() {
'disabled' => array(),
'upgrade' => array(),
'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
'default' => array( wp_get_theme( WP_Theme::network_get_default_theme() ) ),
);

if ( $this->show_autoupdates ) {
Expand Down Expand Up @@ -436,6 +437,9 @@ protected function get_views() {
$count
);
break;
case 'default':
$text = __( 'Default' ) . ' <span class="count">(1)</span>';
break;
}

if ( $this->is_site_themes ) {
Expand Down Expand Up @@ -562,6 +566,7 @@ public function column_name( $theme ) {
'enable' => '',
'disable' => '',
'delete' => '',
'default' => '',
);

$stylesheet = $theme->get_stylesheet();
Expand Down Expand Up @@ -949,9 +954,19 @@ public function single_row_columns( $item ) {
if ( $stylesheet !== $template && $item->get_stylesheet() === $stylesheet ) {
$active_theme_label = ' &mdash; ' . __( 'Active Child Theme' );
}

/* In case this is the network default theme */
if ( $item->get_stylesheet() === $item->network_get_default_theme() ) {
$active_theme_label = ' &mdash; ' . __( 'Default Theme' );
}
}

echo "<td class='theme-title column-primary{$extra_classes}'><strong>" . $item->display( 'Name' ) . $active_theme_label . '</strong>';
printf(
"<td class='theme-title column-primary%s'><strong>%s%s</strong>",
$extra_classes,
$item->display( 'Name' ),
$active_theme_label
);

$this->column_name( $item );

Expand Down
5 changes: 5 additions & 0 deletions src/wp-admin/network/themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
WP_Theme::network_disable_theme( $_GET['theme'] );
wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
exit;
case 'default':
check_admin_referer( 'default-theme_' . $_GET['theme'] );
WP_Theme::network_set_default_theme( $_GET['theme'] );
wp_safe_redirect( add_query_arg( 'default', '1', $referer ) );
exit;
case 'enable-selected':
check_admin_referer( 'bulk-themes' );
$themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
Expand Down
33 changes: 33 additions & 0 deletions src/wp-includes/class-wp-theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -2097,6 +2097,39 @@ public static function network_disable_theme( $stylesheets ) {
update_site_option( 'allowedthemes', $allowed_themes );
}

/**
* Set the network default theme.
*
* @since 5.0.0
* @access public
* @static
*
* @param string $stylesheet name.
*/
public static function network_set_default_theme( $stylesheet ) {
if ( ! is_multisite() ) {
return;
}

$theme = wp_get_theme( $stylesheet );
if ( ! $theme->exists() || ! $theme->is_allowed() ) {
return;
}

update_network_option( null, 'default_theme', $stylesheet );
}

/**
* Get the network default theme.
*
* @since 5.0.0
* @access public
* @static
*/
public static function network_get_default_theme() {
return get_network_option( null, 'default_theme', WP_DEFAULT_THEME );
}

/**
* Sorts themes by name.
*
Expand Down
Loading