PageRenderTime 27ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/theme-install.php

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