WordPress Widget options saving doesn’t work

I want to have changeable widget title via Options Panel in wp-admin > Appearance > Widgets.

It doesn’t seem to work, after clicking “SAVE” it always gives back the default instead of saving stuff.

Read More

Widgets control panel is very simplistic:

function myplugin_control() {

    echo '<p>
           <label for="myplugin_title">Title:</label>
           <input id="myplugin_title" name="myplugin_title" type="text" value="Default title:"/>
        </p>
        <p>
           <label for="myplugin_number">Number of items to show:</label>
           <input id="myplugin_number" name="myplugin_number" type="text" value="5" size="3"/>';  

        $myplugin_title = ($_POST["myplugin_title"]);
        $myplugin_number = ($_POST["myplugin_number"]);

        update_option('myplugin_widget', $myplugin_number , $myplugin_title); 

}

And plugin goes like:

(...)
    function widget_myplugin($args) {
      extract($args);
      echo $before_widget;
      echo $before_title . $myplugin_title . $after_title;
      myplugin();
      echo $after_widget;     
    }

Related posts

Leave a Reply

1 comment

    1. I think you’re using update_option(); improperly. It only takes two values. http://codex.wordpress.org/Function_Reference/update_option

    2. Try change the name of your title field to simply “title”. I think WP looks for this by default; see: http://wordpress.org/support/topic/how-can-i-set-a-widgets-title-in-for-use-in-the-dashboard

    3. Instead of using $_POST[‘title’], use the more standard $this->get_field_id(‘title’); and echo $this->get_field_name(‘title’);

    Hope this helps! Also: you may find the following link helpful: http://wpengineer.com/1023/wordpress-built-a-widget/