From c98ac461a996e963a730aafbf268b734e22d161c Mon Sep 17 00:00:00 2001 From: Helen Hou-Sandi Date: Wed, 14 Oct 2015 18:57:16 +0000 Subject: [PATCH] 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 --- src/wp-admin/css/common.css | 5 +++++ src/wp-admin/includes/class-wp-screen.php | 24 +++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/css/common.css b/src/wp-admin/css/common.css index ea7211dbaa..5f03d8a381 100644 --- a/src/wp-admin/css/common.css +++ b/src/wp-admin/css/common.css @@ -1629,6 +1629,11 @@ form.upgrade .hint { margin-top: 10px; } +.metabox-prefs .submit { + margin-top: 1em; + padding: 0; +} + /*------------------------------------------------------------------------------ 6.2 - Help Menu ------------------------------------------------------------------------------*/ diff --git a/src/wp-admin/includes/class-wp-screen.php b/src/wp-admin/includes/class-wp-screen.php index 311bdd0b54..100fa132ed 100644 --- a/src/wp-admin/includes/class-wp-screen.php +++ b/src/wp-admin/includes/class-wp-screen.php @@ -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' ); + ?>
@@ -1163,10 +1181,8 @@ final class WP_Screen { - - + +