Forums

How to automatically instanciate a widget and add it to a sidebar ? (1 post)

  1. drzraf
    Member
    Posted 2 years ago #

    I never spent so much time in code while understanding so little from it.
    I attempted to instanciate a widget (a simple WP_Widget_Text) in order to add it to a sidebar. I failed to do this.

    $a = new WP_Widget_Text();
    $_POST = array(
       'id_base' => 'text',
       'widget-id' => 3,
    /* I still don't understand why we don't get an autoincrement to ease the task and simplify the code, ...*/
        'multi_number' => '55',
    /* don't really know the following, because :
    $num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number']; // wp-includes/widgets.php, l 220) */
         'widget_number' => '42',
    );
    $b = $a->update_callback(55);
     /* nothing here, I come in the complexity of all_instances where I can't do anything */
    $b = $a->update(array(), array('text' => 'blah));
     /* nothing here, because it doesn't get stored */

    If I provides the fields in the constructor, the 'system' fields get omitted (like 'filter'), so no defaults are available.

    I don't understand why its so complex with so many nested arrays and 'ID'.
    If somebody would give me even the tiniest hint possible that would be the end of the evil for me.
    thanks

Topic Closed

This topic has been closed to new replies.

About this Topic