WordPress.org

Ideas

Allow ability to pass parameters when registering widgets

  1. Timothy Wood
    Member

    12345

    I have run into an issue several times when calling register_widget( 'MyNewWidget' ); for a shared widget class it instantiates the widget over any previously called register_widget() calls to the same class. My proposal is to implement a change of the WP_Widget_Factory::register method to allow passing parameters thus allowing unique constructor calls when registering. My proposed change can be seen as an extension of the WP_Widget_Factory now: https://gist.github.com/2437027

    Posted: 4 years ago #
  2. Dieta Dukana
    Member

    I don't think many people have ran into the same problem as you Timothy, but I think that this is a good idea and would make wordpress better.

    Posted: 4 years ago #
  3. Wonder
    Member

    12345

    I do not think this is strictly required, I think wordpress developers will overlook.

    Posted: 4 years ago #
  4. Hello Timothy,
    first of all, excuse me for my bad english, i'm from Germany. I have to say that you problem is not too rare. But have you checked your code at this point?:
    Class Extend_WP_Widget_Factory extends WP_Widget_Factory {

    In the most cases the fault could be found here.

    I hope you can solve your problem!
    with best regards,
    Jens Zalando

    Posted: 4 years ago #
  5. Tien Nguyen
    Member

    This way is much better than, add your widget naturally into WordPress stream:

    global $wp_widget_factory;
    $wp_widget_factory->widgets[$id] = new WP_Custom_Widget($args);
    Posted: 1 year ago #
  6. xoogu
    Member

    I agree adding the ability to pass constructor parameters would be useful. At the moment you need to use the hack Tien Nguyen used if you want to pass parameters to the widget.

    Another option could be to have a do_action in your widget constructor, to which you pass the widget instance. That would then allow you to register a callback for the action where you could inject the parameters into the object. But that would be even messier than Tien's solution IMO.

    Posted: 5 months ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    5 Votes
  • Status

    This idea is under consideration