name = 'hyperlink';
$this->label = __( 'Hyperlink', 'cfs' );
}
function html( $field ) {
$field->value = array(
'url' => isset( $field->value['url'] ) ? $field->value['url'] : '',
'text' => isset( $field->value['text'] ) ? $field->value['text'] : '',
'class' => isset( $field->value['class'] ) ? $field->value['class'] : '',
'target' => isset( $field->value['target'] ) ? $field->value['target'] : '',
);
?>
|
|
create_field(array(
'type' => 'select',
'input_name' => "cfs[fields][$key][options][format]",
'options' => array(
'choices' => array(
'html' => __( 'HTML', 'cfs' ),
'php' => __( 'PHP Array', 'cfs' )
),
'force_single' => true,
),
'value' => $this->get_option( $field, 'format', 'html' ),
));
?>
|
$value[0]['url'],
'text' => $value[1]['text'],
'target' => $value[2]['target'],
);
}
return serialize( $value );
}
function prepare_value( $value, $field = null ) {
return unserialize( $value[0] );
}
function format_value_for_api( $value, $field = null ) {
$url = isset( $value['url'] ) ? $value['url'] : '';
$text = isset( $value['text'] ) ? $value['text'] : $value['url'];
$target = isset( $value['target'] ) ? $value['target'] : '';
$format = $this->get_option( $field, 'format', 'html' );
// target="none" (sometimes?) opens a new tab
if ( 'none' == $target ) {
$target = '';
}
// Return an HTML string
if ( 'html' == $format ) {
$output = '';
if ( ! empty( $url ) ) {
$output = '' . esc_html( $text ) . '';
}
}
// Return an associative array
elseif ( 'php' == $format ) {
$output = $value;
}
return $output;
}
}