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