PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/theme-install.php

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