unregister_setting

Unregister a setting.

Description

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

Parameters (3)

0. $option_group (string)
The settings group name used during registration.
1. $option_name (string)
The name of the option to unregister.
2. $deprecated — Optional. (string) => ''
The deprecated.

Usage

  1. if ( !function_exists( 'unregister_setting' ) ) { 
  2. require_once ABSPATH . WPINC . '/option.php'; 
  3.  
  4. // The settings group name used during registration. 
  5. $option_group = ''; 
  6.  
  7. // The name of the option to unregister. 
  8. $option_name = ''; 
  9.  
  10. // The deprecated. 
  11. $deprecated = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = unregister_setting($option_group, $option_name, $deprecated); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/option.php  
  1. function unregister_setting( $option_group, $option_name, $deprecated = '' ) { 
  2. global $new_whitelist_options, $wp_registered_settings; 
  3.  
  4. if ( 'misc' == $option_group ) { 
  5. _deprecated_argument( __FUNCTION__, '3.0.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); 
  6. $option_group = 'general'; 
  7.  
  8. if ( 'privacy' == $option_group ) { 
  9. _deprecated_argument( __FUNCTION__, '3.5.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) ); 
  10. $option_group = 'reading'; 
  11.  
  12. $pos = array_search( $option_name, (array) $new_whitelist_options[ $option_group ] ); 
  13. if ( $pos !== false ) { 
  14. unset( $new_whitelist_options[ $option_group ][ $pos ] ); 
  15. if ( '' !== $deprecated ) { 
  16. _deprecated_argument( __FUNCTION__, '4.7.0', __( '$sanitize_callback is deprecated. The callback from register_setting() is used instead.' ) ); 
  17. remove_filter( "sanitize_option_{$option_name}", $deprecated ); 
  18.  
  19. if ( isset( $wp_registered_settings[ $option_name ] ) ) { 
  20. // Remove the sanitize callback if one was set during registration. 
  21. if ( ! empty( $wp_registered_settings[ $option_name ]['sanitize_callback'] ) ) { 
  22. remove_filter( "sanitize_option_{$option_name}", $wp_registered_settings[ $option_name ]['sanitize_callback'] ); 
  23.  
  24. unset( $wp_registered_settings[ $option_name ] );