Created
August 28, 2012 12:38
-
-
Save tott/3497696 to your computer and use it in GitHub Desktop.
Easy Custom Fields Richtext area
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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