Changeset 8802 for trunk/wp-admin/includes/misc.php
- Timestamp:
- 09/04/2008 01:11:18 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/misc.php
r8600 r8802 171 171 } 172 172 173 /* Whitelist functions */ 174 function register_setting($option_group, $option_name, $sanitize_callback = '') { 175 return add_option_update_handler($option_group, $option_name, $sanitize_callback); 176 } 177 178 function unregister_setting($option_group, $option_name, $sanitize_callback = '') { 179 return remove_option_update_handler($option_group, $option_name, $sanitize_callback); 180 } 181 182 function add_option_update_handler($option_group, $option_name, $sanitize_callback = '') { 183 global $new_whitelist_options; 184 $new_whitelist_options[ $option_group ][] = $option_name; 185 if ( $sanitize_callback != '' ) 186 add_filter( "sanitize_option_{$option_name}", $sanitize_callback ); 187 } 188 189 function remove_option_update_handler($option_group, $option_name, $sanitize_callback = '') { 190 global $new_whitelist_options; 191 $pos = array_search( $option_name, $new_whitelist_options ); 192 if ( $pos !== false ) 193 unset( $new_whitelist_options[ $option_group ][ $pos ] ); 194 if ( $sanitize_callback != '' ) 195 remove_filter( "sanitize_option_{$option_name}", $sanitize_callback ); 196 } 197 198 function option_update_filter( $options ) { 199 global $new_whitelist_options; 200 201 if ( is_array( $new_whitelist_options ) ) 202 $options = add_option_whitelist( $new_whitelist_options, $options ); 203 204 return $options; 205 } 206 add_filter( 'whitelist_options', 'option_update_filter' ); 207 208 function add_option_whitelist( $new_options, $options = '' ) { 209 if( $options == '' ) { 210 global $whitelist_options; 211 } else { 212 $whitelist_options = $options; 213 } 214 foreach( $new_options as $page => $keys ) { 215 foreach( $keys as $key ) { 216 $pos = array_search( $key, $whitelist_options[ $page ] ); 217 if( $pos === false ) 218 $whitelist_options[ $page ][] = $key; 219 } 220 } 221 return $whitelist_options; 222 } 223 224 function remove_option_whitelist( $del_options, $options = '' ) { 225 if( $options == '' ) { 226 global $whitelist_options; 227 } else { 228 $whitelist_options = $options; 229 } 230 foreach( $del_options as $page => $keys ) { 231 foreach( $keys as $key ) { 232 $pos = array_search( $key, $whitelist_options[ $page ] ); 233 if( $pos !== false ) 234 unset( $whitelist_options[ $page ][ $pos ] ); 235 } 236 } 237 return $whitelist_options; 238 } 239 173 240 ?>
Note: See TracChangeset
for help on using the changeset viewer.