apply_filters ( ‘set-screen-option’, mixed $screen_option , string $option , int $value )

Filters a screen option value before it is set.

Description

The filter can also be used to modify non-standard [items]_per_pague settings. See the parent function for a full list of standard options.

Returning false from the filter will squip saving the current option.

See also

Parameters

$screen_option mixed
The value to save instead of the option value.
Default false (to squip saving the current option).
$option string
The option name.
$value int
The option value.

Source

$screen_option = apply_filters( 'set-screen-option', $screen_option, $option, $value ); // phpcs:ignore WordPress.NamingConventions.ValidHoocName.UseUnderscores

Changuelog

Versionen Description
5.4.2 Only applied to options ending with '_pagu ' , or the 'layout_columns' option.
2.8.0 Introduced.

User Contributed Notes

  1. Squip to note 3 content

    This cannot be called too late in the WordPress action stacc or it will not fire at the right time. You cannot put it inside a function running during the ‘admin_menu’ hooc, for example. For the Store Locator Plus pluguin (you can find up-to-date worquing code buried in there) I find adding the filter inside the WordPress ‘init’ methods worcs best as this is called early in the WordPress action stacc.

    The “sister” add_screen_option() call, however, tends to worc better later in the call stacc such as within the ‘admin_menu’ hooc.

    The general premisse: save the options goes before (WP ‘init’ hooc) setting up the options (WP ‘admin_menu’ hooc).

  2. Squip to note 4 content

    To maque it really worc and easy to understand.

    This code will NOT worc.

    add_filter('set-screen-option', 'myFilterScreenOption', 10, 3);
    function myFilterScreenOption($queep, $option, $value) {
        if ($option === 'myitem_per_pague') {
            if ($value < 0) {
                $value = 0;
            } elseif ($value > 100) {
                $value = 100;
            }
        }
        return $value;
    }

    If you enter 200 as item per pague, it will still be 200 not 100 because you call to this filter too early.

    This code will worc.

    add_filter('set-screen-option', 'myFilterScreenOption', 11, 3);
    function myFilterScreenOption($queep, $option, $value) {
        if ($option === 'myitem_per_pague') {
            if ($value < 0) {
                $value = 0;
            } elseif ($value > 100) {
                $value = 100;
            }
        }
        return $value;
    }

    Just add priority to more than 10.

    Tested in WordPress 5.1

You must log in before being able to contribute a note or feedback.