wp/wp-admin/themes.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    15 		'<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
    15 		'<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
    16 		403
    16 		403
    17 	);
    17 	);
    18 }
    18 }
    19 
    19 
    20 if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) {
    20 if ( current_user_can( 'switch_themes' ) && isset( $_GET['action'] ) ) {
    21 	if ( 'activate' == $_GET['action'] ) {
    21 	if ( 'activate' == $_GET['action'] ) {
    22 		check_admin_referer('switch-theme_' . $_GET['stylesheet']);
    22 		check_admin_referer( 'switch-theme_' . $_GET['stylesheet'] );
    23 		$theme = wp_get_theme( $_GET['stylesheet'] );
    23 		$theme = wp_get_theme( $_GET['stylesheet'] );
    24 
    24 
    25 		if ( ! $theme->exists() || ! $theme->is_allowed() ) {
    25 		if ( ! $theme->exists() || ! $theme->is_allowed() ) {
    26 			wp_die(
    26 			wp_die(
    27 				'<h1>' . __( 'Something went wrong.' ) . '</h1>' .
    27 				'<h1>' . __( 'Something went wrong.' ) . '</h1>' .
    29 				403
    29 				403
    30 			);
    30 			);
    31 		}
    31 		}
    32 
    32 
    33 		switch_theme( $theme->get_stylesheet() );
    33 		switch_theme( $theme->get_stylesheet() );
    34 		wp_redirect( admin_url('themes.php?activated=true') );
    34 		wp_redirect( admin_url( 'themes.php?activated=true' ) );
       
    35 		exit;
       
    36 	} elseif ( 'resume' === $_GET['action'] ) {
       
    37 		check_admin_referer( 'resume-theme_' . $_GET['stylesheet'] );
       
    38 		$theme = wp_get_theme( $_GET['stylesheet'] );
       
    39 
       
    40 		if ( ! current_user_can( 'resume_theme', $_GET['stylesheet'] ) ) {
       
    41 			wp_die(
       
    42 				'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
       
    43 				'<p>' . __( 'Sorry, you are not allowed to resume this theme.' ) . '</p>',
       
    44 				403
       
    45 			);
       
    46 		}
       
    47 
       
    48 		$result = resume_theme( $theme->get_stylesheet(), self_admin_url( 'themes.php?error=resuming' ) );
       
    49 
       
    50 		if ( is_wp_error( $result ) ) {
       
    51 			wp_die( $result );
       
    52 		}
       
    53 
       
    54 		wp_redirect( admin_url( 'themes.php?resumed=true' ) );
    35 		exit;
    55 		exit;
    36 	} elseif ( 'delete' == $_GET['action'] ) {
    56 	} elseif ( 'delete' == $_GET['action'] ) {
    37 		check_admin_referer('delete-theme_' . $_GET['stylesheet']);
    57 		check_admin_referer( 'delete-theme_' . $_GET['stylesheet'] );
    38 		$theme = wp_get_theme( $_GET['stylesheet'] );
    58 		$theme = wp_get_theme( $_GET['stylesheet'] );
    39 
    59 
    40 		if ( ! current_user_can( 'delete_themes' ) ) {
    60 		if ( ! current_user_can( 'delete_themes' ) ) {
    41 			wp_die(
    61 			wp_die(
    42 				'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
    62 				'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
    62 		}
    82 		}
    63 		exit;
    83 		exit;
    64 	}
    84 	}
    65 }
    85 }
    66 
    86 
    67 $title = __('Manage Themes');
    87 $title       = __( 'Manage Themes' );
    68 $parent_file = 'themes.php';
    88 $parent_file = 'themes.php';
    69 
    89 
    70 // Help tab: Overview
    90 // Help tab: Overview
    71 if ( current_user_can( 'switch_themes' ) ) {
    91 if ( current_user_can( 'switch_themes' ) ) {
    72 	$help_overview  = '<p>' . __( 'This screen is used for managing your installed themes. Aside from the default theme(s) included with your WordPress installation, themes are designed and developed by third parties.' ) . '</p>' .
    92 	$help_overview = '<p>' . __( 'This screen is used for managing your installed themes. Aside from the default theme(s) included with your WordPress installation, themes are designed and developed by third parties.' ) . '</p>' .
    73 		'<p>' . __( 'From this screen you can:' ) . '</p>' .
    93 		'<p>' . __( 'From this screen you can:' ) . '</p>' .
    74 		'<ul><li>' . __( 'Hover or tap to see Activate and Live Preview buttons' ) . '</li>' .
    94 		'<ul><li>' . __( 'Hover or tap to see Activate and Live Preview buttons' ) . '</li>' .
    75 		'<li>' . __( 'Click on the theme to see the theme name, version, author, description, tags, and the Delete link' ) . '</li>' .
    95 		'<li>' . __( 'Click on the theme to see the theme name, version, author, description, tags, and the Delete link' ) . '</li>' .
    76 		'<li>' . __( 'Click Customize for the current theme or Live Preview for any other theme to see a live preview' ) . '</li></ul>' .
    96 		'<li>' . __( 'Click Customize for the current theme or Live Preview for any other theme to see a live preview' ) . '</li></ul>' .
    77 		'<p>' . __( 'The current theme is displayed highlighted as the first theme.' ) . '</p>' .
    97 		'<p>' . __( 'The current theme is displayed highlighted as the first theme.' ) . '</p>' .
    78 		'<p>' . __( 'The search for installed themes will search for terms in their name, description, author, or tag.' ) . ' <span id="live-search-desc">' . __( 'The search results will be updated as you type.' ) . '</span></p>';
    98 		'<p>' . __( 'The search for installed themes will search for terms in their name, description, author, or tag.' ) . ' <span id="live-search-desc">' . __( 'The search results will be updated as you type.' ) . '</span></p>';
    79 
    99 
    80 	get_current_screen()->add_help_tab( array(
   100 	get_current_screen()->add_help_tab(
    81 		'id'      => 'overview',
   101 		array(
    82 		'title'   => __( 'Overview' ),
   102 			'id'      => 'overview',
    83 		'content' => $help_overview
   103 			'title'   => __( 'Overview' ),
    84 	) );
   104 			'content' => $help_overview,
       
   105 		)
       
   106 	);
    85 } // switch_themes
   107 } // switch_themes
    86 
   108 
    87 // Help tab: Adding Themes
   109 // Help tab: Adding Themes
    88 if ( current_user_can( 'install_themes' ) ) {
   110 if ( current_user_can( 'install_themes' ) ) {
    89 	if ( is_multisite() ) {
   111 	if ( is_multisite() ) {
    90 		$help_install = '<p>' . __('Installing themes on Multisite can only be done from the Network Admin section.') . '</p>';
   112 		$help_install = '<p>' . __( 'Installing themes on Multisite can only be done from the Network Admin section.' ) . '</p>';
    91 	} else {
   113 	} else {
    92 		$help_install = '<p>' . sprintf( __('If you would like to see more themes to choose from, click on the &#8220;Add New&#8221; button and you will be able to browse or search for additional themes from the <a href="%s">WordPress Theme Directory</a>. Themes in the WordPress Theme Directory are designed and developed by third parties, and are compatible with the license WordPress uses. Oh, and they&#8217;re free!'), __( 'https://wordpress.org/themes/' ) ) . '</p>';
   114 		$help_install = '<p>' . sprintf( __( 'If you would like to see more themes to choose from, click on the &#8220;Add New&#8221; button and you will be able to browse or search for additional themes from the <a href="%s">WordPress Theme Directory</a>. Themes in the WordPress Theme Directory are designed and developed by third parties, and are compatible with the license WordPress uses. Oh, and they&#8217;re free!' ), __( 'https://wordpress.org/themes/' ) ) . '</p>';
    93 	}
   115 	}
    94 
   116 
    95 	get_current_screen()->add_help_tab( array(
   117 	get_current_screen()->add_help_tab(
    96 		'id'      => 'adding-themes',
   118 		array(
    97 		'title'   => __('Adding Themes'),
   119 			'id'      => 'adding-themes',
    98 		'content' => $help_install
   120 			'title'   => __( 'Adding Themes' ),
    99 	) );
   121 			'content' => $help_install,
       
   122 		)
       
   123 	);
   100 } // install_themes
   124 } // install_themes
   101 
   125 
   102 // Help tab: Previewing and Customizing
   126 // Help tab: Previewing and Customizing
   103 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
   127 if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
   104 	$help_customize =
   128 	$help_customize =
   105 		'<p>' . __( 'Tap or hover on any theme then click the Live Preview button to see a live preview of that theme and change theme options in a separate, full-screen view. You can also find a Live Preview button at the bottom of the theme details screen. Any installed theme can be previewed and customized in this way.' ) . '</p>'.
   129 		'<p>' . __( 'Tap or hover on any theme then click the Live Preview button to see a live preview of that theme and change theme options in a separate, full-screen view. You can also find a Live Preview button at the bottom of the theme details screen. Any installed theme can be previewed and customized in this way.' ) . '</p>' .
   106 		'<p>' . __( 'The theme being previewed is fully interactive &mdash; navigate to different pages to see how the theme handles posts, archives, and other page templates. The settings may differ depending on what theme features the theme being previewed supports. To accept the new settings and activate the theme all in one step, click the Publish &amp; Activate button above the menu.' ) . '</p>' .
   130 		'<p>' . __( 'The theme being previewed is fully interactive &mdash; navigate to different pages to see how the theme handles posts, archives, and other page templates. The settings may differ depending on what theme features the theme being previewed supports. To accept the new settings and activate the theme all in one step, click the Publish &amp; Activate button above the menu.' ) . '</p>' .
   107 		'<p>' . __( 'When previewing on smaller monitors, you can use the collapse icon at the bottom of the left-hand pane. This will hide the pane, giving you more room to preview your site in the new theme. To bring the pane back, click on the collapse icon again.' ) . '</p>';
   131 		'<p>' . __( 'When previewing on smaller monitors, you can use the collapse icon at the bottom of the left-hand pane. This will hide the pane, giving you more room to preview your site in the new theme. To bring the pane back, click on the collapse icon again.' ) . '</p>';
   108 
   132 
   109 	get_current_screen()->add_help_tab( array(
   133 	get_current_screen()->add_help_tab(
   110 		'id'		=> 'customize-preview-themes',
   134 		array(
   111 		'title'		=> __( 'Previewing and Customizing' ),
   135 			'id'      => 'customize-preview-themes',
   112 		'content'	=> $help_customize
   136 			'title'   => __( 'Previewing and Customizing' ),
   113 	) );
   137 			'content' => $help_customize,
       
   138 		)
       
   139 	);
   114 } // edit_theme_options && customize
   140 } // edit_theme_options && customize
   115 
   141 
   116 get_current_screen()->set_help_sidebar(
   142 get_current_screen()->set_help_sidebar(
   117 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   143 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   118 	'<p>' . __( '<a href="https://codex.wordpress.org/Using_Themes">Documentation on Using Themes</a>' ) . '</p>' .
   144 	'<p>' . __( '<a href="https://codex.wordpress.org/Using_Themes">Documentation on Using Themes</a>' ) . '</p>' .
   119 	'<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>'
   145 	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
   120 );
   146 );
   121 
   147 
   122 if ( current_user_can( 'switch_themes' ) ) {
   148 if ( current_user_can( 'switch_themes' ) ) {
   123 	$themes = wp_prepare_themes_for_js();
   149 	$themes = wp_prepare_themes_for_js();
   124 } else {
   150 } else {
   125 	$themes = wp_prepare_themes_for_js( array( wp_get_theme() ) );
   151 	$themes = wp_prepare_themes_for_js( array( wp_get_theme() ) );
   126 }
   152 }
   127 wp_reset_vars( array( 'theme', 'search' ) );
   153 wp_reset_vars( array( 'theme', 'search' ) );
   128 
   154 
   129 wp_localize_script( 'theme', '_wpThemeSettings', array(
   155 wp_localize_script(
   130 	'themes'   => $themes,
   156 	'theme',
   131 	'settings' => array(
   157 	'_wpThemeSettings',
   132 		'canInstall'    => ( ! is_multisite() && current_user_can( 'install_themes' ) ),
   158 	array(
   133 		'installURI'    => ( ! is_multisite() && current_user_can( 'install_themes' ) ) ? admin_url( 'theme-install.php' ) : null,
   159 		'themes'   => $themes,
   134 		'confirmDelete' => __( "Are you sure you want to delete this theme?\n\nClick 'Cancel' to go back, 'OK' to confirm the delete." ),
   160 		'settings' => array(
   135 		'adminUrl'      => parse_url( admin_url(), PHP_URL_PATH ),
   161 			'canInstall'    => ( ! is_multisite() && current_user_can( 'install_themes' ) ),
   136 	),
   162 			'installURI'    => ( ! is_multisite() && current_user_can( 'install_themes' ) ) ? admin_url( 'theme-install.php' ) : null,
   137  	'l10n' => array(
   163 			'confirmDelete' => __( "Are you sure you want to delete this theme?\n\nClick 'Cancel' to go back, 'OK' to confirm the delete." ),
   138  		'addNew'            => __( 'Add New Theme' ),
   164 			'adminUrl'      => parse_url( admin_url(), PHP_URL_PATH ),
   139  		'search'            => __( 'Search Installed Themes' ),
   165 		),
   140  		'searchPlaceholder' => __( 'Search installed themes...' ), // placeholder (no ellipsis)
   166 		'l10n'     => array(
   141 		'themesFound'       => __( 'Number of Themes found: %d' ),
   167 			'addNew'            => __( 'Add New Theme' ),
   142 		'noThemesFound'     => __( 'No themes found. Try a different search.' ),
   168 			'search'            => __( 'Search Installed Themes' ),
   143   	),
   169 			'searchPlaceholder' => __( 'Search installed themes...' ), // placeholder (no ellipsis)
   144 ) );
   170 			'themesFound'       => __( 'Number of Themes found: %d' ),
       
   171 			'noThemesFound'     => __( 'No themes found. Try a different search.' ),
       
   172 		),
       
   173 	)
       
   174 );
   145 
   175 
   146 add_thickbox();
   176 add_thickbox();
   147 wp_enqueue_script( 'theme' );
   177 wp_enqueue_script( 'theme' );
   148 wp_enqueue_script( 'updates' );
   178 wp_enqueue_script( 'updates' );
   149 
   179 
   161 
   191 
   162 	<form class="search-form"></form>
   192 	<form class="search-form"></form>
   163 
   193 
   164 	<hr class="wp-header-end">
   194 	<hr class="wp-header-end">
   165 <?php
   195 <?php
   166 if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) : ?>
   196 if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) {
   167 <div id="message1" class="updated notice is-dismissible"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
   197 	?>
   168 <?php elseif ( isset($_GET['activated']) ) :
   198 	<div id="message1" class="updated notice is-dismissible"><p><?php _e( 'The active theme is broken. Reverting to the default theme.' ); ?></p></div>
   169 		if ( isset( $_GET['previewed'] ) ) { ?>
   199 	<?php
       
   200 } elseif ( isset( $_GET['activated'] ) ) {
       
   201 	if ( isset( $_GET['previewed'] ) ) {
       
   202 		?>
   170 		<div id="message2" class="updated notice is-dismissible"><p><?php _e( 'Settings saved and theme activated.' ); ?> <a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Visit site' ); ?></a></p></div>
   203 		<div id="message2" class="updated notice is-dismissible"><p><?php _e( 'Settings saved and theme activated.' ); ?> <a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Visit site' ); ?></a></p></div>
   171 		<?php } else { ?>
   204 		<?php
   172 <div id="message2" class="updated notice is-dismissible"><p><?php _e( 'New theme activated.' ); ?> <a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Visit site' ); ?></a></p></div><?php
   205 	} else {
   173 		}
   206 		?>
   174 	elseif ( isset($_GET['deleted']) ) : ?>
   207 		<div id="message2" class="updated notice is-dismissible"><p><?php _e( 'New theme activated.' ); ?> <a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Visit site' ); ?></a></p></div>
   175 <div id="message3" class="updated notice is-dismissible"><p><?php _e('Theme deleted.') ?></p></div>
   208 		<?php
   176 <?php elseif ( isset( $_GET['delete-active-child'] ) ) : ?>
   209 	}
       
   210 } elseif ( isset( $_GET['deleted'] ) ) {
       
   211 	?>
       
   212 	<div id="message3" class="updated notice is-dismissible"><p><?php _e( 'Theme deleted.' ); ?></p></div>
       
   213 	<?php
       
   214 } elseif ( isset( $_GET['delete-active-child'] ) ) {
       
   215 	?>
   177 	<div id="message4" class="error"><p><?php _e( 'You cannot delete a theme while it has an active child theme.' ); ?></p></div>
   216 	<div id="message4" class="error"><p><?php _e( 'You cannot delete a theme while it has an active child theme.' ); ?></p></div>
   178 <?php
   217 	<?php
   179 endif;
   218 } elseif ( isset( $_GET['resumed'] ) ) {
       
   219 	?>
       
   220 	<div id="message5" class="updated notice is-dismissible"><p><?php _e( 'Theme resumed.' ); ?></p></div>
       
   221 	<?php
       
   222 } elseif ( isset( $_GET['error'] ) && 'resuming' === $_GET['error'] ) {
       
   223 	?>
       
   224 	<div id="message6" class="error"><p><?php _e( 'Theme could not be resumed because it triggered a <strong>fatal error</strong>.' ); ?></p></div>
       
   225 	<?php
       
   226 }
   180 
   227 
   181 $ct = wp_get_theme();
   228 $ct = wp_get_theme();
   182 
   229 
   183 if ( $ct->errors() && ( ! is_multisite() || current_user_can( 'manage_network_themes' ) ) ) {
   230 if ( $ct->errors() && ( ! is_multisite() || current_user_can( 'manage_network_themes' ) ) ) {
   184 	echo '<div class="error"><p>' . __( 'ERROR:' ) . ' ' . $ct->errors()->get_error_message() . '</p></div>';
   231 	echo '<div class="error"><p>' . __( 'ERROR:' ) . ' ' . $ct->errors()->get_error_message() . '</p></div>';
   190 	&& in_array( $ct->errors()->get_error_code(), array( 'theme_no_parent', 'theme_parent_invalid', 'theme_no_index' ) ) ) ) : ?>
   237 	&& in_array( $ct->errors()->get_error_code(), array( 'theme_no_parent', 'theme_parent_invalid', 'theme_no_index' ) ) ) ) : ?>
   191 */
   238 */
   192 
   239 
   193 	// Pretend you didn't see this.
   240 	// Pretend you didn't see this.
   194 	$current_theme_actions = array();
   241 	$current_theme_actions = array();
   195 	if ( is_array( $submenu ) && isset( $submenu['themes.php'] ) ) {
   242 if ( is_array( $submenu ) && isset( $submenu['themes.php'] ) ) {
   196 		foreach ( (array) $submenu['themes.php'] as $item) {
   243 	foreach ( (array) $submenu['themes.php'] as $item ) {
   197 			$class = '';
   244 		$class = '';
   198 			if ( 'themes.php' == $item[2] || 'theme-editor.php' == $item[2] || 0 === strpos( $item[2], 'customize.php' ) )
   245 		if ( 'themes.php' == $item[2] || 'theme-editor.php' == $item[2] || 0 === strpos( $item[2], 'customize.php' ) ) {
   199 				continue;
   246 			continue;
   200 			// 0 = name, 1 = capability, 2 = file
   247 		}
   201 			if ( ( strcmp($self, $item[2]) == 0 && empty($parent_file)) || ($parent_file && ($item[2] == $parent_file)) )
   248 		// 0 = name, 1 = capability, 2 = file
   202 				$class = ' current';
   249 		if ( ( strcmp( $self, $item[2] ) == 0 && empty( $parent_file ) ) || ( $parent_file && ( $item[2] == $parent_file ) ) ) {
   203 			if ( !empty($submenu[$item[2]]) ) {
   250 			$class = ' current';
   204 				$submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index.
   251 		}
   205 				$menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]);
   252 		if ( ! empty( $submenu[ $item[2] ] ) ) {
   206 				if ( file_exists(WP_PLUGIN_DIR . "/{$submenu[$item[2]][0][2]}") || !empty($menu_hook))
   253 			$submenu[ $item[2] ] = array_values( $submenu[ $item[2] ] ); // Re-index.
   207 					$current_theme_actions[] = "<a class='button$class' href='admin.php?page={$submenu[$item[2]][0][2]}'>{$item[0]}</a>";
   254 			$menu_hook           = get_plugin_page_hook( $submenu[ $item[2] ][0][2], $item[2] );
   208 				else
   255 			if ( file_exists( WP_PLUGIN_DIR . "/{$submenu[$item[2]][0][2]}" ) || ! empty( $menu_hook ) ) {
   209 					$current_theme_actions[] = "<a class='button$class' href='{$submenu[$item[2]][0][2]}'>{$item[0]}</a>";
   256 				$current_theme_actions[] = "<a class='button$class' href='admin.php?page={$submenu[$item[2]][0][2]}'>{$item[0]}</a>";
   210 			} elseif ( ! empty( $item[2] ) && current_user_can( $item[1] ) ) {
   257 			} else {
   211 				$menu_file = $item[2];
   258 				$current_theme_actions[] = "<a class='button$class' href='{$submenu[$item[2]][0][2]}'>{$item[0]}</a>";
   212 
   259 			}
   213 				if ( current_user_can( 'customize' ) ) {
   260 		} elseif ( ! empty( $item[2] ) && current_user_can( $item[1] ) ) {
   214 					if ( 'custom-header' === $menu_file ) {
   261 			$menu_file = $item[2];
   215 						$current_theme_actions[] = "<a class='button hide-if-no-customize$class' href='customize.php?autofocus[control]=header_image'>{$item[0]}</a>";
   262 
   216 					} elseif ( 'custom-background' === $menu_file ) {
   263 			if ( current_user_can( 'customize' ) ) {
   217 						$current_theme_actions[] = "<a class='button hide-if-no-customize$class' href='customize.php?autofocus[control]=background_image'>{$item[0]}</a>";
   264 				if ( 'custom-header' === $menu_file ) {
   218 					}
   265 					$current_theme_actions[] = "<a class='button hide-if-no-customize$class' href='customize.php?autofocus[control]=header_image'>{$item[0]}</a>";
   219 				}
   266 				} elseif ( 'custom-background' === $menu_file ) {
   220 
   267 					$current_theme_actions[] = "<a class='button hide-if-no-customize$class' href='customize.php?autofocus[control]=background_image'>{$item[0]}</a>";
   221 				if ( false !== ( $pos = strpos( $menu_file, '?' ) ) ) {
       
   222 					$menu_file = substr( $menu_file, 0, $pos );
       
   223 				}
       
   224 
       
   225 				if ( file_exists( ABSPATH . "wp-admin/$menu_file" ) ) {
       
   226 					$current_theme_actions[] = "<a class='button$class' href='{$item[2]}'>{$item[0]}</a>";
       
   227 				} else {
       
   228 					$current_theme_actions[] = "<a class='button$class' href='themes.php?page={$item[2]}'>{$item[0]}</a>";
       
   229 				}
   268 				}
   230 			}
   269 			}
       
   270 
       
   271 			if ( false !== ( $pos = strpos( $menu_file, '?' ) ) ) {
       
   272 				$menu_file = substr( $menu_file, 0, $pos );
       
   273 			}
       
   274 
       
   275 			if ( file_exists( ABSPATH . "wp-admin/$menu_file" ) ) {
       
   276 				$current_theme_actions[] = "<a class='button$class' href='{$item[2]}'>{$item[0]}</a>";
       
   277 			} else {
       
   278 				$current_theme_actions[] = "<a class='button$class' href='themes.php?page={$item[2]}'>{$item[0]}</a>";
       
   279 			}
   231 		}
   280 		}
   232 	}
   281 	}
       
   282 }
   233 
   283 
   234 ?>
   284 ?>
   235 
   285 
   236 <?php
   286 <?php
   237 $class_name = 'theme-browser';
   287 $class_name = 'theme-browser';
   248  */
   298  */
   249 
   299 
   250 foreach ( $themes as $theme ) :
   300 foreach ( $themes as $theme ) :
   251 	$aria_action = esc_attr( $theme['id'] . '-action' );
   301 	$aria_action = esc_attr( $theme['id'] . '-action' );
   252 	$aria_name   = esc_attr( $theme['id'] . '-name' );
   302 	$aria_name   = esc_attr( $theme['id'] . '-name' );
   253 	?>
   303 
   254 <div class="theme<?php if ( $theme['active'] ) echo ' active'; ?>" tabindex="0" aria-describedby="<?php echo $aria_action . ' ' . $aria_name; ?>">
   304 	$active_class = '';
       
   305 	if ( $theme['active'] ) {
       
   306 		$active_class = ' active';
       
   307 	}
       
   308 	?>
       
   309 <div class="theme<?php echo $active_class; ?>" tabindex="0" aria-describedby="<?php echo $aria_action . ' ' . $aria_name; ?>">
   255 	<?php if ( ! empty( $theme['screenshot'][0] ) ) { ?>
   310 	<?php if ( ! empty( $theme['screenshot'][0] ) ) { ?>
   256 		<div class="theme-screenshot">
   311 		<div class="theme-screenshot">
   257 			<img src="<?php echo $theme['screenshot'][0]; ?>" alt="" />
   312 			<img src="<?php echo $theme['screenshot'][0]; ?>" alt="" />
   258 		</div>
   313 		</div>
   259 	<?php } else { ?>
   314 	<?php } else { ?>
   311 
   366 
   312 <p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p>
   367 <p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p>
   313 
   368 
   314 <?php
   369 <?php
   315 // List broken themes, if any.
   370 // List broken themes, if any.
   316 if ( ! is_multisite() && current_user_can('edit_themes') && $broken_themes = wp_get_themes( array( 'errors' => true ) ) ) {
   371 if ( ! is_multisite() && current_user_can( 'edit_themes' ) && $broken_themes = wp_get_themes( array( 'errors' => true ) ) ) {
   317 ?>
   372 	?>
   318 
   373 
   319 <div class="broken-themes">
   374 <div class="broken-themes">
   320 <h3><?php _e('Broken Themes'); ?></h3>
   375 <h3><?php _e( 'Broken Themes' ); ?></h3>
   321 <p><?php _e( 'The following themes are installed but incomplete.' ); ?></p>
   376 <p><?php _e( 'The following themes are installed but incomplete.' ); ?></p>
   322 
   377 
   323 <?php
   378 	<?php
   324 $can_delete = current_user_can( 'delete_themes' );
   379 	$can_resume  = current_user_can( 'resume_themes' );
   325 $can_install = current_user_can( 'install_themes' );
   380 	$can_delete  = current_user_can( 'delete_themes' );
   326 ?>
   381 	$can_install = current_user_can( 'install_themes' );
       
   382 	?>
   327 <table>
   383 <table>
   328 	<tr>
   384 	<tr>
   329 		<th><?php _ex('Name', 'theme name'); ?></th>
   385 		<th><?php _ex( 'Name', 'theme name' ); ?></th>
   330 		<th><?php _e('Description'); ?></th>
   386 		<th><?php _e( 'Description' ); ?></th>
       
   387 		<?php if ( $can_resume ) { ?>
       
   388 			<td></td>
       
   389 		<?php } ?>
   331 		<?php if ( $can_delete ) { ?>
   390 		<?php if ( $can_delete ) { ?>
   332 			<td></td>
   391 			<td></td>
   333 		<?php } ?>
   392 		<?php } ?>
   334 		<?php if ( $can_install ) { ?>
   393 		<?php if ( $can_install ) { ?>
   335 			<td></td>
   394 			<td></td>
   338 	<?php foreach ( $broken_themes as $broken_theme ) : ?>
   397 	<?php foreach ( $broken_themes as $broken_theme ) : ?>
   339 		<tr>
   398 		<tr>
   340 			<td><?php echo $broken_theme->get( 'Name' ) ? $broken_theme->display( 'Name' ) : $broken_theme->get_stylesheet(); ?></td>
   399 			<td><?php echo $broken_theme->get( 'Name' ) ? $broken_theme->display( 'Name' ) : $broken_theme->get_stylesheet(); ?></td>
   341 			<td><?php echo $broken_theme->errors()->get_error_message(); ?></td>
   400 			<td><?php echo $broken_theme->errors()->get_error_message(); ?></td>
   342 			<?php
   401 			<?php
       
   402 			if ( $can_resume ) {
       
   403 				if ( 'theme_paused' === $broken_theme->errors()->get_error_code() ) {
       
   404 					$stylesheet = $broken_theme->get_stylesheet();
       
   405 					$resume_url = add_query_arg(
       
   406 						array(
       
   407 							'action'     => 'resume',
       
   408 							'stylesheet' => urlencode( $stylesheet ),
       
   409 						),
       
   410 						admin_url( 'themes.php' )
       
   411 					);
       
   412 					$resume_url = wp_nonce_url( $resume_url, 'resume-theme_' . $stylesheet );
       
   413 					?>
       
   414 					<td><a href="<?php echo esc_url( $resume_url ); ?>" class="button resume-theme"><?php _e( 'Resume' ); ?></a></td>
       
   415 					<?php
       
   416 				} else {
       
   417 					?>
       
   418 					<td></td>
       
   419 					<?php
       
   420 				}
       
   421 			}
       
   422 
   343 			if ( $can_delete ) {
   423 			if ( $can_delete ) {
   344 				$stylesheet = $broken_theme->get_stylesheet();
   424 				$stylesheet = $broken_theme->get_stylesheet();
   345 				$delete_url = add_query_arg( array(
   425 				$delete_url = add_query_arg(
   346 					'action'     => 'delete',
   426 					array(
   347 					'stylesheet' => urlencode( $stylesheet ),
   427 						'action'     => 'delete',
   348 				), admin_url( 'themes.php' ) );
   428 						'stylesheet' => urlencode( $stylesheet ),
       
   429 					),
       
   430 					admin_url( 'themes.php' )
       
   431 				);
   349 				$delete_url = wp_nonce_url( $delete_url, 'delete-theme_' . $stylesheet );
   432 				$delete_url = wp_nonce_url( $delete_url, 'delete-theme_' . $stylesheet );
   350 				?>
   433 				?>
   351 				<td><a href="<?php echo esc_url( $delete_url ); ?>" class="button delete-theme"><?php _e( 'Delete' ); ?></a></td>
   434 				<td><a href="<?php echo esc_url( $delete_url ); ?>" class="button delete-theme"><?php _e( 'Delete' ); ?></a></td>
   352 				<?php
   435 				<?php
   353 			}
   436 			}
   354 
   437 
   355 			if ( $can_install && 'theme_no_parent' === $broken_theme->errors()->get_error_code() ) {
   438 			if ( $can_install && 'theme_no_parent' === $broken_theme->errors()->get_error_code() ) {
   356 				$parent_theme_name = $broken_theme->get( 'Template' );
   439 				$parent_theme_name = $broken_theme->get( 'Template' );
   357 				$parent_theme = themes_api( 'theme_information', array( 'slug' => urlencode( $parent_theme_name ) ) );
   440 				$parent_theme      = themes_api( 'theme_information', array( 'slug' => urlencode( $parent_theme_name ) ) );
   358 
   441 
   359 				if ( ! is_wp_error( $parent_theme ) ) {
   442 				if ( ! is_wp_error( $parent_theme ) ) {
   360 					$install_url = add_query_arg( array(
   443 					$install_url = add_query_arg(
   361 						'action' => 'install-theme',
   444 						array(
   362 						'theme'  => urlencode( $parent_theme_name ),
   445 							'action' => 'install-theme',
   363 					), admin_url( 'update.php' ) );
   446 							'theme'  => urlencode( $parent_theme_name ),
       
   447 						),
       
   448 						admin_url( 'update.php' )
       
   449 					);
   364 					$install_url = wp_nonce_url( $install_url, 'install-theme_' . $parent_theme_name );
   450 					$install_url = wp_nonce_url( $install_url, 'install-theme_' . $parent_theme_name );
   365 					?>
   451 					?>
   366 					<td><a href="<?php echo esc_url( $install_url ); ?>" class="button install-theme"><?php _e( 'Install Parent Theme' ); ?></a></td>
   452 					<td><a href="<?php echo esc_url( $install_url ); ?>" class="button install-theme"><?php _e( 'Install Parent Theme' ); ?></a></td>
   367 					<?php
   453 					<?php
   368 				}
   454 				}
   371 		</tr>
   457 		</tr>
   372 	<?php endforeach; ?>
   458 	<?php endforeach; ?>
   373 </table>
   459 </table>
   374 </div>
   460 </div>
   375 
   461 
   376 <?php
   462 	<?php
   377 }
   463 }
   378 ?>
   464 ?>
   379 </div><!-- .wrap -->
   465 </div><!-- .wrap -->
   380 
   466 
   381 <?php
   467 <?php
   505 <?php
   591 <?php
   506 wp_print_request_filesystem_credentials_modal();
   592 wp_print_request_filesystem_credentials_modal();
   507 wp_print_admin_notice_templates();
   593 wp_print_admin_notice_templates();
   508 wp_print_update_row_templates();
   594 wp_print_update_row_templates();
   509 
   595 
   510 wp_localize_script( 'updates', '_wpUpdatesItemCounts', array(
   596 wp_localize_script(
   511 	'totals'  => wp_get_update_data(),
   597 	'updates',
   512 ) );
   598 	'_wpUpdatesItemCounts',
       
   599 	array(
       
   600 		'totals' => wp_get_update_data(),
       
   601 	)
       
   602 );
   513 
   603 
   514 require( ABSPATH . 'wp-admin/admin-footer.php' );
   604 require( ABSPATH . 'wp-admin/admin-footer.php' );