WordPress.org

Ready to get started?Download WordPress

Forums

wp_editor() in WordPress Text Widget without plugin (1 post)

  1. TrueFalse
    Member
    Posted 1 year ago #

    Hello.
    I'm used next code for create child class of WP_Widget_Text:

    function Custom_Widget_Text() {
      unregister_widget("WP_Widget_Text");
      register_widget("Custom_WP_Widget_Text");
    }
    add_action("widgets_init", "Custom_Widget_Text");
    
    class Custom_WP_Widget_Text extends WP_Widget_Text {
    
      function __construct() {
        $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML'));
        $control_ops = array('width' => 600, 'height' => 350);
        WP_Widget::__construct('text', __('Text'), $widget_ops, $control_ops);
      }
    
      function form( $instance ) {
        $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
        $title = strip_tags($instance['title']);
        $text = esc_textarea($instance['text']);
    ?>
        <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
        <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
    <?php
      $options = array(
        'media_buttons' => true,
        'textarea_name' => $this->get_field_name('text'),
        'textarea_rows' => '16',
        'tinymce' => true,
        'quicktags' => false
      );
      wp_editor($text, $this->get_field_id('text'), $options);
    ?>
        <p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked(isset($instance['filter']) ? $instance['filter'] : 0); ?> /> <label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p>
    <?php
      }
    
    }

    But i'm having 1 problem after saving text in standard mode:
    <img src="" alt="http://s58.radikal.ru/i162/1303/d3/087fb9daf9ed.png" />

    What me doing with WordPress Ajax?

Topic Closed

This topic has been closed to new replies.

About this Topic