钩子文档

set_screen_option_{$option}

💡 云策文档标注

概述

set_screen_option_{$option} 是一个动态过滤器钩子,用于在设置屏幕选项值之前进行过滤。开发者可以通过此钩子修改或阻止选项的保存。

关键要点

  • 这是一个动态钩子,$option 部分对应选项名称,例如 set_screen_option_per_page。
  • 过滤器接收三个参数:$screen_option(要保存的值,默认为 false 以跳过保存)、$option(选项名称)和 $value(选项值)。
  • 从过滤器返回 false 可以跳过保存当前选项,用于自定义验证或阻止操作。
  • 相关函数 set_screen_options() 用于保存列表页面(如文章、页面、评论)的行数选项。
  • 该钩子自 WordPress 5.4.2 版本引入。

📄 原文内容

Filters a screen option value before it is set.

Description

The dynamic portion of the hook name, $option, refers to the option name.

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

See also

Parameters

$screen_optionmixed
The value to save instead of the option value.
Default false (to skip saving the current option).
$optionstring
The option name.
$valueint
The option value.

Source

$value = apply_filters( "set_screen_option_{$option}", $screen_option, $option, $value );

Changelog

Version Description
5.4.2 Introduced.