【问题标题】:After WordPress 4.3 update widget does not workWordPress 4.3 更新小部件后不起作用
【发布时间】:2015-11-14 17:22:22
【问题描述】:

在我将 WordPress 更新到 4.3 后,我的小部件无法工作。 在更新之前,我的小部件工作正常。 我浏览了谷歌,但除了他们说我必须使用我正在使用的 __construct 函数外,我没有发现任何可以帮助我的东西。 有什么帮助吗?

ps。我知道我已经包含了文件,小部件出现在小部件列表中我也确实将小部件放在了侧边栏上,但它没有在侧边栏上打印“这是小部件的内容”。

这是我的简单代码:(编辑:下面是编辑后的代码,现在可以使用。感谢提供解决方案的两个人)

<?php

class test_widget extends WP_Widget {

function __construct() {
  parent::__construct(
    'test_pop', // Base ID
    __( 'test widget', 'text_domain' ), // Name
    array( 'description' => __( 'A test Widget', 'text_domain' ), ) // Args
  );

  add_action('widgets_init', array($this, 'widgets_init'));
}

public function widget( $args, $instance ) {
  echo $args['before_widget'];
  echo "<h1> This is the content of widget<h1>";
  echo $args['after_widget'];
}

public function form( $instance ) {

}

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

}

function test_widget_register() {
  register_widget( 'test_widget' );
}

add_action( 'widgets_init', 'test_widget_register' );

?>

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    内部函数__construct:

    function __construct(){
        parent::__construct(
        //define your widgets ID,Name, Description.
        )
        add_action('widgets_init', array($this, 'widgets_init'));
    }
    

    然后应用上面的 user5251252 进行功能更新。

    【讨论】:

      【解决方案2】:

      这些问题来自插件。因为有些插件旧版本的类名和函数名是相同的所以你会这样做,

      1. 首先停用所有插件并更新所有插件。它将起作用。

      例子:

          class PHP_Code_Widget extends WP_Widget {
      
          function PHP_Code_Widget() {
      
         }
      

      【讨论】:

        【解决方案3】:
        <pre><code>
        public function update( $new_instance, $old_instance ) {        
                $instance = array();        
                return $instance;       
            }
        </code></pre>
        

        $instance 必须设置。

        【讨论】:

        • 非常感谢您的帮助,但它也不起作用。
        猜你喜欢
        • 2012-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-10
        • 1970-01-01
        • 1970-01-01
        • 2016-07-09
        相关资源
        最近更新 更多