unregister_setting() - WordPress 函数参考中文文档

返回介绍

unregister_setting()

发布于 2017-09-11 字数3182 浏览 794 评论 0

unregister_setting( string $option_group,  string $option_name,  callable $deprecated = '' )

Unregister a setting.


描述


参数

$option_group

(string)
(Required)
The settings group name used during registration.

$option_name

(string)
(Required)
The name of the option to unregister.

$deprecated

(callable)
(Optional)
Deprecated.

Default value: ”


源代码

File: wp-includes/option.php

function unregister_setting( $option_group, $option_name, $deprecated = '' ) {
	global $new_whitelist_options, $wp_registered_settings;

	if ( 'misc' == $option_group ) {
		_deprecated_argument( __FUNCTION__, '3.0.0',
			/* translators: %s: misc */
			sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ),
				'misc'
			)
		);
		$option_group = 'general';
	}

	if ( 'privacy' == $option_group ) {
		_deprecated_argument( __FUNCTION__, '3.5.0',
			/* translators: %s: privacy */
			sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ),
				'privacy'
			)
		);
		$option_group = 'reading';
	}

	$pos = array_search( $option_name, (array) $new_whitelist_options[ $option_group ] );
	if ( $pos !== false ) {
		unset( $new_whitelist_options[ $option_group ][ $pos ] );
	}
	if ( '' !== $deprecated ) {
		_deprecated_argument( __FUNCTION__, '4.7.0',
			/* translators: 1: $sanitize_callback, 2: register_setting() */
			sprintf( __( '%1$s is deprecated. The callback from %2$s is used instead.' ),
				'<code>$sanitize_callback</code>',
				'<code>register_setting()</code>'
			)
		);
		remove_filter( "sanitize_option_{$option_name}", $deprecated );
	}

	if ( isset( $wp_registered_settings[ $option_name ] ) ) {
		// Remove the sanitize callback if one was set during registration.
		if ( ! empty( $wp_registered_settings[ $option_name ]['sanitize_callback'] ) ) {
			remove_filter( "sanitize_option_{$option_name}", $wp_registered_settings[ $option_name ]['sanitize_callback'] );
		}

		unset( $wp_registered_settings[ $option_name ] );
	}
}

更新日志

Version 描述
4.7.0 $sanitize_callback was deprecated. The callback from register_setting() is now used instead.
2.7.0 Introduced.

相关函数

Uses

  • wp-includes/l10n.php:
    __()
  • wp-includes/functions.php:
    _deprecated_argument()
  • wp-includes/plugin.php:
    remove_filter()

Used By

  • wp-admin/includes/deprecated.php:
    remove_option_update_handler()

User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!