theme-install.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. /**
  3. * WordPress Theme Installation Administration API
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. $themes_allowedtags = array(
  9. 'a' => array(
  10. 'href' => array(),
  11. 'title' => array(),
  12. 'target' => array(),
  13. ),
  14. 'abbr' => array( 'title' => array() ),
  15. 'acronym' => array( 'title' => array() ),
  16. 'code' => array(),
  17. 'pre' => array(),
  18. 'em' => array(),
  19. 'strong' => array(),
  20. 'div' => array(),
  21. 'p' => array(),
  22. 'ul' => array(),
  23. 'ol' => array(),
  24. 'li' => array(),
  25. 'h1' => array(),
  26. 'h2' => array(),
  27. 'h3' => array(),
  28. 'h4' => array(),
  29. 'h5' => array(),
  30. 'h6' => array(),
  31. 'img' => array(
  32. 'src' => array(),
  33. 'class' => array(),
  34. 'alt' => array(),
  35. ),
  36. );
  37. $theme_field_defaults = array(
  38. 'description' => true,
  39. 'sections' => false,
  40. 'tested' => true,
  41. 'requires' => true,
  42. 'rating' => true,
  43. 'downloaded' => true,
  44. 'downloadlink' => true,
  45. 'last_updated' => true,
  46. 'homepage' => true,
  47. 'tags' => true,
  48. 'num_ratings' => true,
  49. );
  50. /**
  51. * Retrieves the list of WordPress theme features (aka theme tags).
  52. *
  53. * @since 2.8.0
  54. *
  55. * @deprecated 3.1.0 Use get_theme_feature_list() instead.
  56. *
  57. * @return array
  58. */
  59. function install_themes_feature_list() {
  60. _deprecated_function( __FUNCTION__, '3.1.0', 'get_theme_feature_list()' );
  61. $cache = get_transient( 'wporg_theme_feature_list' );
  62. if ( ! $cache ) {
  63. set_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS );
  64. }
  65. if ( $cache ) {
  66. return $cache;
  67. }
  68. $feature_list = themes_api( 'feature_list', array() );
  69. if ( is_wp_error( $feature_list ) ) {
  70. return array();
  71. }
  72. set_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS );
  73. return $feature_list;
  74. }
  75. /**
  76. * Displays search form for searching themes.
  77. *
  78. * @since 2.8.0
  79. *
  80. * @param bool $type_selector
  81. */
  82. function install_theme_search_form( $type_selector = true ) {
  83. $type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
  84. $term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : '';
  85. if ( ! $type_selector ) {
  86. echo '<p class="install-help">' . __( 'Search for themes by keyword.' ) . '</p>';
  87. }
  88. ?>
  89. <form id="search-themes" method="get">
  90. <input type="hidden" name="tab" value="search" />
  91. <?php if ( $type_selector ) : ?>
  92. <label class="screen-reader-text" for="typeselector"><?php _e( 'Type of search' ); ?></label>
  93. <select name="type" id="typeselector">
  94. <option value="term" <?php selected( 'term', $type ); ?>><?php _e( 'Keyword' ); ?></option>
  95. <option value="author" <?php selected( 'author', $type ); ?>><?php _e( 'Author' ); ?></option>
  96. <option value="tag" <?php selected( 'tag', $type ); ?>><?php _ex( 'Tag', 'Theme Installer' ); ?></option>
  97. </select>
  98. <label class="screen-reader-text" for="s">
  99. <?php
  100. switch ( $type ) {
  101. case 'term':
  102. _e( 'Search by keyword' );
  103. break;
  104. case 'author':
  105. _e( 'Search by author' );
  106. break;
  107. case 'tag':
  108. _e( 'Search by tag' );
  109. break;
  110. }
  111. ?>
  112. </label>
  113. <?php else : ?>
  114. <label class="screen-reader-text" for="s"><?php _e( 'Search by keyword' ); ?></label>
  115. <?php endif; ?>
  116. <input type="search" name="s" id="s" size="30" value="<?php echo esc_attr( $term ); ?>" autofocus="autofocus" />
  117. <?php submit_button( __( 'Search' ), '', 'search', false ); ?>
  118. </form>
  119. <?php
  120. }
  121. /**
  122. * Displays tags filter for themes.
  123. *
  124. * @since 2.8.0
  125. */
  126. function install_themes_dashboard() {
  127. install_theme_search_form( false );
  128. ?>
  129. <h4><?php _e( 'Feature Filter' ); ?></h4>
  130. <p class="install-help"><?php _e( 'Find a theme based on specific features.' ); ?></p>
  131. <form method="get">
  132. <input type="hidden" name="tab" value="search" />
  133. <?php
  134. $feature_list = get_theme_feature_list();
  135. echo '<div class="feature-filter">';
  136. foreach ( (array) $feature_list as $feature_name => $features ) {
  137. $feature_name = esc_html( $feature_name );
  138. echo '<div class="feature-name">' . $feature_name . '</div>';
  139. echo '<ol class="feature-group">';
  140. foreach ( $features as $feature => $feature_name ) {
  141. $feature_name = esc_html( $feature_name );
  142. $feature = esc_attr( $feature );
  143. ?>
  144. <li>
  145. <input type="checkbox" name="features[]" id="feature-id-<?php echo $feature; ?>" value="<?php echo $feature; ?>" />
  146. <label for="feature-id-<?php echo $feature; ?>"><?php echo $feature_name; ?></label>
  147. </li>
  148. <?php } ?>
  149. </ol>
  150. <br class="clear" />
  151. <?php
  152. }
  153. ?>
  154. </div>
  155. <br class="clear" />
  156. <?php submit_button( __( 'Find Themes' ), '', 'search' ); ?>
  157. </form>
  158. <?php
  159. }
  160. /**
  161. * Displays a form to upload themes from zip files.
  162. *
  163. * @since 2.8.0
  164. */
  165. function install_themes_upload() {
  166. ?>
  167. <p class="install-help"><?php _e( 'If you have a theme in a .zip format, you may install or update it by uploading it here.' ); ?></p>
  168. <form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo esc_url( self_admin_url( 'update.php?action=upload-theme' ) ); ?>">
  169. <?php wp_nonce_field( 'theme-upload' ); ?>
  170. <label class="screen-reader-text" for="themezip"><?php _e( 'Theme zip file' ); ?></label>
  171. <input type="file" id="themezip" name="themezip" accept=".zip" />
  172. <?php submit_button( __( 'Install Now' ), '', 'install-theme-submit', false ); ?>
  173. </form>
  174. <?php
  175. }
  176. /**
  177. * Prints a theme on the Install Themes pages.
  178. *
  179. * @deprecated 3.4.0
  180. *
  181. * @global WP_Theme_Install_List_Table $wp_list_table
  182. *
  183. * @param object $theme
  184. */
  185. function display_theme( $theme ) {
  186. _deprecated_function( __FUNCTION__, '3.4.0' );
  187. global $wp_list_table;
  188. if ( ! isset( $wp_list_table ) ) {
  189. $wp_list_table = _get_list_table( 'WP_Theme_Install_List_Table' );
  190. }
  191. $wp_list_table->prepare_items();
  192. $wp_list_table->single_row( $theme );
  193. }
  194. /**
  195. * Displays theme content based on theme list.
  196. *
  197. * @since 2.8.0
  198. *
  199. * @global WP_Theme_Install_List_Table $wp_list_table
  200. */
  201. function display_themes() {
  202. global $wp_list_table;
  203. if ( ! isset( $wp_list_table ) ) {
  204. $wp_list_table = _get_list_table( 'WP_Theme_Install_List_Table' );
  205. }
  206. $wp_list_table->prepare_items();
  207. $wp_list_table->display();
  208. }
  209. /**
  210. * Displays theme information in dialog box form.
  211. *
  212. * @since 2.8.0
  213. *
  214. * @global WP_Theme_Install_List_Table $wp_list_table
  215. */
  216. function install_theme_information() {
  217. global $wp_list_table;
  218. $theme = themes_api( 'theme_information', array( 'slug' => wp_unslash( $_REQUEST['theme'] ) ) );
  219. if ( is_wp_error( $theme ) ) {
  220. wp_die( $theme );
  221. }
  222. iframe_header( __( 'Theme Installation' ) );
  223. if ( ! isset( $wp_list_table ) ) {
  224. $wp_list_table = _get_list_table( 'WP_Theme_Install_List_Table' );
  225. }
  226. $wp_list_table->theme_installer_single( $theme );
  227. iframe_footer();
  228. exit;
  229. }