Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#10051 closed enhancement (invalid)

More flexible register_widget()

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


The way widgets are currently registered don't allow you to pass arguments to the constructor.

This is a possible solution that is backwards compatible.

Attachments (1)

widgets.patch (664 bytes) - added by scribu 9 years ago.
Modifies WP_Widget_Factory::register() to allow object as the parameter

Download all attachments as: .zip

Change History (7)

9 years ago

Modifies WP_Widget_Factory::register() to allow object as the parameter

#1 @scribu
9 years ago

  • Keywords needs-testing removed
  • Summary changed from register_widget() should accept an object as the parameter to More flexible register_widget()
  • Type changed from defect (bug) to enhancement

I realize now that this goes against the whole ideea of the Factory pattern. Will think of a better solution.

#2 @Denis-de-Bernardy
9 years ago

  • Component changed from General to Widgets
  • Keywords reporter-feedback added; dev-feedback removed
  • Owner set to azaozz

What kind of argument do you need to pass? I've rewritten quite a few widget-related plugins myself in the past three weeks, and I've probably found your needed workaround.

#3 @Denis-de-Bernardy
9 years ago

  • Keywords needs-patch added; has-patch removed

#4 @scribu
9 years ago

  • Keywords reporter-feedback removed

I needed to pass the textdomain, but I realized that I can use a constant for that. Anyway, I would like to know your workaround.

#5 @Denis-de-Bernardy
9 years ago

The same as yours. Used defines where this kind of stuff was needed. Probably differently from what you're doing, but definitely works.

Shall we close?

#6 @scribu
9 years ago

  • Milestone 2.9 deleted
  • Resolution set to invalid
  • Status changed from new to closed

Yeah, if constants are not enough, we can always use global variables.

Note: See TracTickets for help on using tickets.