Creating default user settings on plugin initialization
A typical first step of most user-configurable plugins is to create a default set of values for all options when the plugin is activated. These default options will subsequently be used to populate the plugin's configuration page when it is visited by the site administrator.
How to do it...
Follow these steps to register a function that is called when a plugin is activated and learn how to store options data in the site database:
- Navigate to the WordPress
plugins
directory of your development installation. - Create a new directory called
ch3-individual-options
. - Navigate to this directory and create a new text file called
ch3-individual-options.php
. - Open the new file in a code editor and add an appropriate header at the top of the plugin file, naming the plugin
Chapter 3 - Individual Options
. - Add the following line of code to register a function that will be executed when the plugin is activated...