Make WordPress Core

Changeset 9249


Ignore:
Timestamp:
10/19/2008 11:35:09 PM (16 years ago)
Author:
ryan
Message:

Move whitelist functions to plugin.php. Add settings_fields().

Location:
trunk/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/misc.php

    r9053 r9249  
    239239}
    240240
    241 /* Whitelist functions */
    242 
    243 /**
    244  * {@internal Missing Short Description}}
    245  *
    246  * @since unknown
    247  *
    248  * @param unknown_type $option_group
    249  * @param unknown_type $option_name
    250  * @param unknown_type $sanitize_callback
    251  * @return unknown
    252  */
    253 function register_setting($option_group, $option_name, $sanitize_callback = '') {
    254     return add_option_update_handler($option_group, $option_name, $sanitize_callback);
    255 }
    256 
    257 /**
    258  * {@internal Missing Short Description}}
    259  *
    260  * @since unknown
    261  *
    262  * @param unknown_type $option_group
    263  * @param unknown_type $option_name
    264  * @param unknown_type $sanitize_callback
    265  * @return unknown
    266  */
    267 function unregister_setting($option_group, $option_name, $sanitize_callback = '') {
    268     return remove_option_update_handler($option_group, $option_name, $sanitize_callback);
    269 }
    270 
    271 /**
    272  * {@internal Missing Short Description}}
    273  *
    274  * @since unknown
    275  *
    276  * @param unknown_type $option_group
    277  * @param unknown_type $option_name
    278  * @param unknown_type $sanitize_callback
    279  */
    280 function add_option_update_handler($option_group, $option_name, $sanitize_callback = '') {
    281     global $new_whitelist_options;
    282     $new_whitelist_options[ $option_group ][] = $option_name;
    283     if ( $sanitize_callback != '' )
    284         add_filter( "sanitize_option_{$option_name}", $sanitize_callback );
    285 }
    286 
    287 /**
    288  * {@internal Missing Short Description}}
    289  *
    290  * @since unknown
    291  *
    292  * @param unknown_type $option_group
    293  * @param unknown_type $option_name
    294  * @param unknown_type $sanitize_callback
    295  */
    296 function remove_option_update_handler($option_group, $option_name, $sanitize_callback = '') {
    297     global $new_whitelist_options;
    298     $pos = array_search( $option_name, $new_whitelist_options );
    299     if ( $pos !== false )
    300         unset( $new_whitelist_options[ $option_group ][ $pos ] );
    301     if ( $sanitize_callback != '' )
    302         remove_filter( "sanitize_option_{$option_name}", $sanitize_callback );
    303 }
    304 
    305 /**
    306  * {@internal Missing Short Description}}
    307  *
    308  * @since unknown
    309  *
    310  * @param unknown_type $options
    311  * @return unknown
    312  */
    313 function option_update_filter( $options ) {
    314     global $new_whitelist_options;
    315 
    316     if ( is_array( $new_whitelist_options ) )
    317         $options = add_option_whitelist( $new_whitelist_options, $options );
    318 
    319     return $options;
    320 }
    321 add_filter( 'whitelist_options', 'option_update_filter' );
    322 
    323 /**
    324  * {@internal Missing Short Description}}
    325  *
    326  * @since unknown
    327  *
    328  * @param unknown_type $new_options
    329  * @param unknown_type $options
    330  * @return unknown
    331  */
    332 function add_option_whitelist( $new_options, $options = '' ) {
    333     if( $options == '' ) {
    334         global $whitelist_options;
    335     } else {
    336         $whitelist_options = $options;
    337     }
    338     foreach( $new_options as $page => $keys ) {
    339         foreach( $keys as $key ) {
    340             $pos = array_search( $key, $whitelist_options[ $page ] );
    341             if( $pos === false )
    342                 $whitelist_options[ $page ][] = $key;
    343         }
    344     }
    345     return $whitelist_options;
    346 }
    347 
    348 /**
    349  * {@internal Missing Short Description}}
    350  *
    351  * @since unknown
    352  *
    353  * @param unknown_type $del_options
    354  * @param unknown_type $options
    355  * @return unknown
    356  */
    357 function remove_option_whitelist( $del_options, $options = '' ) {
    358     if( $options == '' ) {
    359         global $whitelist_options;
    360     } else {
    361         $whitelist_options = $options;
    362     }
    363     foreach( $del_options as $page => $keys ) {
    364         foreach( $keys as $key ) {
    365             $pos = array_search( $key, $whitelist_options[ $page ] );
    366             if( $pos !== false )
    367                 unset( $whitelist_options[ $page ][ $pos ] );
    368         }
    369     }
    370     return $whitelist_options;
    371 }
    372 
    373241?>
  • trunk/wp-admin/includes/plugin.php

    r9182 r9249  
    798798}
    799799
     800/* Whitelist functions */
     801
     802/**
     803 * Register a setting and its sanitization callback
     804 *
     805 * @since 2.7.0
     806 *
     807 * @param string $option_group A settings group name.  Can be anything.
     808 * @param string $option_name The name of an option to sanitize and save.
     809 * @param unknown_type $sanitize_callback A callback function that sanitizes the option's value.
     810 * @return unknown
     811 */
     812function register_setting($option_group, $option_name, $sanitize_callback = '') {
     813    return add_option_update_handler($option_group, $option_name, $sanitize_callback);
     814}
     815
     816/**
     817 * Unregister a setting
     818 *
     819 * @since 2.7.0
     820 *
     821 * @param unknown_type $option_group
     822 * @param unknown_type $option_name
     823 * @param unknown_type $sanitize_callback
     824 * @return unknown
     825 */
     826function unregister_setting($option_group, $option_name, $sanitize_callback = '') {
     827    return remove_option_update_handler($option_group, $option_name, $sanitize_callback);
     828}
     829
     830/**
     831 * {@internal Missing Short Description}}
     832 *
     833 * @since unknown
     834 *
     835 * @param unknown_type $option_group
     836 * @param unknown_type $option_name
     837 * @param unknown_type $sanitize_callback
     838 */
     839function add_option_update_handler($option_group, $option_name, $sanitize_callback = '') {
     840    global $new_whitelist_options;
     841    $new_whitelist_options[ $option_group ][] = $option_name;
     842    if ( $sanitize_callback != '' )
     843        add_filter( "sanitize_option_{$option_name}", $sanitize_callback );
     844}
     845
     846/**
     847 * {@internal Missing Short Description}}
     848 *
     849 * @since unknown
     850 *
     851 * @param unknown_type $option_group
     852 * @param unknown_type $option_name
     853 * @param unknown_type $sanitize_callback
     854 */
     855function remove_option_update_handler($option_group, $option_name, $sanitize_callback = '') {
     856    global $new_whitelist_options;
     857    $pos = array_search( $option_name, $new_whitelist_options );
     858    if ( $pos !== false )
     859        unset( $new_whitelist_options[ $option_group ][ $pos ] );
     860    if ( $sanitize_callback != '' )
     861        remove_filter( "sanitize_option_{$option_name}", $sanitize_callback );
     862}
     863
     864/**
     865 * {@internal Missing Short Description}}
     866 *
     867 * @since unknown
     868 *
     869 * @param unknown_type $options
     870 * @return unknown
     871 */
     872function option_update_filter( $options ) {
     873    global $new_whitelist_options;
     874
     875    if ( is_array( $new_whitelist_options ) )
     876        $options = add_option_whitelist( $new_whitelist_options, $options );
     877
     878    return $options;
     879}
     880add_filter( 'whitelist_options', 'option_update_filter' );
     881
     882/**
     883 * {@internal Missing Short Description}}
     884 *
     885 * @since unknown
     886 *
     887 * @param unknown_type $new_options
     888 * @param unknown_type $options
     889 * @return unknown
     890 */
     891function add_option_whitelist( $new_options, $options = '' ) {
     892    if( $options == '' ) {
     893        global $whitelist_options;
     894    } else {
     895        $whitelist_options = $options;
     896    }
     897    foreach( $new_options as $page => $keys ) {
     898        foreach( $keys as $key ) {
     899            $pos = array_search( $key, $whitelist_options[ $page ] );
     900            if( $pos === false )
     901                $whitelist_options[ $page ][] = $key;
     902        }
     903    }
     904    return $whitelist_options;
     905}
     906
     907/**
     908 * {@internal Missing Short Description}}
     909 *
     910 * @since unknown
     911 *
     912 * @param unknown_type $del_options
     913 * @param unknown_type $options
     914 * @return unknown
     915 */
     916function remove_option_whitelist( $del_options, $options = '' ) {
     917    if( $options == '' ) {
     918        global $whitelist_options;
     919    } else {
     920        $whitelist_options = $options;
     921    }
     922    foreach( $del_options as $page => $keys ) {
     923        foreach( $keys as $key ) {
     924            $pos = array_search( $key, $whitelist_options[ $page ] );
     925            if( $pos !== false )
     926                unset( $whitelist_options[ $page ][ $pos ] );
     927        }
     928    }
     929    return $whitelist_options;
     930}
     931
     932/**
     933 * Output nonce, action, and option_page fields for a settings page.
     934 *
     935 * @since 2.7.0
     936 *
     937 * @param string $option_group A settings group name.  This should match the group name used in register_setting().
     938 */
     939function settings_fields($option_group) {
     940    echo "<input type='hidden' name='option_page' value='$option_group' />";
     941    echo '<input type="hidden" name="action" value="update" />';
     942    wp_nonce_field("$option_group-options");
     943}
     944
    800945?>
  • trunk/wp-admin/options-general.php

    r9233 r9249  
    5353
    5454<form method="post" action="options.php">
    55 <input type='hidden' name='option_page' value='general' />
    56 <input type="hidden" name="action" value="update" />
    57 <?php wp_nonce_field('general-options') ?>
     55<?php settings_fields('general'); ?>
    5856
    5957<p class="submit">
Note: See TracChangeset for help on using the changeset viewer.