- Navigate to the WordPress plugin directory of your development installation.
- Create a new directory called ch11-hello-world.
- Navigate to the directory and create a text file called ch11-hello-world.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 11 - Hello World.
- Add the following line of code to register a function to be called when the plugin is activated:
register_activation_hook( __FILE__,
'ch11hw_set_default_options_array' );
- Insert the following block of code to provide an implementation for the ch11hw_set_default_options_array function:
function ch11hw_set_default_options_array() {
if ( false === get_option( 'ch11hw_options' ) ) {
$new_options = array();
$new_options['default_text'] = __( 'Hello World',
'ch11hw_hello_world' );
add_option( 'ch11hw_options', $new_options );
}
}
- Save and close the plugin file.
- Navigate to the Extensions (Plugins in French) management page and click on the Activer (Activate in French) link for the Chapter 11 - Hello World plugin.
- Using phpMyAdmin, find the options table entry where the option_name field has a value of ch11hw_options to see the newly created option: