【问题标题】:WordPress - TinyMCE disappears on widget saveWordPress - TinyMCE 在小部件保存时消失
【发布时间】:2014-03-17 17:34:44
【问题描述】:

我想在 WordPress 中创建一个自定义小部件。为了更好的用户体验,我想在小部件中插入一个最小的 TinyMCE WYSIWYG 编辑器。

我的问题

我已经将 WYSIWYG 与 wp_editor() 函数集成,但是当我输入一个值并点击保存按钮时,按钮消失并且文本为白色(但仍然存在)。

在 firebug 中,列出了以下错误:

  1. D.hasChildNodes 不是函数(editor-template.js,第 1 行)

  2. NS_ERROR_UNEXPECTED:(tiny_mce.js,第 1 行)

这是我目前得到的代码:

我的密码

表格功能:

public function form( $instance ) {
    //$pages = 

    $settings = array( 
        'media_buttons' => false,
        'tinymce' => array(
            'theme_advanced_buttons1' => 'bold,italic,underline',
            'theme_advanced_buttons2' => '',
            'theme_advanced_buttons3' => ''
        ),
        'textarea_name' => $this->get_field_name( 'description' )
    );

    if ( $instance ) {
        $title = $instance[ 'title' ];
        $page = $instance['page'];
        $description = $instance['description'];
        $image_uri = $instance['image_uri'];
    } else {
        $title = __( 'New title', 'wpb_widget_domain' );
        $page = __( 'New Page', 'wpb_widget_domain' );
        $image_uri = __( 'New Image', 'wpb_widget_domain' );
        $description = __( 'New Description', 'wpb_widget_domain' );
    }
?>
[some code that doesn't matter]
<p>
<label for="<?php echo $this->get_field_id( 'description' ); ?>"><?php _e( 'Description:' ); ?></label><br />
<?php wp_editor( $description, $this->get_field_id( 'description' ), $settings ) ?>
</p>
[some code that doesn't matter]

<?php 
}

更新函数:

public function update( $new_instance, $old_instance ) {
    var_dump($new_instance);
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
    $instance['page'] = ( ! empty( $new_instance['page'] ) ) ? strip_tags( $new_instance['page'] ) : '';
    $instance['image_uri'] = ( ! empty( $new_instance['image_uri'] ) ) ? strip_tags( $new_instance['image_uri'] ) : '';
    $instance['description'] = ( ! empty( $new_instance['description'] ) ) ? strip_tags( $new_instance['description'] ) : '';

    return $instance;
}

另一件可能很重要的事情: 当我转储 $_POST 时,描述字段的值不会更新。

有人吗?

提前致谢。 HS。

【问题讨论】:

  • 您在描述字段中调用 tinymce 按钮对吗?为什么要剥离 textarea 的标签? strip_tags( $new_instance['description'] ) 你可以尝试从这一行中删除 strip_tags 吗?

标签: jquery wordpress widget tinymce wysiwyg


【解决方案1】:

我认为这是在调用编辑器上的方法remove() 时发生的tinymce 核心错误。您使用的是哪个 tinymce 版本?

【讨论】:

  • 我使用的是 WordPress TinyMCE Advanced 插件,版本为 3.5.9.1
  • 好的,在这种情况下,它与远程功能没有任何关系 - 特殊的 4.0.x 版本会发生这种情况
猜你喜欢
  • 2017-06-28
  • 1970-01-01
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 2016-08-03
  • 1970-01-01
  • 2013-09-09
  • 2013-08-01
相关资源
最近更新 更多