optionsframework_setdefaults

Adds default options to the database if they aren't already present.

Description

optionsframework_setdefaults(); 

May update this later to load only on plugin activation, or theme activation since most people won't be editing the options.php on a regular basis.

http://codex.wordpress.org/Function_Reference/add_option


Usage

  1. if ( !function_exists( 'optionsframework_setdefaults' ) ) { 
  2. require_once '/inc/options-framework.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = optionsframework_setdefaults(); 
  7.  

Defined (1)

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

/inc/options-framework.php  
  1. function optionsframework_setdefaults() { 
  2.  
  3. $optionsframework_settings = get_option( 'optionsframework' ); 
  4.  
  5. // Gets the unique option id 
  6. $option_name = $optionsframework_settings['id']; 
  7.  
  8. /**  
  9. * Each theme will hopefully have a unique id, and all of its options saved 
  10. * as a separate option set. We need to track all of these option sets so 
  11. * it can be easily deleted if someone wishes to remove the plugin and 
  12. * its associated data. No need to clutter the database.  
  13. */ 
  14.  
  15. if ( isset( $optionsframework_settings['knownoptions'] ) ) { 
  16. $knownoptions = $optionsframework_settings['knownoptions']; 
  17. if ( !in_array( $option_name, $knownoptions ) ) { 
  18. array_push( $knownoptions, $option_name ); 
  19. $optionsframework_settings['knownoptions'] = $knownoptions; 
  20. update_option( 'optionsframework', $optionsframework_settings ); 
  21. } else { 
  22. $newoptionname = array( $option_name ); 
  23. $optionsframework_settings['knownoptions'] = $newoptionname; 
  24. update_option( 'optionsframework', $optionsframework_settings ); 
  25.  
  26. // Gets the default options data from the array in options.php 
  27. $options =& _optionsframework_options(); 
  28.  
  29. // If the options haven't been added to the database yet, they are added now 
  30. $values = of_get_default_values(); 
  31.  
  32. if ( isset( $values ) ) { 
  33. add_option( $option_name, $values ); // Add option with default settings