Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#16761 closed defect (bug) (fixed)

php notices with the_widget().

Reported by: mfields's profile mfields Owned by: nacin's profile nacin
Milestone: 3.3 Priority: normal
Severity: normal Version:
Component: Widgets Keywords: has-patch
Focuses: Cc:

Description

the_widget() generates php notices when not passed $args and $instance parameters. To my knowledge these parameters are intended to be optional. To reproduce:

  1. Define WP_DEBUG as true in wp_config.php
  2. Please the following code in any template file in your active theme:
<?php
	the_widget( 'WP_Widget_Archives' );
	the_widget( 'WP_Widget_Calendar' );
	the_widget( 'WP_Widget_Categories' );
	the_widget( 'WP_Nav_Menu_Widget' );
	the_widget( 'WP_Widget_Links' );
	the_widget( 'WP_Widget_Meta' );
	the_widget( 'WP_Widget_Pages' );
	the_widget( 'WP_Widget_Recent_Comments' );
	the_widget( 'WP_Widget_Recent_Posts' );
	the_widget( 'WP_Widget_RSS' );
	the_widget( 'WP_Widget_Search' );
	the_widget( 'WP_Widget_Tag_Cloud' );
	the_widget( 'WP_Widget_Text' );
?>

I have attached a patch that I believe eliminates all notices. Please let me know your thoughts.

Attachments (2)

16761.patch (5.7 KB) - added by mfields 13 years ago.
Fixes notices in widgets.
16761.2.patch (4.9 KB) - added by SergeyBiryukov 13 years ago.

Download all attachments as: .zip

Change History (14)

@mfields
13 years ago

Fixes notices in widgets.

#1 @nacin
13 years ago

  • Milestone changed from Awaiting Review to 3.2
  • Owner set to nacin
  • Status changed from new to accepted

#2 @aaroncampbell
13 years ago

It seems like even an empty title should be passed through the widget_title filter.

#3 @mfields
13 years ago

Good call. I think you're totally right about this.

#4 follow-up: @westi
13 years ago

I'm not sure that these are really widget bugs.

If these notices only show when widgets are loaded via the_widget then it may be because these items are required configuration for the widget that the theme should be providing.

If we do make the changes here we can revert - [17672]

#5 @ryan
13 years ago

  • Milestone changed from 3.2 to Future Release

#7 @ocean90
13 years ago

#16281

#16131 is not included in this patch, if it's in we can close it too.

#9 in reply to: ↑ 4 @SergeyBiryukov
13 years ago

  • Milestone changed from Future Release to 3.3

Replying to westi:

If these notices only show when widgets are loaded via the_widget then it may be because these items are required configuration for the widget that the theme should be providing.

Most of these widgets have default configurations and should fall back to them properly.
As I mentioned in #18595, Google shows a lot of results with these notices, so it would be nice to fix them.

Refreshed the patch for 3.3.

Last edited 13 years ago by SergeyBiryukov (previous) (diff)

#10 @westi
13 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In [18676]:

Fix Notices in default Widgets when called using the_widget(). Fixes #16761 props mfields and SergeyBiryukov

#11 @westi
13 years ago

In [18677]:

Set a consistent cache key when using the_widget to display the Recent Posts and Recent Comments widgets so that they get cached. See #16761.

#12 @ramiy
13 years ago

Related #16159.

The "Rrecent Post widget" and the "Recent Comments widget" have no args filters.

Last edited 13 years ago by ramiy (previous) (diff)
Note: See TracTickets for help on using tickets.