WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Settings for multiple instances of a widget (5 posts)

  1. dc_photo
    Member
    Posted 1 year ago #

    Hi all,

    I am creating a widget for wp which needs to be able to appear in multiple instances within a page. This widget basically draws data from another server and displays them. This is OK so far.

    What I am now contemplating is this:
    Each of the instances must have its own settings - which are quite a lot. It is obvious how I can include some settings in the space provided in wp-admin/widgets.php, however I find this space quite limited.

    So the question is:
    If I create a page that manages my plugin under "Settings", can this page be made so that it knows whether the administrator has more than one instances of the widget active, and dynamically add a settings page (in the form of a tab perhaps)?

    Otherwise, can I create a "Settings" page in the actual widget in the front-end, that is aware (and is only active) if the administrator is logged-in?

    These are the two approaches I could think of, any advice would be very much appreciated. Please let me know if something is not clear.

    Thanks!

    D.

    [No bumping. If it's that urgent, consider hiring someone.]

  2. bcworkz
    Member
    Posted 1 year ago #

    I have no experience with external widget settings, but I'm willing to speculate for the sake of discussion. The settings pages under the admin menu could work. You can get which widgets are in use from various globals defined in wp-includes/widgets.php.

    I don't like the front end settings idea simply because it is illogical. I would not normally think to go there to administer a widget. So I would curse the author that thought that was a good idea ;) Why not apply the same concept to the backend form? Simply add a link to the form to your settings page, passing the widget ID as a parameter.

    Of course, with external settings, you will need to completely manage their sanitizing, saving, maintenance, and use outside of the widget class methods that normally would do this for you. The only real problem I see right now is how would you know to remove the settings if the user deletes the associated widget? There may be a way, but I don't see one on a cursory look at the class methods.

    As stated initially, I only offer these thoughts for the sake of discussion. I am not in any way qualified to offer any expert opinion in this matter. Feel free to rebut, concur, or ignore as you see fit.

  3. dc_photo
    Member
    Posted 1 year ago #

    Hi bcworkz,

    Thanks for your reply!

    The problem you describe - how to remove the settings if the user deletes the associated widget - is exactly the point at which I would prefer to have the settings in the front page, as part of the widget. I think that this would make the coding for sanitizing/saving/maintenance much easier as well...

    Also, even though I agree with you that it seems illogical to have settings in the front-end , for this particular application the settings are irrelevant to wordpress functionality or content but rather have to do with the content the widget dispalys from another server. So saving the user to have to go back and forth in the admin panel might not be such a bad thing.

    Anyway, if I decide to go with the front end solution, do you by any chance know of a hook that would recognize if the owner of the widget is logged-in? Mind you that this is a multisite installation, so I'd rather associate it with a particular user rather than with a role but anyway this is not a "must", as every user of the widget will also be an administrator to his blog.

    Thanks a lot for your help.

  4. catacaustic
    Member
    Posted 1 year ago #

    Don't have the settings anywhere apart from in the widgets area. That's just adding a lot of confusion andI guarantee that you'll confuse anyone that's trying to use it without a whole lot of training. If you're running multisite, then you'll be training every administrator that looks after each site on how to set it up. That's way to involved for something that should be simple, and gives your admins way to many chances to get it all wrong.

    The widgets form area is adjustable. It goes as deep as it needs to, and it can be extended wider to fit more in (look at the Text widget for an example) so there's no excuse about form fields not fitting.

  5. dc_photo
    Member
    Posted 1 year ago #

    Ok catacaustic, I checked the text widget like you said, and you've convinced me to do it that way! Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic