How to do it...

  1. Navigate to the WordPress plugin directory of your development installation.
  2. Create a new directory called ch3-settings-api.
  3. Navigate to this directory and create a new text file called ch3-settings-api.php.
  4. 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 - Settings API.

 

  1. Add the following line of code to register a function that will be called when WordPress activates the plugin:
register_activation_hook( __FILE__,                           'ch3sapi_set_default_options' );
  1. Add the following code section to provide an implementation for the ch3sapi_set_default_options function to set default plugin options:
function ch3sapi_set_default_options() { ch3sapi_get_options(); ...

Get WordPress Plugin Development Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.