Screen options: Improve the "Apply" button

Previously the button was output as a part of the per-page option rendering, inline with that input. While this was appropriate for core's usage, the `screen_settings` filter has allowed plugins to place additional items at the bottom of the panel, which a number take advantage of. This leads to confusing situations where plugins that don't save settings via Ajax either have to add their own button or piggyback onto the existing button, which doesn't make any sense in the flow of additional options. It also hinders core from adding any other options that need to be submitted.

Also, when the screen options panel is open, a submit button there is the primary action at that moment. The "Apply" button also does a full page load, which a primary button indicates better.

fixes #34295. see #22222, #23738.


git-svn-id: https://develop.svn.wordpress.org/trunk@35161 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Helen Hou-Sandi 2015-10-14 18:57:16 +00:00
parent 33a3d1bba8
commit c98ac461a9
2 changed files with 25 additions and 4 deletions

View File

@ -1629,6 +1629,11 @@ form.upgrade .hint {
margin-top: 10px;
}
.metabox-prefs .submit {
margin-top: 1em;
padding: 0;
}
/*------------------------------------------------------------------------------
6.2 - Help Menu
------------------------------------------------------------------------------*/

View File

@ -993,6 +993,21 @@ final class WP_Screen {
$this->render_per_page_options();
echo $this->_screen_settings;
/**
* Filter whether to show the Screen Options submit button.
*
* @since 4.4.0
*
* @param bool $show_button Whether to show Screen Options submit button.
* Default false.
* @param WP_Screen $this Current WP_Screen instance.
*/
$show_button = apply_filters( 'screen_options_show_submit', false, $this );
if ( $show_button ) {
submit_button( __( 'Apply' ), 'primary', 'screen-options-apply', true );
}
echo $form_end . $wrapper_end;
}
@ -1155,6 +1170,9 @@ final class WP_Screen {
$per_page = apply_filters( 'edit_posts_per_page', $per_page, $this->post_type );
}
// This needs a submit button
add_filter( 'screen_options_show_submit', '__return_true' );
?>
<fieldset class="screen-options">
<legend><?php _e( 'Pagination' ); ?></legend>
@ -1163,10 +1181,8 @@ final class WP_Screen {
<input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]"
id="<?php echo esc_attr( $option ); ?>" maxlength="3"
value="<?php echo esc_attr( $per_page ); ?>" />
<?php endif;
echo get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ); ?>
<input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $option ); ?>" />
<?php endif; ?>
<input type="hidden" name="wp_screen_options[option]" value="<?php echo esc_attr( $option ); ?>" />
</fieldset>
<?php
}