【问题标题】:Weird issue: Custom wordpress widget being confused as text widget奇怪的问题:自定义 wordpress 小部件被混淆为文本小部件
【发布时间】:2013-08-24 14:59:30
【问题描述】:

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

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

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

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

当我打开小部件进行编辑时,最终的文本区域(称为 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');

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

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    /掌心

    .....

    问题是一个未关闭的&lt;/textarea&gt;...

    全部重写后才发现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-05
      • 1970-01-01
      • 2012-02-17
      • 2019-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多