I made a plugin that obtains enrollment for a course. Each student in a course has a blog. The plugin creates a blogroll with links to each of the other students’ blogs.
I have everything working with the exception of adding it to the sidebar, by default. The user has to be able to change theme’s, so I don’t want to hardcode the plugin in the theme. I prefer to add it via the plugin.
I could go into all the ways I’ve tried to get this to work, but it basically comes down to this: I need to obtain (or calculate) the widget’s ID number prior to adding it to the options table.
For instance, before doing this:
// the widget configuration data $new_options = array( 'name'=>0, 'description'=>0, 'category'=>$term->term_id ); // the current options in the db table $classroll_options = get_option('widget_classroll'); // add widget config data to options array $classroll_options = $new_options; // IS THIS RIGHT??? // add the widget config data to the db table update_option($widget_classroll, $classroll_options);
I need to know the classroll widget’s id. Otherwise, as you can see in the above code, I just add it to the end of the $classroll_options array. This doesn’t work properly–yes, it adds to the array, but after testing, it looks like I should be defining the array key to define the element. In other words, WordPress does not use the options array as a numerically indexed array. Instead, it seems to use it as a named index array, those names just happen to be digits. Meaning an array with a single element can have an index of “6” like so: array( => options_data).
So, how do i get the index to which to assign the options data?
- The topic ‘Programming widget in sidebar by default’ is closed to new replies.