field; $a = $this->parse_args( 'wysiwyg', array( 'id' => $this->_id(), 'value' => $field->escaped_value( 'stripslashes' ), 'desc' => $this->_desc( true ), 'options' => $field->options(), ) ); if ( ! $field->group ) { return $this->rendered( $this->get_wp_editor( $a ) . $a['desc'] ); } // wysiwyg fields in a group need some special handling. $field->add_js_dependencies( 'wp-util' ); $field->add_js_dependencies( 'cmb2-wysiwyg' ); // Hook in our template-output to the footer. add_action( is_admin() ? 'admin_footer' : 'wp_footer', array( $this, 'add_wysiwyg_template_for_group' ) ); return $this->rendered( sprintf( '
%s', parent::render( array( 'class' => 'cmb2_textarea cmb2-wysiwyg-placeholder', 'data-groupid' => $field->group->id(), 'data-iterator' => $field->group->index, 'data-fieldid' => $field->id( true ), 'desc' => '
' . $this->_desc( true ), ) ) ) ); } protected function get_wp_editor( $args ) { ob_start(); wp_editor( $args['value'], $args['id'], $args['options'] ); return ob_get_clean(); } public function add_wysiwyg_template_for_group() { $group_id = $this->field->group->id(); $field_id = $this->field->id( true ); $hash = $this->field->hash_id(); $options = $this->field->options(); $options['textarea_name'] = 'cmb2_n_' . $group_id . $field_id; // Initate the editor with special id/value/name so we can retrieve the options in JS. $editor = $this->get_wp_editor( array( 'value' => 'cmb2_v_' . $group_id . $field_id, 'id' => 'cmb2_i_' . $group_id . $field_id, 'options' => $options, ) ); // Then replace the special id/value/name with underscore placeholders. $editor = str_replace( array( 'cmb2_n_' . $group_id . $field_id, 'cmb2_v_' . $group_id . $field_id, 'cmb2_i_' . $group_id . $field_id, ), array( '{{ data.name }}', '{{{ data.value }}}', '{{ data.id }}', ), $editor ); // And put the editor instance in a JS template wrapper. echo ''; } }