Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( class_exists( 'RWMB_Field' ) ) {
- class RWMB_Jackky_Tinymce_Field extends RWMB_Field {
- /**
- * Get field HTML.
- *
- * @param mixed $meta Meta value.
- * @param array $field Field parameters.
- * @return string
- */
- public static function html( $meta, $field ) {
- // Using output buffering because wp_editor() echos directly.
- ob_start();
- $attributes = self::get_attributes( $field );
- $options = [
- 'editor_class' => 'jackky-tinymce rwmb-jackky-tinymce', // rwmb-jackky-tinymce class is for clone fix
- 'dfw' => true,
- ];
- $options['textarea_name'] = $field['field_name'];
- if ( ! empty( $attributes['required'] ) )
- {
- $options['editor_class'] .= ' jackky-tinymce-required';
- }
- $settings = json_encode( $field['settings'] );
- if ( isset($field['settings']['tinymce']) )
- {
- $options = array_merge( $options, $field['settings']['tinymce'] ); // a hotfix to load wp_editor more properly
- }
- wp_editor( $meta, $attributes['id'], $options );
- echo '<script class="jackky-tinymce-id" type="text/html" data-id="' . esc_attr( $attributes['id'] ) . '" data-settings=\'' . $settings . '\'></script>';
- return ob_get_clean();
- }
- /**
- * Escape meta for field output.
- *
- * @param mixed $meta Meta value.
- * @return mixed
- */
- public static function esc_meta( $meta ) {
- return $meta;
- }
- /**
- * Normalize parameters for field.
- *
- * @param array $field Field parameters.
- * @return array
- */
- public static function normalize( $field ) {
- $field = parent::normalize( $field );
- $field = wp_parse_args(
- $field,
- array(
- 'raw' => false,
- 'settings' => [],
- )
- );
- return $field;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement