0

I'm attempting to dynamically create a text widget, add it to a named sidebar widget that my theme has already created ($sidebar_id = 'home-header-widget'), then populate the text widget with some preset content. I'm getting an error as indicated above at line 35 (commented below). Any ideas what I'm doing wrong?

Parse error: syntax error, unexpected '[' in C:....widgettest.php on line 35


<?php
/*
Plugin Name: Widget Test
*/


function cb_activate_widgettest(){

    $ops = get_option('widget_text');
    // find an $id that works...
    $ops[$id] = array(
      'title' => '',
      'text' => 'bar', // content?
    );
    update_option('widget_text', $ops);

    $sidebar_id = 'home-header-widget';
    $sidebars_widgets = get_option('sidebars_widgets');
    $sidebars_widgets[$sidebar_id] = ["widget_text-$id"];  //this is line 35
    update_option('sidebars_widgets', $sidebars_widgets);
}

register_activation_hook(__FILE__, 'cb_activate_widgettest');
?>
3

This part triggers it:

= ["widget_text-$id"]

Copy paste gone wrong or something? Square brackets used this way make no sense to PHP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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