WordPress PHP Cross Reference Web Logs

Source: /wp-admin/includes/theme-install.php - 192 lines - 6007 bytes - Summary - Text - Print

Description: WordPress Theme Install Administration API

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

title

Description

title

Description

title

Description

title

title

Body