wp/wp-includes/customize/class-wp-customize-themes-section.php
changeset 7 cf61fcea0001
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
       
     1 <?php
       
     2 /**
       
     3  * Customize API: WP_Customize_Themes_Section class
       
     4  *
       
     5  * @package WordPress
       
     6  * @subpackage Customize
       
     7  * @since 4.4.0
       
     8  */
       
     9 
       
    10 /**
       
    11  * Customize Themes Section class.
       
    12  *
       
    13  * A UI container for theme controls, which are displayed within sections.
       
    14  *
       
    15  * @since 4.2.0
       
    16  *
       
    17  * @see WP_Customize_Section
       
    18  */
       
    19 class WP_Customize_Themes_Section extends WP_Customize_Section {
       
    20 
       
    21 	/**
       
    22 	 * Section type.
       
    23 	 *
       
    24 	 * @since 4.2.0
       
    25 	 * @var string
       
    26 	 */
       
    27 	public $type = 'themes';
       
    28 
       
    29 	/**
       
    30 	 * Theme section action.
       
    31 	 *
       
    32 	 * Defines the type of themes to load (installed, wporg, etc.).
       
    33 	 *
       
    34 	 * @since 4.9.0
       
    35 	 * @var string
       
    36 	 */
       
    37 	public $action = '';
       
    38 
       
    39 	/**
       
    40 	 * Theme section filter type.
       
    41 	 *
       
    42 	 * Determines whether filters are applied to loaded (local) themes or by initiating a new remote query (remote).
       
    43 	 * When filtering is local, the initial themes query is not paginated by default.
       
    44 	 *
       
    45 	 * @since 4.9.0
       
    46 	 * @var string
       
    47 	 */
       
    48 	public $filter_type = 'local';
       
    49 
       
    50 	/**
       
    51 	 * Get section parameters for JS.
       
    52 	 *
       
    53 	 * @since 4.9.0
       
    54 	 * @return array Exported parameters.
       
    55 	 */
       
    56 	public function json() {
       
    57 		$exported = parent::json();
       
    58 		$exported['action'] = $this->action;
       
    59 		$exported['filter_type'] = $this->filter_type;
       
    60 
       
    61 		return $exported;
       
    62 	}
       
    63 
       
    64 	/**
       
    65 	 * Render a themes section as a JS template.
       
    66 	 *
       
    67 	 * The template is only rendered by PHP once, so all actions are prepared at once on the server side.
       
    68 	 *
       
    69 	 * @since 4.9.0
       
    70 	 */
       
    71 	protected function render_template() {
       
    72 		?>
       
    73 		<li id="accordion-section-{{ data.id }}" class="theme-section">
       
    74 			<button type="button" class="customize-themes-section-title themes-section-{{ data.id }}">{{ data.title }}</button>
       
    75 			<?php if ( current_user_can( 'install_themes' ) || is_multisite() ) : // @todo: upload support ?>
       
    76 			<?php endif; ?>
       
    77 			<div class="customize-themes-section themes-section-{{ data.id }} control-section-content themes-php">
       
    78 				<div class="theme-overlay" tabindex="0" role="dialog" aria-label="<?php esc_attr_e( 'Theme Details' ); ?>"></div>
       
    79 				<div class="theme-browser rendered">
       
    80 					<div class="customize-preview-header themes-filter-bar">
       
    81 						<?php $this->filter_bar_content_template(); ?>
       
    82 					</div>
       
    83 					<?php $this->filter_drawer_content_template(); ?>
       
    84 					<div class="error unexpected-error" style="display: none; "><p><?php _e( '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>.' ); ?></p></div>
       
    85 					<ul class="themes">
       
    86 					</ul>
       
    87 					<p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p>
       
    88 					<p class="no-themes-local">
       
    89 						<?php
       
    90 						/* translators: %s: "Search WordPress.org themes" button */
       
    91 						printf( __( 'No themes found. Try a different search, or %s.' ),
       
    92 							sprintf( '<button type="button" class="button-link search-dotorg-themes">%s</button>', __( 'Search WordPress.org themes' ) )
       
    93 						);
       
    94 						?>
       
    95 					</p>
       
    96 					<p class="spinner"></p>
       
    97 				</div>
       
    98 			</div>
       
    99 		</li>
       
   100 		<?php
       
   101 	}
       
   102 
       
   103 	/**
       
   104 	 * Render the filter bar portion of a themes section as a JS template.
       
   105 	 *
       
   106 	 * The template is only rendered by PHP once, so all actions are prepared at once on the server side.
       
   107 	 * The filter bar container is rendered by @see `render_template()`.
       
   108 	 *
       
   109 	 * @since 4.9.0
       
   110 	 */
       
   111 	protected function filter_bar_content_template() {
       
   112 		?>
       
   113 		<button type="button" class="button button-primary customize-section-back customize-themes-mobile-back"><?php _e( 'Back to theme sources' ); ?></button>
       
   114 		<# if ( 'wporg' === data.action ) { #>
       
   115 			<div class="search-form">
       
   116 				<label for="wp-filter-search-input-{{ data.id }}" class="screen-reader-text"><?php _e( 'Search themes&hellip;' ); ?></label>
       
   117 				<input type="search" id="wp-filter-search-input-{{ data.id }}" placeholder="<?php esc_attr_e( 'Search themes&hellip;' ); ?>" aria-describedby="{{ data.id }}-live-search-desc" class="wp-filter-search">
       
   118 				<div class="search-icon" aria-hidden="true"></div>
       
   119 				<span id="{{ data.id }}-live-search-desc" class="screen-reader-text"><?php _e( 'The search results will be updated as you type.' ); ?></span>
       
   120 			</div>
       
   121 			<button type="button" class="button feature-filter-toggle">
       
   122 				<span class="filter-count-0"><?php _e( 'Filter themes' ); ?></span><span class="filter-count-filters">
       
   123 				<?php
       
   124 				/* translators: %s: number of filters selected. */
       
   125 				printf( __( 'Filter themes (%s)' ), '<span class="theme-filter-count">0</span>' );
       
   126 				?>
       
   127 				</span>
       
   128 			</button>
       
   129 		<# } else { #>
       
   130 			<div class="themes-filter-container">
       
   131 				<label for="{{ data.id }}-themes-filter" class="screen-reader-text"><?php _e( 'Search themes&hellip;' ); ?></label>
       
   132 				<input type="search" id="{{ data.id }}-themes-filter" placeholder="<?php esc_attr_e( 'Search themes&hellip;' ); ?>" aria-describedby="{{ data.id }}-live-search-desc" class="wp-filter-search wp-filter-search-themes" />
       
   133 				<div class="search-icon" aria-hidden="true"></div>
       
   134 				<span id="{{ data.id }}-live-search-desc" class="screen-reader-text"><?php _e( 'The search results will be updated as you type.' ); ?></span>
       
   135 			</div>
       
   136 		<# } #>
       
   137 		<div class="filter-themes-count">
       
   138 			<span class="themes-displayed">
       
   139 				<?php
       
   140 				/* translators: %s: number of themes displayed. */
       
   141 				echo sprintf( __( '%s themes' ), '<span class="theme-count">0</span>' );
       
   142 				?>
       
   143 			</span>
       
   144 		</div>
       
   145 		<?php
       
   146 	}
       
   147 
       
   148 	/**
       
   149 	 * Render the filter drawer portion of a themes section as a JS template.
       
   150 	 *
       
   151 	 * The filter bar container is rendered by @see `render_template()`.
       
   152 	 *
       
   153 	 * @since 4.9.0
       
   154 	 */
       
   155 	protected function filter_drawer_content_template() {
       
   156 		$feature_list = get_theme_feature_list( false ); // @todo: Use the .org API instead of the local core feature list. The .org API is currently outdated and will be reconciled when the .org themes directory is next redesigned.
       
   157 		?>
       
   158 		<# if ( 'wporg' === data.action ) { #>
       
   159 			<div class="filter-drawer filter-details">
       
   160 				<?php foreach ( $feature_list as $feature_name => $features ) : ?>
       
   161 					<fieldset class="filter-group">
       
   162 						<legend><?php echo esc_html( $feature_name ); ?></legend>
       
   163 						<div class="filter-group-feature">
       
   164 							<?php foreach ( $features as $feature => $feature_name ) : ?>
       
   165 								<input type="checkbox" id="filter-id-<?php echo esc_attr( $feature ); ?>" value="<?php echo esc_attr( $feature ); ?>" />
       
   166 								<label for="filter-id-<?php echo esc_attr( $feature ); ?>"><?php echo esc_html( $feature_name ); ?></label>
       
   167 							<?php endforeach; ?>
       
   168 						</div>
       
   169 					</fieldset>
       
   170 				<?php endforeach; ?>
       
   171 			</div>
       
   172 		<# } #>
       
   173 		<?php
       
   174 	}
       
   175 }