Skip to content

Commit 294f5ff

Browse files
committed
Ability to choose a network default theme
1 parent 07bf0f9 commit 294f5ff

3 files changed

Lines changed: 53 additions & 1 deletion

File tree

src/wp-admin/includes/class-wp-ms-themes-list-table.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public function prepare_items() {
118118
'disabled' => array(),
119119
'upgrade' => array(),
120120
'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
121+
'default' => array( wp_get_theme( WP_Theme::network_get_default_theme() ) ),
121122
);
122123

123124
if ( $this->show_autoupdates ) {
@@ -436,6 +437,9 @@ protected function get_views() {
436437
$count
437438
);
438439
break;
440+
case 'default':
441+
$text = __( 'Default' ) . ' <span class="count">(1)</span>';
442+
break;
439443
}
440444

441445
if ( $this->is_site_themes ) {
@@ -562,6 +566,7 @@ public function column_name( $theme ) {
562566
'enable' => '',
563567
'disable' => '',
564568
'delete' => '',
569+
'default' => '',
565570
);
566571

567572
$stylesheet = $theme->get_stylesheet();
@@ -949,9 +954,18 @@ public function single_row_columns( $item ) {
949954
if ( $stylesheet !== $template && $item->get_stylesheet() === $stylesheet ) {
950955
$active_theme_label = ' &mdash; ' . __( 'Active Child Theme' );
951956
}
957+
958+
/* In case this is the network default theme */
959+
if ( $item->get_stylesheet() === $item->network_get_default_theme() ) {
960+
$active_theme_label = ' &mdash; ' . __( 'Default Theme' );
961+
}
952962
}
953963

954-
echo "<td class='theme-title column-primary{$extra_classes}'><strong>" . $item->display( 'Name' ) . $active_theme_label . '</strong>';
964+
printf( "<td class='theme-title column-primary%s'><strong>%s%s</strong>",
965+
$extra_classes,
966+
$item->display( 'Name' ),
967+
$active_theme_label
968+
);
955969

956970
$this->column_name( $item );
957971

src/wp-admin/network/themes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
WP_Theme::network_disable_theme( $_GET['theme'] );
5151
wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
5252
exit;
53+
case 'default':
54+
check_admin_referer( 'default-theme_' . $_GET['theme'] );
55+
WP_Theme::network_set_default_theme( $_GET['theme'] );
56+
wp_safe_redirect( add_query_arg( 'default', '1', $referer ) );
57+
exit;
5358
case 'enable-selected':
5459
check_admin_referer( 'bulk-themes' );
5560
$themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();

src/wp-includes/class-wp-theme.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,39 @@ public static function network_disable_theme( $stylesheets ) {
20972097
update_site_option( 'allowedthemes', $allowed_themes );
20982098
}
20992099

2100+
/**
2101+
* Set the network default theme.
2102+
*
2103+
* @since 5.0.0
2104+
* @access public
2105+
* @static
2106+
*
2107+
* @param string $stylesheet name.
2108+
*/
2109+
public static function network_set_default_theme( $stylesheet ) {
2110+
if ( ! is_multisite() ) {
2111+
return;
2112+
}
2113+
2114+
$theme = wp_get_theme( $stylesheet );
2115+
if ( ! $theme->exists() || ! $theme->is_allowed() ) {
2116+
return;
2117+
}
2118+
2119+
update_network_option( null, 'default_theme', $stylesheet );
2120+
}
2121+
2122+
/**
2123+
* Get the network default theme.
2124+
*
2125+
* @since 5.0.0
2126+
* @access public
2127+
* @static
2128+
*/
2129+
public static function network_get_default_theme() {
2130+
return get_network_option( null, 'default_theme', WP_DEFAULT_THEME );
2131+
}
2132+
21002133
/**
21012134
* Sorts themes by name.
21022135
*

0 commit comments

Comments
 (0)