Make WordPress Core

Opened 15 years ago

Closed 14 years ago

Last modified 9 years ago

#10276 closed defect (bug) (wontfix)

Cannot inherit from WP_Widget_RSS

Reported by: jonknight73's profile jonknight73 Owned by: azaozz's profile 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 15 years ago.
Suggested code change removing hardcoded class names.

Download all attachments as: .zip

Change History (5)

15 years ago

Suggested code change removing hardcoded class names.

#1 @jonknight73
15 years ago

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

#2 @peaceablewhale
15 years ago

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

#3 @azaozz
14 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.

#4 @DrewAPicture
9 years ago

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