Storing user settings using arrays
While the previous recipe worked quite well in creating entries in the site's options table for each individual plugin option, another way to manage user settings is to store them as arrays in the database.
This recipe creates the same option as the previous one, but also adds a second option indicating whether outgoing links should be tracked. It uses an array instead of individual options to store these settings. It also incorporates an upgrade strategy to deal with the creation of additional options as a plugin evolves over time.
Getting ready
You should have already followed the recipe entitled Inserting link tracking code in the page body using plugin filters in Chapter 2, Plugin Framework Basics, to have a starting point for this recipe. Alternatively, you can get the resulting code (ch2/ch2-page-header-output/ch2-page-header-output-v2.php
) from the book's GitHub page and rename the file ch2-page-header-output.php
.