The called constructor method for WP_Widget is deprecated since version 4.3.0

前端 未结 6 612
一生所求
一生所求 2020-12-13 13:28

I just updated to WordPress 4.3 and it seems that something is broken.

I get this error that shows up on my page:

Notice: The called construct

6条回答
  •  心在旅途
    2020-12-13 14:19

    I am also getting the same error And I fixed it in such a way

    class Dokan_Category_Widget extends WP_Widget {
    
        /**
         * Constructor
         *
         * @return void
         **/
        public function __construct() {
            $widget_ops = array( 'classname' => 'dokan-category-menu', 'description' => __( 'Dokan product category menu', 'dokan' ) );
            $this->WP_Widget( 'dokan-category-menu', 'Dokan: Product Category', $widget_ops );
        }
    }
    

    As way of calling constructor in such way is deprecated in php 7, so I replaced calling way as $this->WP_Widget() with parent::__construct()

    class Dokan_Category_Widget extends WP_Widget {
    
        /**
         * Constructor
         *
         * @return void
         **/
        public function __construct() {
            $widget_ops = array( 'classname' => 'dokan-category-menu', 'description' => __( 'Dokan product category menu', 'dokan' ) );
            //$this->WP_Widget( 'dokan-category-menu', 'Dokan: Product Category', $widget_ops );
            parent::__construct('dokan-category-menu', 'Dokan: Product Category', $widget_ops  );
        }
    }
    

提交回复
热议问题