$value )
$checked[$index] = checked( in_array( $value, $settings ), true, false );
self::_fieldRenderer( 'checkbox', compact( 'id', 'name', 'values', 'checked', 'labels' ) );
}
// Renders a radiobox. More than one value should be provided as an option group.
static function radiobuttonRenderer( $args ) {
$setting = Blogfolio::config( $args[ 'id' ] );
$id = Blogfolio::options . '_' . $args[ 'id' ];
$name = Blogfolio::options . "[{$args[ 'id' ]}]";
$values = (array) $args[ 'value' ];
array_walk( $values, 'esc_attr' );
$checked = array();
$labels = (array) $args[ 'label' ];
foreach( $values as $index => $value )
$checked[$index] = checked( $value, $setting, false );
self::_fieldRenderer( 'radiobutton', compact( 'id', 'name', 'values', 'checked', 'labels' ) );
}
// Validates raw input from option submission.
static function validateFields( $fields ) {
$validated = array();
foreach( $fields as $field => $value ) {
$sanction = isset( self::$registeredfields[ $field ] ) ? self::$registeredfields[ $field ] : false;
if( ! $sanction )
continue;
$valid = true;
switch( $sanction[ 'type' ] ) {
case 'colorpicker' :
$value = sanitize_text_field( $value );
if( '' != $value && ! preg_match( '/^#([[:xdigit:]]{3}|[[:xdigit:]]{6})$/' , $value ) ) {
$valid = false;
add_settings_error( Blogfolio::options, 'invalid-value', "'{$sanction[ 'title' ]}' Not a hex value" );
}
break;
case 'checkbox' :
case 'radiobox' :
default :
if( is_scalar( $sanction[ 'value' ] ) && $value != $sanction[ 'value' ] ) {
$valid = false;
add_settings_error( Blogfolio::options, 'invalid-value', "'{$sanction[ 'title' ]}' Invalid input" );
}
elseif( is_array( $sanction[ 'value' ] ) && array_diff( (array) $value, $sanction[ 'value' ] ) ) {
$valid = false;
add_settings_error( Blogfolio::options, 'invalid-value', "'{$sanction[ 'title' ]}' Invalid input" );
}
}
if( $valid ) $validated[ $field ] = $value;
}
return apply_filters( 'blogfolio_validate_fields', $validated, $fields );
}
// Adds theme option to sanctioned list. Should be called when a field is added.
private static function _addFieldFilter( $type, $id, $title, $value ) {
self::$registeredfields[ $id ] = compact( 'type', 'title', 'value' );
}
// Delegates UI rendering to the template fragment loader.
private static function _fieldRenderer( $type, $params ) {
BlogfolioTemplate::loadFragment( 'admin/optionsfield', $type, $params );
}
}
?>