Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 5 months ago

#10276 closed defect (bug) (wontfix)

Cannot inherit from WP_Widget_RSS

Reported by: jonknight73 Owned by: azaozz
Milestone: Priority: normal
Severity: normal Version: 2.8
Component: Widgets Keywords: has-patch needs-review
Focuses: Cc:


I attempted to use the following code in a plugin, with the eventual aim of contextually modifying the URL.

require_once( ABSPATH . WPINC . '/default-widgets.php' );

class Example_Widget extends WP_Widget_RSS {

function  Example_Widget() {
	$widget_ops = array( 'description' => __('Example Widget') );
	$control_ops = array( 'width' => 400, 'height' => 200 );
    $this->WP_Widget( 'example-widget', 'Example Widget', $widget_ops, $control_ops );

function widget($args, $instance)
     $newinstance = $instance;
	 WP_Widget_RSS::widget($args, $newinstance);

I was attempting to customise the default WordPress RSS plugin using inheritance. It works, but you cannot set the settings in the control panel, you need to hack the url setting into play via SQL.

In wp-include/default-widgets.php the form and update methods of WP_Widget_RSS reference static functions that hard codes it's base id.

The function wp_widget_rss_form sets the id on the form as follows:

<input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" /></p>

Should this code really be in the class, and the id and name set using the functions get_field_id and get_field_name. This will then allow inheritance to work properly.

wp-admin/includes/dashboard.php also references the function wp_widget_rss_form.

Attachments (1)

default-widgets.diff (5.1 KB) - added by jonknight73 6 years ago.
Suggested code change removing hardcoded class names.

Download all attachments as: .zip

Change History (5)

@jonknight736 years ago

Suggested code change removing hardcoded class names.

comment:1 @jonknight736 years ago

The above diff is a hack, and does not address dashboard.php, but it illustrates what I am getting at.

comment:2 @peaceablewhale6 years ago

  • Keywords has-patch needs-review added
  • Milestone changed from Unassigned to 2.9

comment:3 @azaozz6 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

The RSS handling functions were separated from the widget as they are used in other places too. Instead of extending the RSS widget, a better option would probably be to make your own using the same external functions if needed. This would also make your plugin easier to uninstall: the users wouldn't have to redo the widget's settings in order to use the default.

comment:4 @DrewAPicture5 months ago

  • Milestone 2.9 deleted
Note: See TracTickets for help on using tickets.