wp/wp-admin/theme-install.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    10 require_once( dirname( __FILE__ ) . '/admin.php' );
    10 require_once( dirname( __FILE__ ) . '/admin.php' );
    11 require( ABSPATH . 'wp-admin/includes/theme-install.php' );
    11 require( ABSPATH . 'wp-admin/includes/theme-install.php' );
    12 
    12 
    13 wp_reset_vars( array( 'tab' ) );
    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( __( 'Sorry, you are not allowed to install themes on this site.' ) );
    16 	wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) );
       
    17 }
    17 
    18 
    18 if ( is_multisite() && ! is_network_admin() ) {
    19 if ( is_multisite() && ! is_network_admin() ) {
    19 	wp_redirect( network_admin_url( 'theme-install.php' ) );
    20 	wp_redirect( network_admin_url( 'theme-install.php' ) );
    20 	exit();
    21 	exit();
    21 }
    22 }
    22 
    23 
    23 $title = __( 'Add Themes' );
    24 $title       = __( 'Add Themes' );
    24 $parent_file = 'themes.php';
    25 $parent_file = 'themes.php';
    25 
    26 
    26 if ( ! is_network_admin() ) {
    27 if ( ! is_network_admin() ) {
    27 	$submenu_file = 'themes.php';
    28 	$submenu_file = 'themes.php';
    28 }
    29 }
    37 	if ( false !== strpos( $k, '/' ) ) {
    38 	if ( false !== strpos( $k, '/' ) ) {
    38 		unset( $installed_themes[ $k ] );
    39 		unset( $installed_themes[ $k ] );
    39 	}
    40 	}
    40 }
    41 }
    41 
    42 
    42 wp_localize_script( 'theme', '_wpThemeSettings', array(
    43 wp_localize_script(
    43 	'themes'   => false,
    44 	'theme',
    44 	'settings' => array(
    45 	'_wpThemeSettings',
    45 		'isInstall'  => true,
    46 	array(
    46 		'canInstall' => current_user_can( 'install_themes' ),
    47 		'themes'          => false,
    47 		'installURI' => current_user_can( 'install_themes' ) ? self_admin_url( 'theme-install.php' ) : null,
    48 		'settings'        => array(
    48 		'adminUrl'   => parse_url( self_admin_url(), PHP_URL_PATH )
    49 			'isInstall'  => true,
    49 	),
    50 			'canInstall' => current_user_can( 'install_themes' ),
    50 	'l10n' => array(
    51 			'installURI' => current_user_can( 'install_themes' ) ? self_admin_url( 'theme-install.php' ) : null,
    51 		'addNew'              => __( 'Add New Theme' ),
    52 			'adminUrl'   => parse_url( self_admin_url(), PHP_URL_PATH ),
    52 		'search'              => __( 'Search Themes' ),
       
    53 		'searchPlaceholder'   => __( 'Search themes...' ), // placeholder (no ellipsis)
       
    54 		'upload'              => __( 'Upload Theme' ),
       
    55 		'back'                => __( 'Back' ),
       
    56 		'error'               => sprintf(
       
    57 			/* translators: %s: support forums URL */
       
    58 			__( '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="%s">support forums</a>.' ),
       
    59 			__( 'https://wordpress.org/support/' )
       
    60 		),
    53 		),
    61 		'tryAgain'            => __( 'Try Again' ),
    54 		'l10n'            => array(
    62 		'themesFound'         => __( 'Number of Themes found: %d' ),
    55 			'addNew'              => __( 'Add New Theme' ),
    63 		'noThemesFound'       => __( 'No themes found. Try a different search.' ),
    56 			'search'              => __( 'Search Themes' ),
    64 		'collapseSidebar'     => __( 'Collapse Sidebar' ),
    57 			'searchPlaceholder'   => __( 'Search themes...' ), // placeholder (no ellipsis)
    65 		'expandSidebar'       => __( 'Expand Sidebar' ),
    58 			'upload'              => __( 'Upload Theme' ),
    66 		/* translators: accessibility text */
    59 			'back'                => __( 'Back' ),
    67 		'selectFeatureFilter' => __( 'Select one or more Theme features to filter by' ),
    60 			'error'               => sprintf(
    68 	),
    61 				/* translators: %s: support forums URL */
    69 	'installedThemes' => array_keys( $installed_themes ),
    62 				__( '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="%s">support forums</a>.' ),
    70 ) );
    63 				__( 'https://wordpress.org/support/' )
       
    64 			),
       
    65 			'tryAgain'            => __( 'Try Again' ),
       
    66 			'themesFound'         => __( 'Number of Themes found: %d' ),
       
    67 			'noThemesFound'       => __( 'No themes found. Try a different search.' ),
       
    68 			'collapseSidebar'     => __( 'Collapse Sidebar' ),
       
    69 			'expandSidebar'       => __( 'Expand Sidebar' ),
       
    70 			/* translators: accessibility text */
       
    71 			'selectFeatureFilter' => __( 'Select one or more Theme features to filter by' ),
       
    72 		),
       
    73 		'installedThemes' => array_keys( $installed_themes ),
       
    74 	)
       
    75 );
    71 
    76 
    72 wp_enqueue_script( 'theme' );
    77 wp_enqueue_script( 'theme' );
    73 wp_enqueue_script( 'updates' );
    78 wp_enqueue_script( 'updates' );
    74 
    79 
    75 if ( $tab ) {
    80 if ( $tab ) {
    85 	do_action( "install_themes_pre_{$tab}" );
    90 	do_action( "install_themes_pre_{$tab}" );
    86 }
    91 }
    87 
    92 
    88 $help_overview =
    93 $help_overview =
    89 	'<p>' . sprintf(
    94 	'<p>' . sprintf(
    90 			/* translators: %s: Theme Directory URL */
    95 		/* translators: %s: Theme Directory URL */
    91 			__( '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">WordPress 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.' ),
    96 			__( '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">WordPress 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.' ),
    92 			__( 'https://wordpress.org/themes/' )
    97 		__( 'https://wordpress.org/themes/' )
    93 		) . '</p>' .
    98 	) . '</p>' .
    94 	'<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>' .
    99 	'<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>' .
    95 	'<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>' .
   100 	'<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>' .
    96 	'<p>' . sprintf(
   101 	'<p>' . sprintf(
    97 			/* translators: %s: /wp-content/themes */
   102 		/* translators: %s: /wp-content/themes */
    98 			__( '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 %s directory.' ),
   103 			__( '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 %s directory.' ),
    99 			'<code>/wp-content/themes</code>'
   104 		'<code>/wp-content/themes</code>'
   100 		) . '</p>';
   105 	) . '</p>';
   101 
   106 
   102 get_current_screen()->add_help_tab( array(
   107 get_current_screen()->add_help_tab(
   103 	'id'      => 'overview',
   108 	array(
   104 	'title'   => __('Overview'),
   109 		'id'      => 'overview',
   105 	'content' => $help_overview
   110 		'title'   => __( 'Overview' ),
   106 ) );
   111 		'content' => $help_overview,
       
   112 	)
       
   113 );
   107 
   114 
   108 $help_installing =
   115 $help_installing =
   109 	'<p>' . __('Once you have generated a list of themes, you can preview and install any of them. Click on the thumbnail of the theme you&#8217;re interested in previewing. It will open up in a full-screen Preview page to give you a better idea of how that theme will look.') . '</p>' .
   116 	'<p>' . __( 'Once you have generated a list of themes, you can preview and install any of them. Click on the thumbnail of the theme you&#8217;re interested in previewing. It will open up in a full-screen Preview page to give you a better idea of how that theme will look.' ) . '</p>' .
   110 	'<p>' . __('To install the theme so you can preview it with your site&#8217;s content and customize its theme options, click the "Install" button at the top of the left-hand pane. The theme files will be downloaded to your website automatically. When this is complete, the theme is now available for activation, which you can do by clicking the "Activate" link, or by navigating to your Manage Themes screen and clicking the "Live Preview" link under any installed theme&#8217;s thumbnail image.') . '</p>';
   117 	'<p>' . __( 'To install the theme so you can preview it with your site&#8217;s content and customize its theme options, click the "Install" button at the top of the left-hand pane. The theme files will be downloaded to your website automatically. When this is complete, the theme is now available for activation, which you can do by clicking the "Activate" link, or by navigating to your Manage Themes screen and clicking the "Live Preview" link under any installed theme&#8217;s thumbnail image.' ) . '</p>';
   111 
   118 
   112 get_current_screen()->add_help_tab( array(
   119 get_current_screen()->add_help_tab(
   113 	'id'      => 'installing',
   120 	array(
   114 	'title'   => __('Previewing and Installing'),
   121 		'id'      => 'installing',
   115 	'content' => $help_installing
   122 		'title'   => __( 'Previewing and Installing' ),
   116 ) );
   123 		'content' => $help_installing,
       
   124 	)
       
   125 );
   117 
   126 
   118 get_current_screen()->set_help_sidebar(
   127 get_current_screen()->set_help_sidebar(
   119 	'<p><strong>' . __('For more information:') . '</strong></p>' .
   128 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   120 	'<p>' . __('<a href="https://codex.wordpress.org/Using_Themes#Adding_New_Themes">Documentation on Adding New Themes</a>') . '</p>' .
   129 	'<p>' . __( '<a href="https://codex.wordpress.org/Using_Themes#Adding_New_Themes">Documentation on Adding New Themes</a>' ) . '</p>' .
   121 	'<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
   130 	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
   122 );
   131 );
   123 
   132 
   124 include(ABSPATH . 'wp-admin/admin-header.php');
   133 include( ABSPATH . 'wp-admin/admin-header.php' );
   125 
   134 
   126 ?>
   135 ?>
   127 <div class="wrap">
   136 <div class="wrap">
   128 	<h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
   137 	<h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
   129 
   138 
   134 	 *
   143 	 *
   135 	 * This filter is for backward compatibility only, for the suppression of the upload tab.
   144 	 * This filter is for backward compatibility only, for the suppression of the upload tab.
   136 	 *
   145 	 *
   137 	 * @since 2.8.0
   146 	 * @since 2.8.0
   138 	 *
   147 	 *
   139 	 * @param array $tabs The tabs shown on the Add Themes screen. Default is 'upload'.
   148 	 * @param string[] $tabs Associative array of the tabs shown on the Add Themes screen. Default is 'upload'.
   140 	 */
   149 	 */
   141 	$tabs = apply_filters( 'install_themes_tabs', array( 'upload' => __( 'Upload Theme' ) ) );
   150 	$tabs = apply_filters( 'install_themes_tabs', array( 'upload' => __( 'Upload Theme' ) ) );
   142 	if ( ! empty( $tabs['upload'] ) && current_user_can( 'upload_themes' ) ) {
   151 	if ( ! empty( $tabs['upload'] ) && current_user_can( 'upload_themes' ) ) {
   143 		echo ' <button type="button" class="upload-view-toggle page-title-action hide-if-no-js" aria-expanded="false">' . __( 'Upload Theme' ) . '</button>';
   152 		echo ' <button type="button" class="upload-view-toggle page-title-action hide-if-no-js" aria-expanded="false">' . __( 'Upload Theme' ) . '</button>';
   144 	}
   153 	}
   300 
   309 
   301 <script id="tmpl-theme-preview" type="text/template">
   310 <script id="tmpl-theme-preview" type="text/template">
   302 	<div class="wp-full-overlay-sidebar">
   311 	<div class="wp-full-overlay-sidebar">
   303 		<div class="wp-full-overlay-header">
   312 		<div class="wp-full-overlay-header">
   304 			<button class="close-full-overlay"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></button>
   313 			<button class="close-full-overlay"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></button>
   305 			<button class="previous-theme"><span class="screen-reader-text"><?php _ex( 'Previous', 'Button label for a theme' ); ?></span></button>
   314 			<button class="previous-theme"><span class="screen-reader-text"><?php _e( 'Previous theme' ); ?></span></button>
   306 			<button class="next-theme"><span class="screen-reader-text"><?php _ex( 'Next', 'Button label for a theme' ); ?></span></button>
   315 			<button class="next-theme"><span class="screen-reader-text"><?php _e( 'Next theme' ); ?></span></button>
   307 			<# if ( data.installed ) { #>
   316 			<# if ( data.installed ) { #>
   308 				<a class="button button-primary activate" href="{{ data.activate_url }}"><?php _e( 'Activate' ); ?></a>
   317 				<a class="button button-primary activate" href="{{ data.activate_url }}"><?php _e( 'Activate' ); ?></a>
   309 			<# } else { #>
   318 			<# } else { #>
   310 				<a href="{{ data.install_url }}" class="button button-primary theme-install" data-name="{{ data.name }}" data-slug="{{ data.id }}"><?php _e( 'Install' ); ?></a>
   319 				<a href="{{ data.install_url }}" class="button button-primary theme-install" data-name="{{ data.name }}" data-slug="{{ data.id }}"><?php _e( 'Install' ); ?></a>
   311 			<# } #>
   320 			<# } #>
   324 
   333 
   325 					<div class="theme-details">
   334 					<div class="theme-details">
   326 						<# if ( data.rating ) { #>
   335 						<# if ( data.rating ) { #>
   327 							<div class="theme-rating">
   336 							<div class="theme-rating">
   328 								{{{ data.stars }}}
   337 								{{{ data.stars }}}
   329 								<span class="num-ratings">({{ data.num_ratings }})</span>
   338 								<a class="num-ratings" href="{{ data.reviews_url }}">
       
   339 									<?php
       
   340 									/* translators: %s: number of ratings */
       
   341 									echo sprintf( __( '(%s ratings)' ), '{{ data.num_ratings }}' );
       
   342 									?>
       
   343 								</a>
   330 							</div>
   344 							</div>
   331 						<# } else { #>
   345 						<# } else { #>
   332 							<span class="no-rating"><?php _e( 'This theme has not been rated yet.' ); ?></span>
   346 							<span class="no-rating"><?php _e( 'This theme has not been rated yet.' ); ?></span>
   333 						<# } #>
   347 						<# } #>
   334 						<div class="theme-version">
   348 						<div class="theme-version">
   355 
   369 
   356 <?php
   370 <?php
   357 wp_print_request_filesystem_credentials_modal();
   371 wp_print_request_filesystem_credentials_modal();
   358 wp_print_admin_notice_templates();
   372 wp_print_admin_notice_templates();
   359 
   373 
   360 include(ABSPATH . 'wp-admin/admin-footer.php');
   374 include( ABSPATH . 'wp-admin/admin-footer.php' );