Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/js/_enqueues/wp/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ themes.view.Installer = themes.view.Appearance.extend({
.removeClass( this.activeClass )
.removeAttr( 'aria-current' );

$( '[data-sort="' + sort + '"]' )
$( '[data-sort="' + $.escapeSelector( sort ) + '"]' )
.addClass( this.activeClass )
.attr( 'aria-current', 'page' );

Expand Down Expand Up @@ -2013,6 +2013,7 @@ themes.InstallerRouter = Backbone.Router.extend({
routes: {
'theme-install.php?theme=:slug': 'preview',
'theme-install.php?browse=:sort': 'sort',
'theme-install.php?tab=:sort': 'sort',
'theme-install.php?search=:query': 'search',
'theme-install.php': 'sort'
},
Expand All @@ -2036,10 +2037,12 @@ themes.InstallerRouter = Backbone.Router.extend({
themes.RunInstaller = {

init: function() {
var defaultTab = ( themes.data.settings && themes.data.settings.defaultTab ) || 'popular';

// Set up the view.
// Passes the default 'section' as an option.
this.view = new themes.view.Installer({
section: 'popular',
section: defaultTab,
SearchView: themes.view.InstallerSearch
});

Expand Down Expand Up @@ -2106,12 +2109,12 @@ themes.RunInstaller = {
/*
* Handles sorting / browsing routes.
* Also handles the root URL triggering a sort request
* for `popular`, the default view.
* for the default view.
*/
themes.router.on( 'route:sort', function( sort ) {
if ( ! sort ) {
sort = 'popular';
themes.router.navigate( themes.router.baseUrl( '?browse=popular' ), { replace: true } );
sort = ( themes.data.settings && themes.data.settings.defaultTab ) || 'popular';
themes.router.navigate( themes.router.baseUrl( themes.router.browsePath + sort ), { replace: true } );
}
self.view.sort( sort );

Expand Down
49 changes: 33 additions & 16 deletions src/wp-admin/theme-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require_once __DIR__ . '/admin.php';
require ABSPATH . 'wp-admin/includes/theme-install.php';

$tab = ! empty( $_REQUEST['tab'] ) ? sanitize_text_field( $_REQUEST['tab'] ) : '';
$tab = ! empty( $_REQUEST['tab'] ) ? sanitize_text_field( $_REQUEST['tab'] ) : ( ! empty( $_REQUEST['browse'] ) ? sanitize_text_field( $_REQUEST['browse'] ) : '' );

if ( ! current_user_can( 'install_themes' ) ) {
wp_die( __( 'Sorry, you are not allowed to install themes on this site.' ) );
Expand Down Expand Up @@ -42,6 +42,34 @@
}
}

$tabs = array(
'popular' => _x( 'Popular', 'themes' ),
'new' => _x( 'Latest', 'themes' ),
'block-themes' => _x( 'Block Themes', 'themes' ),
'favorites' => _x( 'Favorites', 'themes' ),
);

if ( current_user_can( 'upload_themes' ) ) {
/*
* No longer a real tab. Here for filter compatibility.
* Gets skipped in the filter links below.
*/
$tabs['upload'] = __( 'Upload Theme' );
}

/**
* Filters the tabs shown on the Add Themes screen.
*
* @since 2.8.0
*
* @param string[] $tabs Associative array of the tabs shown on the Add Themes screen. Default keys
* include 'popular', 'new', 'block-themes', 'favorites', and 'upload'.
*/
$tabs = apply_filters( 'install_themes_tabs', $tabs );

$browse_tabs = array_diff_key( $tabs, array( 'upload' => true ) );
$default_tab = ! empty( $browse_tabs ) ? (string) array_key_first( $browse_tabs ) : 'popular';

wp_localize_script(
'theme',
'_wpThemeSettings',
Expand All @@ -52,6 +80,7 @@
'canInstall' => current_user_can( 'install_themes' ),
'installURI' => current_user_can( 'install_themes' ) ? self_admin_url( 'theme-install.php' ) : null,
'adminUrl' => parse_url( self_admin_url(), PHP_URL_PATH ),
'defaultTab' => $default_tab,
),
'l10n' => array(
'addNew' => __( 'Add Theme' ),
Expand Down Expand Up @@ -166,17 +195,6 @@
<h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>

<?php

/**
* Filters the tabs shown on the Add Themes screen.
*
* This filter is for backward compatibility only, for the suppression of the upload tab.
*
* @since 2.8.0
*
* @param string[] $tabs Associative array of the tabs shown on the Add Themes screen. Default is 'upload'.
*/
$tabs = apply_filters( 'install_themes_tabs', array( 'upload' => __( 'Upload Theme' ) ) );
if ( ! empty( $tabs['upload'] ) && current_user_can( 'upload_themes' ) ) {
echo ' <button type="button" class="upload-view-toggle page-title-action hide-if-no-js" aria-expanded="false">' . __( 'Upload Theme' ) . '</button>';
}
Expand Down Expand Up @@ -210,10 +228,9 @@
</div>

<ul class="filter-links">
<li><a href="#" data-sort="popular"><?php _ex( 'Popular', 'themes' ); ?></a></li>
<li><a href="#" data-sort="new"><?php _ex( 'Latest', 'themes' ); ?></a></li>
<li><a href="#" data-sort="block-themes"><?php _ex( 'Block Themes', 'themes' ); ?></a></li>
<li><a href="#" data-sort="favorites"><?php _ex( 'Favorites', 'themes' ); ?></a></li>
<?php foreach ( (array) $browse_tabs as $action => $text ) : ?>
<li><a href="#" data-sort="<?php echo esc_attr( $action ); ?>"><?php echo esc_html( $text ); ?></a></li>
<?php endforeach; ?>
</ul>

<button type="button" class="button drawer-toggle" aria-expanded="false"><?php _e( 'Feature Filter' ); ?></button>
Expand Down
Loading
Loading