Make WordPress Core

Ticket #37245: 37245.diff

File 37245.diff, 1.8 KB (added by Howdy_McGee, 4 years ago)

Provides 2 new action hooks: register_setting and unregister_setting both fire near the end of the function process.

  • wp-includes/option.php

     
    21142114 * }
    21152115 */
    21162116function register_setting( $option_group, $option_name, $args = array() ) {
     2117       
    21172118        global $new_whitelist_options, $wp_registered_settings;
    21182119
    21192120        $defaults = array(
     
    21862187        if ( array_key_exists( 'default', $args ) ) {
    21872188                add_filter( "default_option_{$option_name}", 'filter_default_option', 10, 3 );
    21882189        }
    2189 
     2190       
     2191        /**
     2192         * Fires immediately before setting arguments are added but after filters are in place.
     2193         *
     2194         * @param string $option_name  Name of the option.
     2195         * @param string $option_group Option group name.
     2196         * @param array  $args         Array of settings arguments.
     2197         */
     2198        do_action( 'register_setting', $option_name, $option_group, $args );
     2199       
    21902200        $wp_registered_settings[ $option_name ] = $args;
    21912201}
    21922202
     
    22512261        }
    22522262
    22532263        if ( isset( $wp_registered_settings[ $option_name ] ) ) {
     2264               
    22542265                // Remove the sanitize callback if one was set during registration.
    22552266                if ( ! empty( $wp_registered_settings[ $option_name ]['sanitize_callback'] ) ) {
    22562267                        remove_filter( "sanitize_option_{$option_name}", $wp_registered_settings[ $option_name ]['sanitize_callback'] );
     
    22602271                if ( array_key_exists( 'default', $wp_registered_settings[ $option_name ] ) ) {
    22612272                        remove_filter( "default_option_{$option_name}", 'filter_default_option', 10 );
    22622273                }
    2263 
     2274               
     2275                /**
     2276                 * Fires immediately before unsetting a specific settings and after filters have been removed.
     2277                 *
     2278                 * @param string $option_name  Name of the option.
     2279                 * @param string $option_group Option group name.
     2280                 */
     2281                do_action( 'unregister_setting', $option_name, $option_group );
     2282               
    22642283                unset( $wp_registered_settings[ $option_name ] );
    22652284        }
    22662285}