WordPress.org

Make WordPress Core

Ticket #18914: plugin.php.diff

File plugin.php.diff, 1.2 KB (added by sirzooro, 10 years ago)

register_setting() with extra param

  • plugin.php

    old new  
    15931593 *      Default whitelisted option key names include "general," "discussion," and "reading," among others.
    15941594 * @param string $option_name The name of an option to sanitize and save.
    15951595 * @param unknown_type $sanitize_callback A callback function that sanitizes the option's value.
     1596 * @param bool $pass_option_name Set to true to pass option name when filter is called. Default false.
    15961597 * @return unknown
    15971598 */
    1598 function register_setting( $option_group, $option_name, $sanitize_callback = '' ) {
     1599function register_setting( $option_group, $option_name, $sanitize_callback = '', $pass_option_name = false ) {
    15991600        global $new_whitelist_options;
    16001601
    16011602        if ( 'misc' == $option_group ) {
     
    16041605        }
    16051606
    16061607        $new_whitelist_options[ $option_group ][] = $option_name;
    1607         if ( $sanitize_callback != '' )
    1608                 add_filter( "sanitize_option_{$option_name}", $sanitize_callback, 10, 2 );
     1608        if ( $sanitize_callback != '' ) {
     1609                if ( $pass_option_name ) {
     1610                        add_filter( "sanitize_option_{$option_name}", $sanitize_callback, 10, 2 );
     1611                } else {
     1612                        add_filter( "sanitize_option_{$option_name}", $sanitize_callback );
     1613                }
     1614        }
    16091615}
    16101616
    16111617/**