settings_sections[0]['option'];
?>
settings_sections as $section ) : ?>
settings_sections[0]['option'];
foreach ( $this->settings_sections as $section ) {
if ( $section['option'] == $active_tab ) {
if ( ! isset( $section['display'] ) || $section['display'] == true ) {
?>settings_sections = $sections;
}
/**
* Set fields
*
* @since 1.0.0
*/
function set_fields( $fields ) {
$this->settings_fields = $fields;
}
/**
* Register settings
*
* @since 1.0.0
*/
function register_settings() {
foreach ( $this->settings_sections as $section ) {
add_settings_section(
$section['id'],
$section['title'],
'', // description, leave empty
$section['page']
);
foreach ( $this->settings_fields[$section['id']] as $setting ) {
add_settings_field(
$setting['id'],
$setting['title'],
array( $this, 'display_field' ),
$section['page'],
$section['id'],
array( $setting, $section )
);
}
register_setting( $section['page'], $section['option'], array( $this, 'sanitize_input' ) );
}
}
/**
* Get the settings values
*
* @since 1.0.0
*/
function get_option( $option_id ) {
// all settings data
$fields = $this->settings_fields;
$sections = $this->settings_sections;
// get section ID
$section_id = false;
foreach ( $sections as $section ) {
if ( $section['option'] == $option_id ) {
$section_id = $section['id'];
}
}
// no section ID, go back
if ( ! $section_id ) {
return false;
}
// generate defaults
$defaults = array();
foreach ( $fields[$section_id] as $field ) {
if ( isset( $field['default'] ) ) {
$defaults[$field['id']] = $field['default'];
} else {
$defaults[$field['id']] = '';
}
}
// user defined
$user_defined = get_option( $option_id, array() );
// combine
$option = array_merge( $defaults, $user_defined );
// pass it back
return $option;
}
/**
* Display settings field
*
* @since 1.0.0
*/
function display_field( $data ) {
$setting = $data[0];
$section = $data[1];
switch ( $setting['type'] ) {
case 'text':
$this->display_field_text( $setting, $section );
break;
case 'textarea':
$this->display_field_textarea( $setting, $section );
break;
case 'select':
$this->display_field_select( $setting, $section );
break;
case 'checkbox':
$this->display_field_checkbox( $setting, $section );
break;
case 'radio':
$this->display_field_radio( $setting, $section );
break;
case 'number':
$this->display_field_number( $setting, $section );
break;
default:
# code...
break;
}
}
/**
* Display text field
*
* @since 1.0.0
*/
function display_field_text( $setting, $section ) {
$settings = $this->get_option( $section['option'] );
?>
[]' value=''>
get_option( $section['option'] );
?>
get_option( $section['option'] );
?>
get_option( $section['option'] );
?>
[]' value='yes'>
get_option( $section['option'] );
?>
$label ) : ?>
[]' value=''>
get_option( $section['option'] );
?>
[]' value=''>
$value ) {
if ( isset( $input[$key] ) ) {
$output[$key] = sanitize_text_field( $input[ $key ] );
}
}
// pass it back
return $output;
}
}
} // end if class About_Author_Box_Settings_API exists