Skip to content

Instantly share code, notes, and snippets.

@tott
Created August 28, 2012 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tott/3497696 to your computer and use it in GitHub Desktop.
Save tott/3497696 to your computer and use it in GitHub Desktop.
Easy Custom Fields Richtext area
if( !class_exists( 'Easy_CF_Field_RichText' )) {
class Easy_CF_Field_RichText extends Easy_CF_Field {
public function print_form() {
$class = ( empty( $this->_field_data['class'] ) ) ? $this->_field_data['id'] . '_class' : $this->_field_data['class'];
$input_class = ( empty( $this->_field_data['input_class'] ) ) ? $this->_field_data['id'] . '_input_class' : $this->_field_data['input_class'];
$id = ( empty( $this->_field_data['id'] ) ) ? $this->_field_data['id'] : $this->_field_data['id'];
$label = ( empty( $this->_field_data['label'] ) ) ? $this->_field_data['id'] : $this->_field_data['label'];
$value = $this->get();
$hint = ( empty( $this->_field_data['hint'] ) ) ? '' : '<p><em>' . $this->_field_data['hint'] . '</em></p>';
printf( '<p><label><strong>%s</strong></label></p>', $label );
wp_editor( $value, $id );
}
}
}
if ( !class_exists( "Easy_CF_Validator_Richtext" ) ) {
class Easy_CF_Validator_Richtext extends Easy_CF_Validator {
public function get( $value='' ) {
return base64_decode( $value );
}
public function set( $value='' ) {
$value = base64_encode( wp_filter_post_kses( trim( $value ) ) );
return $value;
}
public function validate( $value='' ) {
return true;
}
}
}
function create_custom_fields()
{
global $easy_cf;
$field_data = array (
'custom_field_properties' => array (
'fields' => array(
'richtext-example' => array(
'label' => 'Richtext',
'type' => 'richtext',
'validate' => 'richtext',
),
),
'title' => 'Custom Field Properties',
'context' => 'advanced',
'pages' => array( 'post' ),
),
);
$easy_cf = new Easy_CF( $field_data );
}
add_action( 'init', 'create_custom_fields' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment