WP_Widget Deprecated

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.

Solutions Collecting From Web of "WP_Widget Deprecated"

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);
 }