Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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');
?>
share|improve this question

1 Answer 1

up vote 3 down vote accepted

This part triggers it:

= ["widget_text-$id"]

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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