WordPress.org

Forums

Question: how to one widget when another is saved/added? (2 posts)

  1. Mickey Kay
    Member
    Posted 1 year ago #

    Hi there,

    Summary:
    Is there a way to update widget A when widget B is modified/added/removed?

    Details:
    I've create an "alias" widget that outputs the content of any other active widget. In the admin, this widget has a drop-down <select> element that has an option for every other active widget. I would like the <select> menu to update when another widget is added/removed, and am not sure how to achieve this. In case this is unclear, here's an example:

    Save I have one alias widget and two other widgets: one text and one calendar. So the <select> in the alias widget shows:
    - text-1
    - calendar-1

    Say I then drag a new pages widget into the sidebar. As soon as the widget is added, i would like the <select> in my alias widget to auto-update to the following:
    - text-1
    - calendar-1
    - pages-1

    Same goes for deleting the widget or moving it to an inactive sidebar - I would like the <select> to then auto update back to:
    - text-1
    - calendar-1

    Is there a simple way to make this happen? Is it an ajax solution? Seems to me that I need to trigger the update function in my alias widget class whenever another widget is updated - does that sound right? If so, what filter/actions might I be looking for?

    Thanks a ton, ya'll - appreciate the help!
    - Mickey

  2. bcworkz
    Member
    Posted 1 year ago #

    I don't have access to my server right now to double check this, but I believe you do not use PHP at all. It is all client javascript or jQuery. Thus no filters/actions to use, only DOM events.

    Whenever some widget event happens, you need your drop down's content updated at the client. Since the widget changes get registered, when your widget loads with the next request, it will gather the updated data and display the correct state.

Topic Closed

This topic has been closed to new replies.

About this Topic