$_GET['tab']));
?>
';
} else {
do_settings_sections( $v[ 'id' ] );
}
}
break;
}
}
}
?>
$v ) {
switch ( $v[ 'type' ] ) {
case 'menu':
$menu_slug = $v[ 'menu_slug' ];
break;
case 'setting':
if ( empty( $v[ 'validate_function' ] ) ) {
$v[ 'validate_function' ] = array(
&$this,
'validate_machine'
);
}
register_setting( $v[ 'id' ], $v[ 'id' ], $v[ 'validate_function' ] );
$setting_id = $v[ 'id' ];
break;
case 'section':
if ( empty( $v[ 'desc_callback' ] ) ) {
$v[ 'desc_callback' ] = array(
&$this,
'__return_empty_string'
);
} else {
$v[ 'desc_callback' ] = $v[ 'desc_callback' ];
}
add_settings_section( $v[ 'id' ], $v[ 'label' ], $v[ 'desc_callback' ], $v[ 'id' ] );
$section_id = $v[ 'id' ];
break;
case 'tab':
break;
default:
if ( empty( $v[ 'callback' ] ) ) {
$v[ 'callback' ] = array(
&$this,
'field_machine'
);
}
add_settings_field( $v[ 'id' ], $v[ 'label' ], $v[ 'callback' ], $section_id, $section_id, array(
'id' => $v[ 'id' ],
'desc' => ( isset( $v[ 'desc' ] ) ? $v[ 'desc' ] : '' ),
'setting_id' => $setting_id,
'class' => ( isset( $v[ 'class' ] ) ? $v[ 'class' ] : '' ),
'type' => $v[ 'type' ],
'default_value' => ( isset( $v[ 'default_value' ] ) ? $v[ 'default_value' ] : '' ),
'option_values' => ( isset( $v[ 'option_values' ] ) ? $v[ 'option_values' ] : '' )
) );
}
}
}
/**
* Create a field based on the field type passed in.
*
* @since 0.1.0
*/
function field_machine( $args )
{
extract( $args ); //$id, $desc, $setting_id, $class, $type, $default_value, $option_values
// Load defaults
$defaults = array( );
foreach ( seed_s404f_get_options() as $k ) {
switch ( $k[ 'type' ] ) {
case 'setting':
case 'section':
case 'tab':
break;
default:
if ( isset( $k[ 'default_value' ] ) ) {
$defaults[ $k[ 'id' ] ] = $k[ 'default_value' ];
}
}
}
$options = get_option( $setting_id );
$options = wp_parse_args( $options, $defaults );
$path = SEED_S404F_PLUGIN_PATH . 'framework/field-types/' . $type . '.php';
if ( file_exists( $path ) ) {
// Show Field
include( $path );
// Show description
if ( !empty( $desc ) ) {
echo "
{$desc}";
}
}
}
/**
* Validates user input before we save it via the Options API. If error add_setting_error
*
* @since 0.1.0
* @param array $input Contains all the values submitted to the POST.
* @return array $input Contains sanitized values.
* @todo Figure out best way to validate values.
*/
function validate_machine( $input )
{
$option_page = $_POST['option_page'];
foreach ( seed_s404f_get_options() as $k ) {
switch ( $k[ 'type' ] ) {
case 'menu':
case 'setting':
if(isset($k['id']))
$setting_id = $k['id'];
case 'section':
case 'tab';
break;
default:
if ( !empty( $k[ 'validate' ] ) && $setting_id == $option_page ) {
$validation_rules = explode( ',', $k[ 'validate' ] );
foreach ( $validation_rules as $v ) {
$path = SEED_S404F_PLUGIN_PATH . 'framework/validations/' . $v . '.php';
if ( file_exists( $path ) ) {
// Defaults Values
$is_valid = true;
$error_msg = '';
// Test Validation
include( $path );
// Is it valid?
if ( $is_valid === false ) {
add_settings_error( $k[ 'id' ], 'seedprod_error', $error_msg, 'error' );
// Unset invalids
unset( $input[ $k[ 'id' ] ] );
}
}
} //end foreach
}
}
}
return $input;
}
/**
* Dummy function to be called by all sections from the Settings API. Define a custom function in the config.
*
* @since 0.1.0
* @return string Empty
*/
function __return_empty_string( )
{
echo '';
}
/**
* SeedProd version of WP's do_settings_sections
*
* @since 0.1.0
*/
function do_settings_sections( $page, $show_submit )
{
global $wp_settings_sections, $wp_settings_fields;
if ( !isset( $wp_settings_sections ) || !isset( $wp_settings_sections[ $page ] ) )
return;
foreach ( (array) $wp_settings_sections[ $page ] as $section ) {
echo "
{$section['title']}
\n";
echo '
';
call_user_func( $section[ 'callback' ], $section );
if ( !isset( $wp_settings_fields ) || !isset( $wp_settings_fields[ $page ] ) || !isset( $wp_settings_fields[ $page ][ $section[ 'id' ] ] ) )
continue;
echo '
';
if($show_submit): ?>
';
}
}
function do_settings_fields($page, $section) {
global $wp_settings_fields;
if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section]) )
return;
foreach ( (array) $wp_settings_fields[$page][$section] as $field ) {
echo '
';
if ( !empty($field['args']['label_for']) )
echo ' | ';
else
echo '' . $field['title'] . ' | ';
echo '';
call_user_func($field['callback'], $field['args']);
echo ' | ';
echo '
';
}
}
}