函数文档

wp_set_options_autoload()

💡 云策文档标注

概述

wp_set_options_autoload() 是一个 WordPress 函数,用于批量设置数据库中多个选项的自动加载值。它作为 wp_set_option_autoload_values() 的包装器,简化了操作。

关键要点

  • 函数用于设置多个选项的自动加载值,控制选项是否在 WordPress 启动时加载。
  • 接受两个参数:$options(选项名称数组,无需 SQL 转义)和 $autoload(布尔值,表示自动加载状态)。
  • 返回一个关联数组,键为提供的选项名,值为布尔值,指示是否成功更新了自动加载值。
  • 从 WordPress 6.7.0 开始,'yes' 和 'no' 字符串值已被弃用,建议使用布尔值 true 或 false。

代码示例

function wp_set_options_autoload( array $options, $autoload ) {
	return wp_set_option_autoload_values(
		array_fill_keys( $options, $autoload )
	);
}

注意事项

  • 参数 $options 应为选项名称数组,且无需进行 SQL 转义。
  • 参数 $autoload 接受布尔值,但为了向后兼容,也接受 'yes' 和 'no' 字符串,不过这些值已弃用。
  • 函数内部调用 wp_set_option_autoload_values() 实现功能,开发者可参考相关文档了解更多细节。

📄 原文内容

Sets the autoload value for multiple options in the database.

Description

This is a wrapper for wp_set_option_autoload_values(), which can be used to set different autoload values for each option at once.

See also

Parameters

$optionsstring[]required
List of option names. Expected to not be SQL-escaped.
$autoloadboolrequired
Autoload value to control whether to load the options when WordPress starts up.
For backward compatibility 'yes' and 'no' are also accepted, though using these values is deprecated.

Return

array Associative array of all provided $options as keys and boolean values for whether their autoload value was updated.

Source

function wp_set_options_autoload( array $options, $autoload ) {
	return wp_set_option_autoload_values(
		array_fill_keys( $options, $autoload )
	);
}

Changelog

Version Description
6.7.0 The autoload values 'yes' and 'no' are deprecated.
6.4.0 Introduced.