]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/theme-install.php
WordPress 4.0
[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( __( 'You do not have sufficient permissions 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 $sections = array(
31         'featured' => __( 'Featured Themes' ),
32         'popular'  => __( 'Popular Themes' ),
33         'new'      => __( 'Newest Themes' ),
34 );
35
36 $installed_themes = search_theme_directories();
37 foreach ( $installed_themes as $k => $v ) {
38         if ( false !== strpos( $k, '/' ) ) {
39                 unset( $installed_themes[ $k ] );
40         }
41 }
42
43 wp_localize_script( 'theme', '_wpThemeSettings', array(
44         'themes'   => false,
45         'settings' => array(
46                 'isInstall'     => true,
47                 'canInstall'    => current_user_can( 'install_themes' ),
48                 'installURI'    => current_user_can( 'install_themes' ) ? self_admin_url( 'theme-install.php' ) : null,
49                 'adminUrl'      => parse_url( self_admin_url(), PHP_URL_PATH )
50         ),
51         'l10n' => array(
52                 'addNew' => __( 'Add New Theme' ),
53                 'search'  => __( 'Search Themes' ),
54                 'searchPlaceholder' => __( 'Search themes...' ), // placeholder (no ellipsis)
55                 'upload' => __( 'Upload Theme' ),
56                 'back'   => __( 'Back' ),
57                 '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>.' )
58         ),
59         'installedThemes' => array_keys( $installed_themes ),
60         'browse' => array(
61                 'sections' => $sections,
62         ),
63 ) );
64
65 wp_enqueue_script( 'theme' );
66
67 /**
68  * Fires before each of the tabs are rendered on the Install Themes page.
69  *
70  * The dynamic portion of the hook name, $tab, refers to the current
71  * theme install tab. Possible values are 'dashboard', 'search', 'upload',
72  * 'featured', 'new', or 'updated'.
73  *
74  * @since 2.8.0
75  */
76 if ( $tab ) {
77         do_action( "install_themes_pre_{$tab}" );
78 }
79
80 $help_overview =
81         '<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>' .
82         '<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, Popular, or Latest. When you find a theme you like, you can preview it or install it.') . '</p>' .
83         '<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>';
84
85 get_current_screen()->add_help_tab( array(
86         'id'      => 'overview',
87         'title'   => __('Overview'),
88         'content' => $help_overview
89 ) );
90
91 $help_installing =
92         '<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>' .
93         '<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>';
94
95 get_current_screen()->add_help_tab( array(
96         'id'      => 'installing',
97         'title'   => __('Previewing and Installing'),
98         'content' => $help_installing
99 ) );
100
101 get_current_screen()->set_help_sidebar(
102         '<p><strong>' . __('For more information:') . '</strong></p>' .
103         '<p>' . __('<a href="http://codex.wordpress.org/Using_Themes#Adding_New_Themes" target="_blank">Documentation on Adding New Themes</a>') . '</p>' .
104         '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
105 );
106
107 include(ABSPATH . 'wp-admin/admin-header.php');
108
109 ?>
110 <div class="wrap">
111         <h2><?php
112         echo esc_html( $title );
113
114         /**
115          * Filter the tabs shown on the Add Themes screen.
116          *
117          * This filter is for backwards compatibility only,
118          * for the suppression of the upload tab.
119          *
120          * @since 2.8.0
121          * @param array $tabs The tabs shown on the Add Themes screen. Default is 'upload'.
122          */
123         $tabs = apply_filters( 'install_themes_tabs', array( 'upload' => __( 'Upload Theme' ) ) );
124         if ( ! empty( $tabs['upload'] ) && current_user_can( 'upload_themes' ) ) {
125                 echo ' <a href="#" class="upload add-new-h2">' . __( 'Upload Theme' ) . '</a>';
126                 echo ' <a href="#" class="browse-themes add-new-h2">' . _x( 'Browse', 'themes' ) . '</a>';
127         }
128         ?></h2>
129
130         <div class="upload-theme">
131         <?php install_themes_upload(); ?>
132         </div>
133
134         <div class="wp-filter">
135                 <div class="filter-count">
136                         <span class="count theme-count"></span>
137                 </div>
138
139                 <ul class="filter-links">
140                         <li><a href="#" data-sort="featured"><?php _ex( 'Featured', 'themes' ); ?></a></li>
141                         <li><a href="#" data-sort="popular"><?php _ex( 'Popular', 'themes' ); ?></a></li>
142                         <li><a href="#" data-sort="new"><?php _ex( 'Latest', 'themes' ); ?></a></li>
143                 </ul>
144
145                 <a class="drawer-toggle" href="#"><?php _e( 'Feature Filter' ); ?></a>
146
147                 <div class="search-form"></div>
148
149                 <div class="filter-drawer">
150                         <div class="buttons">
151                                 <a class="apply-filters button button-secondary" href="#"><?php _e( 'Apply Filters' ); ?><span></span></a>
152                                 <a class="clear-filters button button-secondary" href="#"><?php _e( 'Clear' ); ?></a>
153                         </div>
154                 <?php
155                 $feature_list = get_theme_feature_list();
156                 foreach ( $feature_list as $feature_name => $features ) {
157                         if ( $feature_name === 'Features' || $feature_name === __( 'Features' ) ) { // hack hack hack
158                                 echo '<div class="filter-group wide">';
159                         } else {
160                                 echo '<div class="filter-group">';
161                         }
162                         $feature_name = esc_html( $feature_name );
163                         echo '<h4>' . $feature_name . '</h4>';
164                         echo '<ol class="feature-group">';
165                         foreach ( $features as $feature => $feature_name ) {
166                                 $feature = esc_attr( $feature );
167                                 echo '<li><input type="checkbox" id="filter-id-' . $feature . '" value="' . $feature . '" /> ';
168                                 echo '<label for="filter-id-' . $feature . '">' . $feature_name . '</label></li>';
169                         }
170                         echo '</ol>';
171                         echo '</div>';
172                 }
173                 ?>
174                         <div class="filtered-by">
175                                 <span><?php _e( 'Filtering by:' ); ?></span>
176                                 <div class="tags"></div>
177                                 <a href="#"><?php _e( 'Edit' ); ?></a>
178                         </div>
179                 </div>
180         </div>
181         <div class="theme-browser content-filterable"></div>
182         <div class="theme-install-overlay wp-full-overlay expanded"></div>
183
184         <p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p>
185         <span class="spinner"></span>
186
187         <br class="clear" />
188 <?php
189 /**
190  * Fires at the top of each of the tabs on the Install Themes page.
191  *
192  * The dynamic portion of the hook name, $tab, refers to the current
193  * theme install tab. Possible values are 'dashboard', 'search', 'upload',
194  * 'featured', 'new', or 'updated'.
195  *
196  * @since 2.8.0
197  *
198  * @param int $paged Number of the current page of results being viewed.
199  */
200 if ( $tab ) {
201         do_action( "install_themes_{$tab}", $paged );
202 }
203 ?>
204 </div>
205
206 <script id="tmpl-theme" type="text/template">
207         <# if ( data.screenshot_url ) { #>
208                 <div class="theme-screenshot">
209                         <img src="{{ data.screenshot_url }}" alt="" />
210                 </div>
211         <# } else { #>
212                 <div class="theme-screenshot blank"></div>
213         <# } #>
214         <span class="more-details"><?php _ex( 'Details &amp; Preview', 'theme' ); ?></span>
215         <div class="theme-author"><?php printf( __( 'By %s' ), '{{ data.author }}' ); ?></div>
216         <h3 class="theme-name">{{ data.name }}</h3>
217
218         <div class="theme-actions">
219                 <a class="button button-primary" href="{{ data.install_url }}"><?php esc_html_e( 'Install' ); ?></a>
220                 <a class="button button-secondary preview install-theme-preview" href="#"><?php esc_html_e( 'Preview' ); ?></a>
221         </div>
222
223         <# if ( data.installed ) { #>
224                 <div class="theme-installed"><?php _ex( 'Already Installed', 'theme' ); ?></div>
225         <# } #>
226 </script>
227
228 <script id="tmpl-theme-preview" type="text/template">
229         <div class="wp-full-overlay-sidebar">
230                 <div class="wp-full-overlay-header">
231                         <a href="#" class="close-full-overlay"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></a>
232                         <a href="#" class="previous-theme"><span class="screen-reader-text"><?php _ex( 'Previous', 'Button label for a theme' ); ?></span></a>
233                         <a href="#" class="next-theme"><span class="screen-reader-text"><?php _ex( 'Next', 'Button label for a theme' ); ?></span></a>
234                 <# if ( data.installed ) { #>
235                         <a href="#" class="button button-primary theme-install disabled"><?php _ex( 'Installed', 'theme' ); ?></a>
236                 <# } else { #>
237                         <a href="{{ data.install_url }}" class="button button-primary theme-install"><?php _e( 'Install' ); ?></a>
238                 <# } #>
239                 </div>
240                 <div class="wp-full-overlay-sidebar-content">
241                         <div class="install-theme-info">
242                                 <h3 class="theme-name">{{ data.name }}</h3>
243                                 <span class="theme-by"><?php printf( __( 'By %s' ), '{{ data.author }}' ); ?></span>
244
245                                 <img class="theme-screenshot" src="{{ data.screenshot_url }}" alt="" />
246
247                                 <div class="theme-details">
248                                         <div class="rating rating-{{ Math.round( data.rating / 10 ) * 10 }}">
249                                                 <span class="one"></span>
250                                                 <span class="two"></span>
251                                                 <span class="three"></span>
252                                                 <span class="four"></span>
253                                                 <span class="five"></span>
254                                         <# if ( data.num_ratings ) { #>
255                                                 <p class="ratings">{{ data.num_ratings }}</p>
256                                         <# } else { #>
257                                                 <p class="ratings"><?php _e( 'No ratings.' ); ?></p>
258                                         <# } #>
259                                         </div>
260                                         <div class="theme-version"><?php printf( __( 'Version: %s' ), '{{ data.version }}' ); ?></div>
261                                         <div class="theme-description">{{{ data.description }}}</div>
262                                 </div>
263                         </div>
264                 </div>
265                 <div class="wp-full-overlay-footer">
266                         <a href="#" class="collapse-sidebar" title="<?php esc_attr_e( 'Collapse Sidebar' ); ?>">
267                                 <span class="collapse-sidebar-label"><?php _e( 'Collapse' ); ?></span>
268                                 <span class="collapse-sidebar-arrow"></span>
269                         </a>
270                 </div>
271         </div>
272         <div class="wp-full-overlay-main">
273                 <iframe src="{{ data.preview_url }}" />
274         </div>
275 </script>
276
277 <?php
278 include(ABSPATH . 'wp-admin/admin-footer.php');