0

I am building a theme that allows widgets to be dragged & dropped, essentially turning WP into a desktop-like environment where the admin controls what "apps" are available via the widget panel.

This is going reasonably well, except that it would be nice is if there were a way for the admin to store starting locations for all of the widgets (and presumably, more meta-data later)

In practical terms, this means I want 2 custom fields to appear on each widget in the admin panel, and then for there to be a hook to spit that data out when the widgets are printed on the page (in my case as some inline style values).

I am building this "desktop" using home.php

I am not sure if wordpress is actually built to do this, but it seems vaguely plausible. Any thoughts? Thanks!

2
  • You are needing/hoping to add fields to any widget on the site, whether made by you or by somebody else?
    – s_ha_dum
    Commented Oct 16, 2013 at 23:28
  • @s_ha_dum that is correct Commented Oct 17, 2013 at 14:19

1 Answer 1

1

Crude code. I have never tried this but I can get you part of the way there.

Add a field...

add_action(
  'in_widget_form', 
  function ($instance) {
    echo '<input type="text" value="c00l" />';
    return null;
  },
  1
);

And there is a hook that runs on settings update.

add_filter(
  'widget_update_callback', 
  function($instance, $new_instance, $old_instance, $this) {
    var_dump($instance, $new_instance, $old_instance, $this); die;
  },
  1,4
);

However, it looks like you need to add an option/setting to the widget before that hook will work and I don't see how to do that. I am probably missing something obvious but don't have time to do more research right now.

Reference

http://core.trac.wordpress.org/browser/trunk/src/wp-includes/widgets.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.