I want to revive an old WordPress theme. This theme has some deprecated functions in it so I'm trying to resolve them.
Notice: The called constructor method for WP_Widget in Custom_Recent_Posts is deprecated since version 4.3.0! Use __construct() instead.
This tells me that the constructor method for WP_Widget is deprecated, so that must be this line:
$this->WP_Widget('Custom_Recent_Posts', 'Custom Recent Posts', $widget_ops);
But that line seems okay? I can't find what's wrong with it.
The full script is like this:
class Custom_Recent_Posts extends WP_Widget {
function Custom_Recent_Posts() {
$widget_ops = array('classname' => 'Custom_Recent_Posts', 'description' => 'The recent posts with thumbnails' );
$this->WP_Widget('Custom_Recent_Posts', 'Custom Recent Posts', $widget_ops);
}
function widget($args, $instance) {
extract($args, EXTR_SKIP);
echo $before_widget;
$items = empty($instance['items']) ? ' ' : apply_filters('widget_title', $instance['items']);
if(!is_numeric($items))
{
$items = 3;
}
if(!empty($items))
{
pp_posts('recent', $items, TRUE);
}
echo $after_widget;
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['items'] = strip_tags($new_instance['items']);
return $instance;
}
function form($instance) {
$instance = wp_parse_args( (array) $instance, array( 'items' => '') );
$items = strip_tags($instance['items']);
?>
<p><label for="<?php echo $this->get_field_id('items'); ?>">Items (default 3): <input class="widefat" id="<?php echo $this->get_field_id('items'); ?>" name="<?php echo $this->get_field_name('items'); ?>" type="text" value="<?php echo esc_attr($items); ?>" /></label></p>
<?php
}
}
register_widget('Custom_Recent_Posts');
Any help would be great.
So now I have this:
class Custom_Recent_Posts extends WP_Widget {
public function __construct() {
$widget_ops = array('classname' => 'Custom_Recent_Posts', 'description' => 'The recent posts with thumbnails' );
$this->WP_Widget('Custom_Recent_Posts', 'Custom Recent Posts', $widget_ops);
}
function widget($args, $instance) {
extract($args, EXTR_SKIP);
echo $before_widget;
$items = empty($instance['items']) ? ' ' : apply_filters('widget_title', $instance['items']);
if(!is_numeric($items))
{
$items = 3;
}
if(!empty($items))
{
pp_posts('recent', $items, TRUE);
}
echo $after_widget;
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['items'] = strip_tags($new_instance['items']);
return $instance;
}
function form($instance) {
$instance = wp_parse_args( (array) $instance, array( 'items' => '') );
$items = strip_tags($instance['items']);
?>
<p><label for="<?php echo $this->get_field_id('items'); ?>">Items (default 3): <input class="widefat" id="<?php echo $this->get_field_id('items'); ?>" name="<?php echo $this->get_field_name('items'); ?>" type="text" value="<?php echo esc_attr($items); ?>" /></label></p>
<?php
}
}
register_widget('Custom_Recent_Posts');