wp/wp-admin/theme-install.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Administration
     6  * @subpackage Administration
     7  */
     7  */
     8 
     8 
     9 if ( !defined( 'IFRAME_REQUEST' ) && isset( $_GET['tab'] ) && ( 'theme-information' == $_GET['tab'] ) )
       
    10 	define( 'IFRAME_REQUEST', true );
       
    11 
       
    12 /** WordPress Administration Bootstrap */
     9 /** WordPress Administration Bootstrap */
    13 require_once( dirname( __FILE__ ) . '/admin.php' );
    10 require_once( dirname( __FILE__ ) . '/admin.php' );
       
    11 require( ABSPATH . 'wp-admin/includes/theme-install.php' );
       
    12 
       
    13 wp_reset_vars( array( 'tab' ) );
    14 
    14 
    15 if ( ! current_user_can('install_themes') )
    15 if ( ! current_user_can('install_themes') )
    16 	wp_die( __( 'You do not have sufficient permissions to install themes on this site.' ) );
    16 	wp_die( __( 'You do not have sufficient permissions to install themes on this site.' ) );
    17 
    17 
    18 if ( is_multisite() && ! is_network_admin() ) {
    18 if ( is_multisite() && ! is_network_admin() ) {
    19 	wp_redirect( network_admin_url( 'theme-install.php' ) );
    19 	wp_redirect( network_admin_url( 'theme-install.php' ) );
    20 	exit();
    20 	exit();
    21 }
    21 }
    22 
    22 
    23 $wp_list_table = _get_list_table('WP_Theme_Install_List_Table');
    23 $title = __( 'Add Themes' );
    24 $pagenum = $wp_list_table->get_pagenum();
       
    25 $wp_list_table->prepare_items();
       
    26 
       
    27 $title = __('Install Themes');
       
    28 $parent_file = 'themes.php';
    24 $parent_file = 'themes.php';
    29 if ( !is_network_admin() )
    25 
       
    26 if ( ! is_network_admin() ) {
    30 	$submenu_file = 'themes.php';
    27 	$submenu_file = 'themes.php';
    31 
    28 }
    32 wp_enqueue_script( 'theme-install' );
    29 
       
    30 $installed_themes = search_theme_directories();
       
    31 foreach ( $installed_themes as $k => $v ) {
       
    32 	if ( false !== strpos( $k, '/' ) ) {
       
    33 		unset( $installed_themes[ $k ] );
       
    34 	}
       
    35 }
       
    36 
       
    37 wp_localize_script( 'theme', '_wpThemeSettings', array(
       
    38 	'themes'   => false,
       
    39 	'settings' => array(
       
    40 		'isInstall'     => true,
       
    41 		'canInstall'    => current_user_can( 'install_themes' ),
       
    42 		'installURI'    => current_user_can( 'install_themes' ) ? self_admin_url( 'theme-install.php' ) : null,
       
    43 		'adminUrl'      => parse_url( self_admin_url(), PHP_URL_PATH )
       
    44 	),
       
    45 	'l10n' => array(
       
    46 		'addNew' => __( 'Add New Theme' ),
       
    47 		'search' => __( 'Search Themes' ),
       
    48 		'searchPlaceholder' => __( 'Search themes...' ), // placeholder (no ellipsis)
       
    49 		'upload' => __( 'Upload Theme' ),
       
    50 		'back'   => __( 'Back' ),
       
    51 		'error'  => __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ),
       
    52 		'themesFound'   => __( 'Number of Themes found: %d' ),
       
    53 		'noThemesFound' => __( 'No themes found. Try a different search.' ),
       
    54 	),
       
    55 	'installedThemes' => array_keys( $installed_themes ),
       
    56 ) );
       
    57 
    33 wp_enqueue_script( 'theme' );
    58 wp_enqueue_script( 'theme' );
    34 
    59 
    35 $body_id = $tab;
    60 if ( $tab ) {
    36 
    61 	/**
    37 do_action('install_themes_pre_' . $tab); //Used to override the general interface, Eg, install or theme information.
    62 	 * Fires before each of the tabs are rendered on the Install Themes page.
       
    63 	 *
       
    64 	 * The dynamic portion of the hook name, `$tab`, refers to the current
       
    65 	 * theme install tab. Possible values are 'dashboard', 'search', 'upload',
       
    66 	 * 'featured', 'new', or 'updated'.
       
    67 	 *
       
    68 	 * @since 2.8.0
       
    69 	 */
       
    70 	do_action( "install_themes_pre_{$tab}" );
       
    71 }
    38 
    72 
    39 $help_overview =
    73 $help_overview =
    40 	'<p>' . sprintf(__('You can find additional themes for your site by using the Theme Browser/Installer on this screen, which will display themes from the <a href="%s" target="_blank">WordPress.org Theme Directory</a>. These themes are designed and developed by third parties, are available free of charge, and are compatible with the license WordPress uses.'), 'http://wordpress.org/themes/') . '</p>' .
    74 	'<p>' . sprintf(__('You can find additional themes for your site by using the Theme Browser/Installer on this screen, which will display themes from the <a href="%s" target="_blank">WordPress.org Theme Directory</a>. These themes are designed and developed by third parties, are available free of charge, and are compatible with the license WordPress uses.'), 'https://wordpress.org/themes/') . '</p>' .
    41 	'<p>' . __('You can Search for themes by keyword, author, or tag, or can get more specific and search by criteria listed in the feature filter. Alternately, you can browse the themes that are Featured, Newest, or Recently Updated. When you find a theme you like, you can preview it or install it.') . '</p>' .
    75 	'<p>' . __( 'You can Search for themes by keyword, author, or tag, or can get more specific and search by criteria listed in the feature filter.' ) . ' <span id="live-search-desc">' . __( 'The search results will be updated as you type.' ) . '</span></p>' .
       
    76 	'<p>' . __( 'Alternately, you can browse the themes that are Featured, Popular, or Latest. When you find a theme you like, you can preview it or install it.' ) . '</p>' .
    42 	'<p>' . __('You can Upload a theme manually if you have already downloaded its ZIP archive onto your computer (make sure it is from a trusted and original source). You can also do it the old-fashioned way and copy a downloaded theme&#8217;s folder via FTP into your <code>/wp-content/themes</code> directory.') . '</p>';
    77 	'<p>' . __('You can Upload a theme manually if you have already downloaded its ZIP archive onto your computer (make sure it is from a trusted and original source). You can also do it the old-fashioned way and copy a downloaded theme&#8217;s folder via FTP into your <code>/wp-content/themes</code> directory.') . '</p>';
    43 
    78 
    44 get_current_screen()->add_help_tab( array(
    79 get_current_screen()->add_help_tab( array(
    45 	'id'      => 'overview',
    80 	'id'      => 'overview',
    46 	'title'   => __('Overview'),
    81 	'title'   => __('Overview'),
    57 	'content' => $help_installing
    92 	'content' => $help_installing
    58 ) );
    93 ) );
    59 
    94 
    60 get_current_screen()->set_help_sidebar(
    95 get_current_screen()->set_help_sidebar(
    61 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    96 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    62 	'<p>' . __('<a href="http://codex.wordpress.org/Using_Themes#Adding_New_Themes" target="_blank">Documentation on Adding New Themes</a>') . '</p>' .
    97 	'<p>' . __('<a href="https://codex.wordpress.org/Using_Themes#Adding_New_Themes" target="_blank">Documentation on Adding New Themes</a>') . '</p>' .
    63 	'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
    98 	'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
    64 );
    99 );
    65 
   100 
    66 include(ABSPATH . 'wp-admin/admin-header.php');
   101 include(ABSPATH . 'wp-admin/admin-header.php');
       
   102 
    67 ?>
   103 ?>
    68 <div class="wrap">
   104 <div class="wrap">
       
   105 	<h2><?php
       
   106 	echo esc_html( $title );
       
   107 
       
   108 	/**
       
   109 	 * Filter the tabs shown on the Add Themes screen.
       
   110 	 *
       
   111 	 * This filter is for backwards compatibility only, for the suppression
       
   112 	 * of the upload tab.
       
   113 	 *
       
   114 	 * @since 2.8.0
       
   115 	 *
       
   116 	 * @param array $tabs The tabs shown on the Add Themes screen. Default is 'upload'.
       
   117 	 */
       
   118 	$tabs = apply_filters( 'install_themes_tabs', array( 'upload' => __( 'Upload Theme' ) ) );
       
   119 	if ( ! empty( $tabs['upload'] ) && current_user_can( 'upload_themes' ) ) {
       
   120 		echo ' <a href="#" class="upload add-new-h2">' . __( 'Upload Theme' ) . '</a>';
       
   121 		echo ' <a href="#" class="browse-themes add-new-h2">' . _x( 'Browse', 'themes' ) . '</a>';
       
   122 	}
       
   123 	?></h2>
       
   124 
       
   125 	<div class="upload-theme">
       
   126 	<?php install_themes_upload(); ?>
       
   127 	</div>
       
   128 
       
   129 	<div class="wp-filter">
       
   130 		<div class="filter-count">
       
   131 			<span class="count theme-count"></span>
       
   132 		</div>
       
   133 
       
   134 		<ul class="filter-links">
       
   135 			<li><a href="#" data-sort="featured"><?php _ex( 'Featured', 'themes' ); ?></a></li>
       
   136 			<li><a href="#" data-sort="popular"><?php _ex( 'Popular', 'themes' ); ?></a></li>
       
   137 			<li><a href="#" data-sort="new"><?php _ex( 'Latest', 'themes' ); ?></a></li>
       
   138 		</ul>
       
   139 
       
   140 		<a class="drawer-toggle" href="#"><?php _e( 'Feature Filter' ); ?></a>
       
   141 
       
   142 		<div class="search-form"></div>
       
   143 
       
   144 		<div class="filter-drawer">
       
   145 			<div class="buttons">
       
   146 				<a class="apply-filters button button-secondary" href="#"><?php _e( 'Apply Filters' ); ?><span></span></a>
       
   147 				<a class="clear-filters button button-secondary" href="#"><?php _e( 'Clear' ); ?></a>
       
   148 			</div>
       
   149 		<?php
       
   150 		$feature_list = get_theme_feature_list();
       
   151 		foreach ( $feature_list as $feature_name => $features ) {
       
   152 			echo '<div class="filter-group">';
       
   153 			$feature_name = esc_html( $feature_name );
       
   154 			echo '<h4>' . $feature_name . '</h4>';
       
   155 			echo '<ol class="feature-group">';
       
   156 			foreach ( $features as $feature => $feature_name ) {
       
   157 				$feature = esc_attr( $feature );
       
   158 				echo '<li><input type="checkbox" id="filter-id-' . $feature . '" value="' . $feature . '" /> ';
       
   159 				echo '<label for="filter-id-' . $feature . '">' . $feature_name . '</label></li>';
       
   160 			}
       
   161 			echo '</ol>';
       
   162 			echo '</div>';
       
   163 		}
       
   164 		?>
       
   165 			<div class="filtered-by">
       
   166 				<span><?php _e( 'Filtering by:' ); ?></span>
       
   167 				<div class="tags"></div>
       
   168 				<a href="#"><?php _e( 'Edit' ); ?></a>
       
   169 			</div>
       
   170 		</div>
       
   171 	</div>
       
   172 	<div class="theme-browser content-filterable"></div>
       
   173 	<div class="theme-install-overlay wp-full-overlay expanded"></div>
       
   174 
       
   175 	<p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p>
       
   176 	<span class="spinner"></span>
       
   177 
       
   178 	<br class="clear" />
    69 <?php
   179 <?php
    70 screen_icon();
   180 if ( $tab ) {
    71 
   181 	/**
    72 if ( is_network_admin() ) : ?>
   182 	 * Fires at the top of each of the tabs on the Install Themes page.
    73 <h2><?php echo esc_html( $title ); ?></h2>
   183 	 *
    74 <?php else : ?>
   184 	 * The dynamic portion of the hook name, `$tab`, refers to the current
    75 <h2 class="nav-tab-wrapper"><a href="themes.php" class="nav-tab"><?php echo esc_html_x('Manage Themes', 'theme'); ?></a><a href="theme-install.php" class="nav-tab nav-tab-active"><?php echo esc_html( $title ); ?></a></h2>
   185 	 * theme install tab. Possible values are 'dashboard', 'search', 'upload',
    76 
   186 	 * 'featured', 'new', or 'updated'.
    77 <?php
   187 	 *
    78 endif;
   188 	 * @since 2.8.0
    79 
   189 	 *
    80 $wp_list_table->views(); ?>
   190 	 * @param int $paged Number of the current page of results being viewed.
    81 
   191 	 */
    82 <br class="clear" />
   192 	do_action( "install_themes_{$tab}", $paged );
    83 <?php do_action('install_themes_' . $tab, $paged); ?>
   193 }
       
   194 ?>
    84 </div>
   195 </div>
       
   196 
       
   197 <script id="tmpl-theme" type="text/template">
       
   198 	<# if ( data.screenshot_url ) { #>
       
   199 		<div class="theme-screenshot">
       
   200 			<img src="{{ data.screenshot_url }}" alt="" />
       
   201 		</div>
       
   202 	<# } else { #>
       
   203 		<div class="theme-screenshot blank"></div>
       
   204 	<# } #>
       
   205 	<span class="more-details"><?php _ex( 'Details &amp; Preview', 'theme' ); ?></span>
       
   206 	<div class="theme-author"><?php printf( __( 'By %s' ), '{{ data.author }}' ); ?></div>
       
   207 	<h3 class="theme-name">{{ data.name }}</h3>
       
   208 
       
   209 	<div class="theme-actions">
       
   210 		<a class="button button-primary" href="{{ data.install_url }}"><?php esc_html_e( 'Install' ); ?></a>
       
   211 		<a class="button button-secondary preview install-theme-preview" href="#"><?php esc_html_e( 'Preview' ); ?></a>
       
   212 	</div>
       
   213 
       
   214 	<# if ( data.installed ) { #>
       
   215 		<div class="theme-installed"><?php _ex( 'Already Installed', 'theme' ); ?></div>
       
   216 	<# } #>
       
   217 </script>
       
   218 
       
   219 <script id="tmpl-theme-preview" type="text/template">
       
   220 	<div class="wp-full-overlay-sidebar">
       
   221 		<div class="wp-full-overlay-header">
       
   222 			<a href="#" class="close-full-overlay"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></a>
       
   223 			<a href="#" class="previous-theme"><span class="screen-reader-text"><?php _ex( 'Previous', 'Button label for a theme' ); ?></span></a>
       
   224 			<a href="#" class="next-theme"><span class="screen-reader-text"><?php _ex( 'Next', 'Button label for a theme' ); ?></span></a>
       
   225 		<# if ( data.installed ) { #>
       
   226 			<a href="#" class="button button-primary theme-install disabled"><?php _ex( 'Installed', 'theme' ); ?></a>
       
   227 		<# } else { #>
       
   228 			<a href="{{ data.install_url }}" class="button button-primary theme-install"><?php _e( 'Install' ); ?></a>
       
   229 		<# } #>
       
   230 		</div>
       
   231 		<div class="wp-full-overlay-sidebar-content">
       
   232 			<div class="install-theme-info">
       
   233 				<h3 class="theme-name">{{ data.name }}</h3>
       
   234 				<span class="theme-by"><?php printf( __( 'By %s' ), '{{ data.author }}' ); ?></span>
       
   235 
       
   236 				<img class="theme-screenshot" src="{{ data.screenshot_url }}" alt="" />
       
   237 
       
   238 				<div class="theme-details">
       
   239 					<# if ( data.rating ) { #>
       
   240 						<div class="rating rating-{{ Math.round( data.rating / 10 ) * 10 }}">
       
   241 							<span class="one"></span>
       
   242 							<span class="two"></span>
       
   243 							<span class="three"></span>
       
   244 							<span class="four"></span>
       
   245 							<span class="five"></span>
       
   246 							<small class="ratings">{{ data.num_ratings }}</small>
       
   247 						</div>
       
   248 					<# } else { #>
       
   249 						<div class="rating">
       
   250 							<small class="ratings"><?php _e( 'This theme has not been rated yet.' ); ?></small>
       
   251 						</div>
       
   252 					<# } #>
       
   253 					<div class="theme-version"><?php printf( __( 'Version: %s' ), '{{ data.version }}' ); ?></div>
       
   254 					<div class="theme-description">{{{ data.description }}}</div>
       
   255 				</div>
       
   256 			</div>
       
   257 		</div>
       
   258 		<div class="wp-full-overlay-footer">
       
   259 			<a href="#" class="collapse-sidebar" title="<?php esc_attr_e( 'Collapse Sidebar' ); ?>">
       
   260 				<span class="collapse-sidebar-label"><?php _e( 'Collapse' ); ?></span>
       
   261 				<span class="collapse-sidebar-arrow"></span>
       
   262 			</a>
       
   263 		</div>
       
   264 	</div>
       
   265 	<div class="wp-full-overlay-main">
       
   266 		<iframe src="{{ data.preview_url }}" title="<?php esc_attr_e( 'Preview' ); ?>" />
       
   267 	</div>
       
   268 </script>
       
   269 
    85 <?php
   270 <?php
    86 include(ABSPATH . 'wp-admin/admin-footer.php');
   271 include(ABSPATH . 'wp-admin/admin-footer.php');