]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/theme-install.php
WordPress 4.7.2
[autoinstalls/wordpress.git] / wp-admin / theme-install.php
1 <?php
2 /**
3  * Install theme administration panel.
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** WordPress Administration Bootstrap */
10 require_once( dirname( __FILE__ ) . '/admin.php' );
11 require( ABSPATH . 'wp-admin/includes/theme-install.php' );
12
13 wp_reset_vars( array( 'tab' ) );
14
15 if ( ! current_user_can('install_themes') )
16         wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) );
17
18 if ( is_multisite() && ! is_network_admin() ) {
19         wp_redirect( network_admin_url( 'theme-install.php' ) );
20         exit();
21 }
22
23 $title = __( 'Add Themes' );
24 $parent_file = 'themes.php';
25
26 if ( ! is_network_admin() ) {
27         $submenu_file = 'themes.php';
28 }
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'               => sprintf(
52                         /* translators: %s: support forums URL */
53                         __( '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>.' ),
54                         __( 'https://wordpress.org/support/' )
55                 ),
56                 'themesFound'         => __( 'Number of Themes found: %d' ),
57                 'noThemesFound'       => __( 'No themes found. Try a different search.' ),
58                 'collapseSidebar'     => __( 'Collapse Sidebar' ),
59                 'expandSidebar'       => __( 'Expand Sidebar' ),
60                 /* translators: hidden accessibility text */
61                 'selectFeatureFilter' => __( 'Select one or more Theme features to filter by' ),
62         ),
63         'installedThemes' => array_keys( $installed_themes ),
64 ) );
65
66 wp_enqueue_script( 'theme' );
67 wp_enqueue_script( 'updates' );
68
69 if ( $tab ) {
70         /**
71          * Fires before each of the tabs are rendered on the Install Themes page.
72          *
73          * The dynamic portion of the hook name, `$tab`, refers to the current
74          * theme install tab. Possible values are 'dashboard', 'search', 'upload',
75          * 'featured', 'new', or 'updated'.
76          *
77          * @since 2.8.0
78          */
79         do_action( "install_themes_pre_{$tab}" );
80 }
81
82 $help_overview =
83         '<p>' . sprintf(
84                         /* translators: %s: Theme Directory URL */
85                         __( '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.' ),
86                         __( 'https://wordpress.org/themes/' )
87                 ) . '</p>' .
88         '<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>' .
89         '<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>' .
90         '<p>' . sprintf(
91                         /* translators: %s: /wp-content/themes */
92                         __( '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.' ),
93                         '<code>/wp-content/themes</code>'
94                 ) . '</p>';
95
96 get_current_screen()->add_help_tab( array(
97         'id'      => 'overview',
98         'title'   => __('Overview'),
99         'content' => $help_overview
100 ) );
101
102 $help_installing =
103         '<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>' .
104         '<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>';
105
106 get_current_screen()->add_help_tab( array(
107         'id'      => 'installing',
108         'title'   => __('Previewing and Installing'),
109         'content' => $help_installing
110 ) );
111
112 get_current_screen()->set_help_sidebar(
113         '<p><strong>' . __('For more information:') . '</strong></p>' .
114         '<p>' . __('<a href="https://codex.wordpress.org/Using_Themes#Adding_New_Themes">Documentation on Adding New Themes</a>') . '</p>' .
115         '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
116 );
117
118 include(ABSPATH . 'wp-admin/admin-header.php');
119
120 ?>
121 <div class="wrap">
122         <h1><?php
123         echo esc_html( $title );
124
125         /**
126          * Filters the tabs shown on the Add Themes screen.
127          *
128          * This filter is for backward compatibility only, for the suppression of the upload tab.
129          *
130          * @since 2.8.0
131          *
132          * @param array $tabs The tabs shown on the Add Themes screen. Default is 'upload'.
133          */
134         $tabs = apply_filters( 'install_themes_tabs', array( 'upload' => __( 'Upload Theme' ) ) );
135         if ( ! empty( $tabs['upload'] ) && current_user_can( 'upload_themes' ) ) {
136                 echo ' <button type="button" class="upload-view-toggle page-title-action hide-if-no-js" aria-expanded="false">' . __( 'Upload Theme' ) . '</button>';
137         }
138         ?></h1>
139         <div class="error hide-if-js">
140                 <p><?php _e( 'The Theme Installer screen requires JavaScript.' ); ?></p>
141         </div>
142
143         <div class="upload-theme">
144         <?php install_themes_upload(); ?>
145         </div>
146
147         <h2 class="screen-reader-text hide-if-no-js"><?php _e( 'Filter themes list' ); ?></h2>
148
149         <div class="wp-filter hide-if-no-js">
150                 <div class="filter-count">
151                         <span class="count theme-count"></span>
152                 </div>
153
154                 <ul class="filter-links">
155                         <li><a href="#" data-sort="featured"><?php _ex( 'Featured', 'themes' ); ?></a></li>
156                         <li><a href="#" data-sort="popular"><?php _ex( 'Popular', 'themes' ); ?></a></li>
157                         <li><a href="#" data-sort="new"><?php _ex( 'Latest', 'themes' ); ?></a></li>
158                         <li><a href="#" data-sort="favorites"><?php _ex( 'Favorites', 'themes' ); ?></a></li>
159                 </ul>
160
161                 <button type="button" class="button drawer-toggle" aria-expanded="false"><?php _e( 'Feature Filter' ); ?></button>
162
163                 <div class="search-form"></div>
164
165                 <div class="favorites-form">
166                         <?php
167                         $action = 'save_wporg_username_' . get_current_user_id();
168                         if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), $action ) ) {
169                                 $user = isset( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' );
170                                 update_user_meta( get_current_user_id(), 'wporg_favorites', $user );
171                         } else {
172                                 $user = get_user_option( 'wporg_favorites' );
173                         }
174                         ?>
175                         <p class="install-help"><?php _e( 'If you have marked themes as favorites on WordPress.org, you can browse them here.' ); ?></p>
176
177                         <p>
178                                 <label for="wporg-username-input"><?php _e( 'Your WordPress.org username:' ); ?></label>
179                                 <input type="hidden" id="wporg-username-nonce" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( $action ) ); ?>" />
180                                 <input type="search" id="wporg-username-input" value="<?php echo esc_attr( $user ); ?>" />
181                                 <input type="button" class="button favorites-form-submit" value="<?php esc_attr_e( 'Get Favorites' ); ?>" />
182                         </p>
183                 </div>
184
185                 <div class="filter-drawer">
186                         <div class="buttons">
187                                 <button type="button" class="apply-filters button"><?php _e( 'Apply Filters' ); ?><span></span></button>
188                                 <button type="button" class="clear-filters button" aria-label="<?php esc_attr_e( 'Clear current filters' ); ?>"><?php _e( 'Clear' ); ?></button>
189                         </div>
190                 <?php
191                 $feature_list = get_theme_feature_list();
192                 foreach ( $feature_list as $feature_name => $features ) {
193                         echo '<fieldset class="filter-group">';
194                         $feature_name = esc_html( $feature_name );
195                         echo '<legend>' . $feature_name . '</legend>';
196                         echo '<div class="filter-group-feature">';
197                         foreach ( $features as $feature => $feature_name ) {
198                                 $feature = esc_attr( $feature );
199                                 echo '<input type="checkbox" id="filter-id-' . $feature . '" value="' . $feature . '" /> ';
200                                 echo '<label for="filter-id-' . $feature . '">' . $feature_name . '</label><br>';
201                         }
202                         echo '</div>';
203                         echo '</fieldset>';
204                 }
205                 ?>
206                         <div class="buttons">
207                                 <button type="button" class="apply-filters button"><?php _e( 'Apply Filters' ); ?><span></span></button>
208                                 <button type="button" class="clear-filters button" aria-label="<?php esc_attr_e( 'Clear current filters' ); ?>"><?php _e( 'Clear' ); ?></button>
209                         </div>
210                         <div class="filtered-by">
211                                 <span><?php _e( 'Filtering by:' ); ?></span>
212                                 <div class="tags"></div>
213                                 <button type="button" class="button-link edit-filters"><?php _e( 'Edit Filters' ); ?></button>
214                         </div>
215                 </div>
216         </div>
217         <h2 class="screen-reader-text hide-if-no-js"><?php _e( 'Themes list' ); ?></h2>
218         <div class="theme-browser content-filterable"></div>
219         <div class="theme-install-overlay wp-full-overlay expanded"></div>
220
221         <p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p>
222         <span class="spinner"></span>
223
224 <?php
225 if ( $tab ) {
226         /**
227          * Fires at the top of each of the tabs on the Install Themes page.
228          *
229          * The dynamic portion of the hook name, `$tab`, refers to the current
230          * theme install tab. Possible values are 'dashboard', 'search', 'upload',
231          * 'featured', 'new', or 'updated'.
232          *
233          * @since 2.8.0
234          *
235          * @param int $paged Number of the current page of results being viewed.
236          */
237         do_action( "install_themes_{$tab}", $paged );
238 }
239 ?>
240 </div>
241
242 <script id="tmpl-theme" type="text/template">
243         <# if ( data.screenshot_url ) { #>
244                 <div class="theme-screenshot">
245                         <img src="{{ data.screenshot_url }}" alt="" />
246                 </div>
247         <# } else { #>
248                 <div class="theme-screenshot blank"></div>
249         <# } #>
250         <span class="more-details"><?php _ex( 'Details &amp; Preview', 'theme' ); ?></span>
251         <div class="theme-author">
252                 <?php
253                 /* translators: %s: Theme author name */
254                 printf( __( 'By %s' ), '{{ data.author }}' );
255                 ?>
256         </div>
257         <h3 class="theme-name">{{ data.name }}</h3>
258
259         <div class="theme-actions">
260                 <# if ( data.installed ) { #>
261                         <?php
262                         /* translators: %s: Theme name */
263                         $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
264                         ?>
265                         <# if ( data.activate_url ) { #>
266                                 <a class="button button-primary activate" href="{{ data.activate_url }}" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a>
267                         <# } #>
268                         <# if ( data.customize_url ) { #>
269                                 <a class="button load-customize" href="{{ data.customize_url }}"><?php _e( 'Live Preview' ); ?></a>
270                         <# } else { #>
271                                 <button class="button preview install-theme-preview"><?php _e( 'Preview' ); ?></button>
272                         <# } #>
273                 <# } else { #>
274                         <?php
275                         /* translators: %s: Theme name */
276                         $aria_label = sprintf( __( 'Install %s' ), '{{ data.name }}' );
277                         ?>
278                         <a class="button button-primary theme-install" data-name="{{ data.name }}" data-slug="{{ data.id }}" href="{{ data.install_url }}" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Install' ); ?></a>
279                         <button class="button preview install-theme-preview"><?php _e( 'Preview' ); ?></button>
280                 <# } #>
281         </div>
282
283         <# if ( data.installed ) { #>
284                 <div class="notice notice-success notice-alt"><p><?php _ex( 'Installed', 'theme' ); ?></p></div>
285         <# } #>
286 </script>
287
288 <script id="tmpl-theme-preview" type="text/template">
289         <div class="wp-full-overlay-sidebar">
290                 <div class="wp-full-overlay-header">
291                         <button class="close-full-overlay"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></button>
292                         <button class="previous-theme"><span class="screen-reader-text"><?php _ex( 'Previous', 'Button label for a theme' ); ?></span></button>
293                         <button class="next-theme"><span class="screen-reader-text"><?php _ex( 'Next', 'Button label for a theme' ); ?></span></button>
294                         <# if ( data.installed ) { #>
295                                 <a class="button button-primary activate" href="{{ data.activate_url }}"><?php _e( 'Activate' ); ?></a>
296                         <# } else { #>
297                                 <a href="{{ data.install_url }}" class="button button-primary theme-install" data-name="{{ data.name }}" data-slug="{{ data.id }}"><?php _e( 'Install' ); ?></a>
298                         <# } #>
299                 </div>
300                 <div class="wp-full-overlay-sidebar-content">
301                         <div class="install-theme-info">
302                                 <h3 class="theme-name">{{ data.name }}</h3>
303                                         <span class="theme-by">
304                                                 <?php
305                                                 /* translators: %s: Theme author name */
306                                                 printf( __( 'By %s' ), '{{ data.author }}' );
307                                                 ?>
308                                         </span>
309
310                                         <img class="theme-screenshot" src="{{ data.screenshot_url }}" alt="" />
311
312                                         <div class="theme-details">
313                                                 <# if ( data.rating ) { #>
314                                                         <div class="theme-rating">
315                                                                 {{{ data.stars }}}
316                                                                 <span class="num-ratings">({{ data.num_ratings }})</span>
317                                                         </div>
318                                                 <# } else { #>
319                                                         <span class="no-rating"><?php _e( 'This theme has not been rated yet.' ); ?></span>
320                                                 <# } #>
321                                                 <div class="theme-version">
322                                                         <?php
323                                                         /* translators: %s: Theme version */
324                                                         printf( __( 'Version: %s' ), '{{ data.version }}' );
325                                                         ?>
326                                                 </div>
327                                                 <div class="theme-description">{{{ data.description }}}</div>
328                                         </div>
329                                 </div>
330                         </div>
331                         <div class="wp-full-overlay-footer">
332                                 <button type="button" class="collapse-sidebar button" aria-expanded="true" aria-label="<?php esc_attr_e( 'Collapse Sidebar' ); ?>">
333                                         <span class="collapse-sidebar-arrow"></span>
334                                         <span class="collapse-sidebar-label"><?php _e( 'Collapse' ); ?></span>
335                                 </button>
336                         </div>
337                 </div>
338                 <div class="wp-full-overlay-main">
339                 <iframe src="{{ data.preview_url }}" title="<?php esc_attr_e( 'Preview' ); ?>"></iframe>
340         </div>
341 </script>
342
343 <?php
344 wp_print_request_filesystem_credentials_modal();
345 wp_print_admin_notice_templates();
346
347 include(ABSPATH . 'wp-admin/admin-footer.php');