Plugins: Use `install_plugins_upload` action to print the upload form.

Since [37221] the upload form is added to every plugin install screen via `install_plugins_upload()`. Previously the form was added through the `install_plugins_upload` (alias of `install_plugins_$tab`) action which allowed plugin authors to replace the form. This restores the previous behaviour.

* Add the form only to non-upload plugin install screens.
* Replace `install_plugins_upload()` with the `install_plugins_upload` and `install_plugins_pre_upload` actions.
* Remove `$upload_tab_class` and add a CSS class for the current tab to `.wrap`
* Adjust CSS selectors and toggle the whole container to support upload without an `upload-plugin` class.

Props DavidAnderson, ocean90.
Fixes #37495.

git-svn-id: https://develop.svn.wordpress.org/trunk@38172 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling 2016-07-31 18:10:45 +00:00
parent 76a5d17bf5
commit dbe140910b
4 changed files with 38 additions and 25 deletions

View File

@ -1026,11 +1026,11 @@ body.folded .theme-browser ~ .theme-overlay .theme-wrap {
}
.upload-view-toggle .browse,
.upload-view-toggle.upload-tab .upload {
.plugin-install-tab-upload .upload-view-toggle .upload {
display: none;
}
.upload-view-toggle.upload-tab .browse {
.plugin-install-tab-upload .upload-view-toggle .browse {
display: inline;
}
@ -1048,9 +1048,14 @@ body.folded .theme-browser ~ .theme-overlay .theme-wrap {
top: 10px;
}
.upload-plugin-wrap {
display: none;
}
.show-upload-view .upload-theme,
.show-upload-view .upload-plugin,
.upload-tab .upload-plugin {
.show-upload-view .upload-plugin-wrap,
.plugin-install-tab-upload .upload-plugin {
display: block;
}

View File

@ -70,6 +70,7 @@ add_filter( 'whitelist_options', 'option_update_filter' );
// Plugin Install hooks.
add_action( 'install_plugins_featured', 'install_dashboard' );
add_action( 'install_plugins_upload', 'install_plugins_upload' );
add_action( 'install_plugins_search', 'display_plugins_table' );
add_action( 'install_plugins_popular', 'display_plugins_table' );
add_action( 'install_plugins_recommended', 'display_plugins_table' );

View File

@ -12,7 +12,8 @@ jQuery( document ).ready( function( $ ) {
$tabbables,
$firstTabbable,
$lastTabbable,
uploadViewToggle = $( '.upload-view-toggle' ),
$uploadViewToggle = $( '.upload-view-toggle' ),
$wrap = $ ( '.wrap' ),
$body = $( document.body );
tb_position = function() {
@ -183,12 +184,12 @@ jQuery( document ).ready( function( $ ) {
* When a user presses the "Upload Plugin" button, show the upload form in place
* rather than sending them to the devoted upload plugin page.
* The `?tab=upload` page still exists for no-js support and for plugins that
* might access it directly (?). When we're in this page, let the link behave
* might access it directly. When we're in this page, let the link behave
* like a link. Otherwise we're in the normal plugin installer pages and the
* link should behave like a toggle button.
*/
if ( ! uploadViewToggle.hasClass( 'upload-tab' ) ) {
uploadViewToggle
if ( ! $wrap.hasClass( 'plugin-install-tab-upload' ) ) {
$uploadViewToggle
.attr({
role: 'button',
'aria-expanded': 'false'
@ -196,7 +197,7 @@ jQuery( document ).ready( function( $ ) {
.on( 'click', function( event ) {
event.preventDefault();
$body.toggleClass( 'show-upload-view' );
uploadViewToggle.attr( 'aria-expanded', $body.hasClass( 'show-upload-view' ) );
$uploadViewToggle.attr( 'aria-expanded', $body.hasClass( 'show-upload-view' ) );
});
}
});

View File

@ -66,6 +66,15 @@ wp_enqueue_script( 'updates' );
*/
do_action( "install_plugins_pre_$tab" );
/*
* Call the pre upload action on every non-upload plugin install screen
* because the form is always displayed on these screens.
*/
if ( 'upload' !== $tab ) {
/** This action is documented in wp-admin/plugin-install.php */
do_action( 'install_plugins_pre_upload' );
}
get_current_screen()->add_help_tab( array(
'id' => 'overview',
'title' => __('Overview'),
@ -101,22 +110,13 @@ get_current_screen()->set_screen_reader_content( array(
*/
include(ABSPATH . 'wp-admin/admin-header.php');
?>
<div class="wrap">
<div class="wrap <?php echo esc_attr( "plugin-install-tab-$tab" ); ?>">
<h1>
<?php
echo esc_html( $title );
if ( ! empty( $tabs['upload'] ) && current_user_can( 'upload_plugins' ) ) {
if ( $tab === 'upload' ) {
$href = self_admin_url( 'plugin-install.php' );
$upload_tab_class = ' upload-tab';
} else {
$href = self_admin_url( 'plugin-install.php?tab=upload' );
$upload_tab_class = '';
}
printf( ' <a href="%s" class="upload-view-toggle page-title-action%s"><span class="upload">%s</span><span class="browse">%s</span></a>',
$href,
$upload_tab_class,
printf( ' <a href="%s" class="upload-view-toggle page-title-action"><span class="upload">%s</span><span class="browse">%s</span></a>',
( 'upload' === $tab ) ? self_admin_url( 'plugin-install.php' ) : self_admin_url( 'plugin-install.php?tab=upload' ),
__( 'Upload Plugin' ),
__( 'Browse Plugins' )
);
@ -124,16 +124,22 @@ include(ABSPATH . 'wp-admin/admin-header.php');
?>
</h1>
<div class="upload-plugin-wrap<?php echo $upload_tab_class; ?>">
<?php
/*
* Output the upload plugin form on every plugin install screen, so it can be
* Output the upload plugin form on every non-upload plugin install screen, so it can be
* displayed via JavaScript rather then opening up the devoted upload plugin page.
*/
install_plugins_upload(); ?>
</div>
if ( $tab !== 'upload' ) {
?>
<div class="upload-plugin-wrap">
<?php
/** This action is documented in wp-admin/plugin-install.php */
do_action( 'install_plugins_upload' );
?>
</div>
<?php
}
<?php
if ( $tab !== 'upload' ) {
$wp_list_table->views();
echo '<br class="clear" />';