A WordPress-centric search engine for devs and theme authors



unregister_setting ›

Since2.7.0
Deprecatedn/a
unregister_setting ( $option_group, $option_name, $deprecated = '' )
Parameters: (3)
  • (string) $option_group The settings group name used during registration.
    Required: Yes
  • (string) $option_name The name of the option to unregister.
    Required: Yes
  • (callable) $deprecated Deprecated.
    Required: No
    Default: (empty)
Defined at:
Codex:
Change Log:
  • 4.7.0

Unregister a setting.



Source

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'] );
		}

		// Remove the default filter if a default was provided during registration.
		if ( array_key_exists( 'default', $wp_registered_settings[ $option_name ] ) ) {
			remove_filter( "default_option_{$option_name}", 'filter_default_option', 10 );
		}

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