Skip to content

Commit b8dea76

Browse files
committed
Administration: Add a new filter to extend set-screen-option.
Merges [47951] to the 5.4 branch. Props: xknown, SergeyBiryukov. git-svn-id: https://develop.svn.wordpress.org/branches/5.4@47957 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 404f397 commit b8dea76

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

Diff for: src/wp-admin/includes/misc.php

+30-7
Original file line numberDiff line numberDiff line change
@@ -686,23 +686,46 @@ function set_screen_options() {
686686
}
687687
break;
688688
default:
689+
if ( '_page' === substr( $option, -5 ) || 'layout_columns' === $option ) {
690+
/**
691+
* Filters a screen option value before it is set.
692+
*
693+
* The filter can also be used to modify non-standard [items]_per_page
694+
* settings. See the parent function for a full list of standard options.
695+
*
696+
* Returning false to the filter will skip saving the current option.
697+
*
698+
* @since 2.8.0
699+
* @since 5.4.2 Only applied to options ending with '_page',
700+
* or the 'layout_columns' option.
701+
*
702+
* @see set_screen_options()
703+
*
704+
* @param bool $keep Whether to save or skip saving the screen option value.
705+
* Default false.
706+
* @param string $option The option name.
707+
* @param int $value The number of rows to use.
708+
*/
709+
$value = apply_filters( 'set-screen-option', false, $option, $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
710+
}
711+
689712
/**
690713
* Filters a screen option value before it is set.
691714
*
692-
* The filter can also be used to modify non-standard [items]_per_page
693-
* settings. See the parent function for a full list of standard options.
715+
* The dynamic portion of the hook, `$option`, refers to the option name.
694716
*
695717
* Returning false to the filter will skip saving the current option.
696718
*
697-
* @since 2.8.0
719+
* @since 5.4.2
698720
*
699721
* @see set_screen_options()
700722
*
701-
* @param bool $keep Whether to save or skip saving the screen option value. Default false.
702-
* @param string $option The option name.
703-
* @param int $value The number of rows to use.
723+
* @param bool $keep Whether to save or skip saving the screen option value.
724+
* Default false.
725+
* @param string $option The option name.
726+
* @param int $value The number of rows to use.
704727
*/
705-
$value = apply_filters( 'set-screen-option', false, $option, $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
728+
$value = apply_filters( "set_screen_option_{$option}", false, $option, $value );
706729

707730
if ( false === $value ) {
708731
return;

0 commit comments

Comments
 (0)