WordPress.org

Ready to get started?Download WordPress

Forums

Widgets creation and destruction hooks (3 posts)

  1. mgiulio
    Member
    Posted 3 years ago #

    Hello,

    I would need to execute some code when an instance of a widget is created and destructed.

    For creation I mean when a widget is dragged in a sidebar in the Widget admin page.
    For destruction I mean when the widget is deleted form the same sidebar.

    I was not able to find any suitable action hooks, so I was wandering if it is something that should be added or if I am approaching the problem in a wrong way.

    If needed I can provide more details, thanks in advance.

  2. Jerry
    Member
    Posted 3 years ago #

    What exactly are you trying to fire and why?

  3. mgiulio
    Member
    Posted 3 years ago #

    First of all, I am subclassing the WP_Widget class.

    The widget must support multiple instances.

    Each instance needs to store(for caching purposes) some data in a subdirectory like this: <plugindir>/cache/instance-<n>.

    So, I need to create and remove this directories and I was thinking that the most natural event would be when the user drag a new widget instance on the sidebar and when he clicks the delete link.

    I understand that i could create the subfolder in the overriden WP_Widget::update() method but it is not elegant (nor efficient).
    And what about the directory removal? How to catch this event?

    I hope I've been clear, sorry for my english.

Topic Closed

This topic has been closed to new replies.

About this Topic