Tinymce is not working as it should be?

Viewed 55

I have made a custom widget and the widget form have the input field for title and a textarea for content. Every thing is working fine including saving the textarea information until I have tried to implement the TinyMCE instead of textarea.

What's the problem?

The problems are

  1. I tried to implement limited editor buttons like Bold, Italic, Bulleted List and Numbered List, and tried to increase the textarea row size both are not working

  2. If I write something in the WYSIWYG it does not save.

  3. After pressing the save button the editor start looking weared. Something like this:

enter image description here

  1. If I switch from Visual to text mode the buttons are not visible ( After saving or before saving the text mode is same ). Here is the screenshot:

enter image description here

Here is my widget form() code:

function form( $instance ) {

    $title = ( !empty($instance['title']) ? esc_attr( $instance['title'] ) : 'About Me Title' );

    $content = ( !empty($instance['content_text']) ? esc_attr( $instance['content_text'] ) : 'About Me Text' );

    #   T I T L E
    $output = "<p>";
    $output .= "<label for='" . esc_attr( $this->get_field_id('title') ) . "'>".esc_html__( 'Title', 'my_theme')."</label>";
    $output .= "<input type=\"text\" class=\"widefat\" id='". esc_attr( $this->get_field_id( 'title' ) ) ."' name='". esc_attr( $this->get_field_name('title') ) ."' value='".$title."'></p>";

    #   A B O U T    M E     T E X T
    $output .= "<p>";
    $output .= "<label for='" . esc_attr( $this->get_field_id('content_text') ) . "'>".esc_html__( 'What\'s About Me? ' , 'my_theme' )."</label>";
    ob_start();
    wp_editor( $content, esc_attr( $this->get_field_id('content_text') ) , array( 'media_buttons'  => false, 'editor_class' => 'widefat', 'textarea_rows' => 15, 'quicktags' => array('buttons' => 'bold,italic,strikethrough')) );
    $output .= ob_get_contents();
    ob_end_clean();
    $output .= "</p>";

    echo $output;
}

How can I solve these problems?

0 Answers
Related