[wp-hackers] Question about the architecture of the admin widgets.php
John BouAntoun
jbouantoun at gmail.com
Mon Jan 4 06:02:53 UTC 2010
Hi guys,
I'm one of the devs on the about me widget, and I've had to do some
ugly/evil things to the widget to get it to work in WP 2.9 and wanted some
advice.
The main thing we try and do is embed the mce editor in the widget
administration page. In order to do that I need to catch the click events of
the widget-action control and the widget-save button to do an
mce.triggerSave() so that the control's text is saved to the db.
In WP 2.9 the two controls who's click event I was trying to catch now use
the live('click') approach, instead of the bind('click') approach, which
makes it more difficult for me to catch the click events and run my custom
code prior to triggering the default behaviour.
I have come up with a work around:
1. Do a bind('click') that return's true on the widget-action's parent
- this allows me to do my pre-display mce widget clean up and then let
the control unwrap itself
2. Do a bind('click') that returns false on the save button
- this allows me to do a triggerSave on MCE and then manually call the
save function.
Both these approaches are ugly hacks, and what I would rather have is a
mechanism for handling a administration form event into the event queue.
Something like savebutton.queueEvent('click', start, function(){..}); that
would allow me to queue my event at the beginning of the click processing
order, so that I could, for example perform validation and data clean up
before the default widgets.php boiler plate code handles the db save.
So the general solution would be to use a queuable event binding mechanism
for all events in Wordpress, but failing that, the specific solution would
be to allow me to wire in a pre-display event and a pre-save event, to allow
me to do my mce control clean up and save triggering.
Can anyone suggest a better approach to solve my issue or let me know the
likelyhood of either solution (general or specific) happening in the near
future so that I know if it's worth updating my plugin with the dirty hack
or not?
Regards,
JBA
More information about the wp-hackers
mailing list