2

I've recently taken over development of a WordPress site that is throwing up the 'WP_Widget()' is deprecated warning.

After searching all the relevant files I've discovered the following block of code, that would appear to be the culprit:

/**
* @Agents(s) list widget Class
*/
if ( ! class_exists( 'cs_agentlist' ) ) {
class cs_agentlist extends WP_Widget {      

/**
 * Outputs the content of the widget
     * @param array $args
 * @param array $instance
 */

/**
 * @init User list Module
         */
 function cs_agentlist() {
    $widget_ops = array('classname' => 'widget_agents', 'description' => 'Select user to show in widget.');


$this->WP_Widget('cs_agentlist', 'CS : Agents', $widget_ops);
 }

......
}

From this i'm making the assumption that the following line needs to be changed:

$this->WP_Widget('cs_agentlist', 'CS : Agents', $widget_ops);

But, I'm not entirely sure how this needs to be changed. I've read this but am not 100% confident on my next move.

Any help would be greatly appreciated.

5

Replace your code with this. This warning is because PHP4 style constructors are depreciated since WordPress 4.3

/**
* @Agents(s) list widget Class
*/
if ( ! class_exists( 'cs_agentlist' ) ) {
class cs_agentlist extends WP_Widget {      

/**
 * Outputs the content of the widget
     * @param array $args
 * @param array $instance
 */

/**
 * @init User list Module
         */
 public function __construct() {
    $widget_ops = array('classname' => 'widget_agents', 'description' => 'Select user to show in widget.');

parent::__construct('cs_agentlist', 'CS : Agents', $widget_ops);
 }
  • Wordpress is leaning toward PHP 7, just wonder when will proper namespacing be introduced ;-) – Pieter Goosen Oct 1 '15 at 16:15
  • Well. I guess, this is a step towards that. – Hareesh Sivasubramanian Oct 1 '15 at 16:23
  • That fixed the problem. It seems I had another 12 instances of WP_Widget being used in the theme!! All are fixed now thanks. – Phill Healey Oct 2 '15 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.