settings ); // No need to initialize options since defaults are applied as needed return ( NULL!==$options[$option_string] ? $options[$option_string] : $this->set_default_option( $options, $option_string ) ); } /** * Simple function to array of all option settings * * @ Since 1.2.0 */ function get_all_options(){ $options = get_option( $this->settings ); $defaults = $this->option_defaults(); foreach( $defaults as $option_string => $details ){ if( NULL === $options[$option_string] ){ $options[$option_string] = $default_options[$option_string]['default']; } } //update_option( $this->settings, $options ); Unnecessary since options will soon be updated if this fuction was called return $options; } /** * Correctly set and save the option's default setting * * @ Since 1.2.0 */ function set_default_option( $options, $option_string ){ $default_options = $this->option_defaults(); if( NULL !== $default_options[$option_string] ){ $options[$option_string] = $default_options[$option_string]['default']; update_option( $this->settings, $options ); return $options[$option_string]; }else{ return NULL; } } /** * Create array of option names for a given tab * * @ Since 1.2.0 */ function get_options_by_tab( $tab = 'generator' ){ $default_options = $this->option_defaults(); $return = array(); foreach($default_options as $key => $val){ if( $val['tab'] == $tab ){ $return[$key] = $key; } } return $return; } /** * Create array of option names and current values for a given tab * * @ Since 1.2.0 */ function get_settings_by_tab( $tab = 'generator' ){ $current = $this->get_all_options(); $default_options = $this->option_defaults(); $return = array(); foreach($default_options as $key => $val){ if( $val['tab'] == $tab ){ $return[$key] = $current[$key]; } } return $return; } /** * Create array of positions for a given tab along with a list of settings for each position * * @ Since 1.2.0 */ function get_option_positions_by_tab( $tab = 'generator' ){ $positions = $this->option_positions(); $return = array(); if( NULL !== $positions[$tab] ){ $options = $this->get_options_by_tab( $tab ); $defaults = $this->option_defaults(); foreach($positions[$tab] as $pos => $title ){ $return[$pos]['title'] = $title; $return[$pos]['options'] = array(); } foreach($options as $name){ $pos = $defaults[$name]['position']; $return[ $pos ]['options'][] = $name; } } return $return; } /** * Create array of positions for each widget along with a list of settings for each position * * @ Since 1.2.0 */ function get_widget_options_by_position(){ $default_options = $this->option_defaults(); $positions = $this->widget_positions(); $return = array(); foreach($positions as $key => $val ){ $return[$key]['title'] = $val; $return[$key]['options'] = array(); } foreach($default_options as $key => $val){ if($val['widget']){ $return[ $val['position'] ]['options'][] = $key; } } return $return; } /** * Options Simple Update for Admin Page * * @since 1.2.0 * */ function SimpleUpdate( $currenttab, $newoptions, $oldoptions ){ $options = $this->option_defaults(); $bytab = $this->get_options_by_tab( $currenttab ); foreach( $bytab as $id){ $oldoptions[$id] = $this->MenuOptionsValidate( $newoptions[$id],$oldoptions[$id],$options[$id] ); } update_option( $this->settings, $oldoptions); return $oldoptions; } /** * Function for displaying forms in the widget page * * @since 1.0.0 * */ function MenuDisplayCallback($options,$option,$fieldname,$fieldid){ $default = $option['default']; $optionname = $option['name']; $optiontitle = $option['title']; $optiondescription = $option['description']; $fieldtype = $option['type']; $value = ( Null !== $options[$optionname] ? $options[$optionname] : $default ); // Output checkbox form field markup if ( 'checkbox' == $fieldtype ) { ?> /> value="" />
the Alpine PressWordPress.org.
| '; $this->MenuDisplayCallback($options,$option,$fieldname,$fieldid); echo ' |
| '; $this->AdminDisplayCallback($options,$option,$fieldname,$fieldid); echo ' |