奇怪的问题:自定义wordpress小部件被混淆为文本小部件

时间:2013-08-22 02:57:27

标签: wordpress

Wordpress似乎让我的小部件与“文本小部件”混淆。

在我的小部件设置页面上,它显示为

About Author (the name of my widget)
Arbitrary text or HTML (the description of the text widget)

当我使用wordpress注册我的小部件时,它会删除“可用小部件”行中的所有小部件。

当我打开我的小部件进行编辑时,最终的textarea(称为about-author)填充了小部件设置页面的HTML

当我将内容添加到表单并单击“保存”时,表单将更改为文本窗口小部件的内容(我输入的内容均未保存,当我刷新页面时,窗口小部件将返回“可用窗口小部件”)

这是打开窗口小部件窗体时包含的html(粘贴时间太长): Weird HTML

这是我的小部件代码(在我的主题中的functions.php中):

class Ms_About_Author_Widget extends WP_Widget {

public function __construct() {
    parent::__construct('ms_about_author_widget', 'About Author',
            array(
                'classname' => 'ms_about_author_widget',
                'description' =>
                'A signature block containing your name and summary',
                ));

    // $this->widget_options['before_widget'] = sprintf($this->widget_options['before_title'],
    //  'authored-by', 'itemscope itemtype="http://schema.org/Person"');
}

public function widget($args, $instance) {
    echo $args['before_widget'];
    echo '<table>
                <tr>
                    <td class="author-image">
                        <img src="'.get_avatar('*my email*', 140).'"
                        width="70" height="70" itemprop="image">
                    </td>
                    <td class="author-bio">
                        <h3>Authored by <span itemprop="name">'.$instance['title'].'</span></h3><a href="https://twitter.com/'.$instance['twitter-name'].'" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false">Follow</a>
                        <p itemprop="description"><img src="'.get_avatar('*my email*', 140).'"
                        width="70" height="70">'.$instance['about-author'].'</p>
                    </td>
                </tr>
            </table>';
    echo $args['after_widget'];

}

public function form($instance) {
    echo '
    <p>
        <label for="'.$this->get_field_name('title').'">Name:</label>
        <input class="widefat" id="'.$this->get_field_id('title').'" name="'.$this->get_field_name('title').'" type="text" value="">
    </p>
    <p>
        <label for="'.$this->get_field_name('twitter-name').'">Twitter Handle:</label>
        <input class="widefat" id="'.$this->get_field_id('twitter-name').'" name="'.$this->get_field_name('twitter-name').'" type="text" value="">
    </p>
    <p>
        <label for="'.$this->get_field_name('about-author').'">About You:</label>
        <textarea class="widefat" id="'.$this->get_field_id('about-author').'" name="'.$this->get_field_name('about-author').'" value="">
    </p>';
}

public function update($new_instance, $old_instance) {
    $instance = array();

    $instance['title'] = (!empty($new_instance['title'] )) ? strip_tags($new_instance['title']) : '';
    $instance['twitter-name'] = (!empty($new_instance['twitter-name'] )) ? strip_tags($new_instance['twitter-name']) : '';
    $instance['about-author'] = (!empty($new_instance['about-author'] )) ? strip_tags($new_instance['about-author']) : '';

    return $instance;
}
}

 function ms_register_widgets() {
    register_widget('Ms_About_Author_Widget');
}

add_action('widgets_init', 'ms_register_widgets');

关于这是什么或如何解决它的任何想法?

1 个答案:

答案 0 :(得分:0)

/捂脸

.....

问题是未公开的</textarea> ...

只有在重写整件事后才发现。

相关问题