$setting )
$checked[$index] = checked( 1, $setting ? 1 : 0, false );
self::_fieldRenderer( 'checkbox', compact( 'id', 'name', 'values', 'checked', 'labels' ) );
}
static function radiobuttonRenderer( $args ) {
$setting = Blogfolio::config( $args['id'] );
$id = Blogfolio::options . '_' . $args['id'];
$name = Blogfolio::options . "[{$args['id']}]";
$values = self::_arrayWrap( $args['value'] );
$checked = array();
$labels = self::_arrayWrap( $args['label'] );
foreach( $values as $index => $value )
$checked[$index] = checked( $value, $setting, false );
self::_fieldRenderer( 'radiobutton', compact( 'id', 'name', 'values', 'checked', 'labels' ) );
}
static function validateFields( $fields ) {
$validated = array();
foreach( $fields as $field => $value ) {
if( ! $sanction = isset( self::$registeredfields[ $field ] ) ? self::$registeredfields[ $field ] : false )
continue;
switch( $sanction[ 'type' ] ) {
case 'checkbox' :
case 'radiobox' :
default :
if( is_scalar( $sanction[ 'value' ] ) && $value != $sanction[ 'value' ] )
add_settings_error( Blogfolio::options, 'invalid-value', "'{$sanction[ 'title' ]}' Invalid input" );
elseif( is_array( $sanction[ 'value' ] ) && array_diff( self::_arrayWrap( $value ), $sanction[ 'value' ] ) )
add_settings_error( Blogfolio::options, 'invalid-value', "'{$sanction[ 'title' ]}' Invalid input" );
else
$validated[ $field ] = $value;
}
}
return apply_filters( 'blogfolio_validate_fields', $validated, $fields );
}
private static function _addFieldFilter( $type, $id, $title, $value ) {
self::$registeredfields[ $id ] = compact( 'type', 'title', 'value' );
}
private static function _fieldRenderer( $type, $params ) {
BlogfolioTemplate::loadFragment( 'admin/optionsfield', $type, $params );
}
private static function _arrayWrap( $field ) {
return is_array( $field ) ? $field : array( $field );
}
}
?>