The biggest change is, of course, the dashboard_notepad_widget_control() function. The first thing you need to do in this function is get the existing options from the database, then run through the data posted from the form and update any options if necessary using the update_options function. (This function is more often used for theme and plugin options, and you'll see it again in the next chapter.) Once that's done, just print form fields for each option, with the stored options shown as the field defaults. As with the sidebar widgets, you don't have to include the form tag or the submit button; those are taken care of automatically.
The control function has to be added to the widget setup function. The name of the control function is the last argument passed to wp_add_dashboard_widget(). As you saw in Listing 8-13, if this argument is not present, the widget will not have a configuration screen.
Most of the other changes to the functions simply involve adding checks for your new options. There is one unusual thing about the revised dashboard_notepad_widget_setup() function. Since you're now checking to see whether the user can read the notes, the entire wp_add_dashboard_widget() function is now wrapped in an if() statement. You could have put this in the dashboard_notepad_widget() function, checking only whether the user gets to see the textarea containing the notes. However, in that case, users who don't have permission to read the notes would have a useless widget cluttering up their Dashboards. By placing this check in the setup function instead, you hide the widget altogether if the user can't see its contents.
Was this article helpful?