When you’re developing something new, taking very small steps is usually best.
This way, if something breaks, the problem is clear. Doing multiple new things at
one time makes finding where something went wrong difficult.
Sticking with this concept, the first plugin you create in this chapter is a plugin
that can be activated and deactivated but doesn’t do anything — in other words, a
fully functional plugin shell that’s ready for code to be added.
Because this plugin is an example and doesn’t do anything, I named it Example
Plugin: Do Nothing
Setting up the plugin files
For this plugin, all you need is a main plugin file. Follow these steps to upload it
to its own directory:
1. Connect to your web server via Secure File Transfer Protocol (SFTP).
Check out Book 2, Chapter 2 for details on using SFTP.
2. Browse to the /wp-content/plugins directory in your WordPress
installation directory.
If you’re unsure where your WordPress installation directory is located, see
Book 2, Chapter 4, where I cover installing WordPress on your web server.
3. Create a new directory within /wp-content/plugins called /
example-do-nothing.
Most SFTP programs allow you to right-click in the SFTP window and choose
Add New Folder or Add New Directory from the shortcut menu.
4. Create an empty .php file with the filename init.php.
Use your favorite text editor, such as Notepad for PC or TextEdit for Mac, to
open a new file and then save it with the filename init.php.
5. Upload your blank do-nothing.php file to /wp-content/plugins/
example-do-nothing.
Your plugin directory and plugin file are set up.
In the next section, you add code to the do-nothing.php plugin file.
Adding the file header
Open the do-nothing.php file you created in the preceding section. (Most SFTP
programs have built-in text editors that allow you to right-click the file and
choose Edit from the shortcut menu.) Add the following lines of code to create the
file header:
<?php
/**
Plugin Name: Example Plugin: Do Nothing
Plugin URI: https://lisasabin-wilson.com
Description: This plugin literally does nothing. It is an example of how to
create a valid WordPress plugin.
Version: 1.0
Author: Lisa Sabin-Wilson
Author URI: https://lisasabin-wilson.com
License: GPLv2 or later
Text Domain: nothing
*/
?>
Adding the closing ?> tag at the end of a PHP file is optional at this point. Leaving it out is helpful because it prevents you from accidentally adding code after it,
which may cause the PHP code to break.
Adding a plugin description isn’t necessary, but it makes the purpose of the plugin
clear to anyone who reads your code. Additionally, the plugin description displays
on the Plugins screen on your Dashboard to give users a good idea of the purpose of your plugin. When developing, you wind up with many plugins that you
used for simple tests or left unfinished. Having solid names and descriptions adds
order to the chaos so that you don’t forget or accidentally delete important code.
Be sure to save the do-nothing.php file and upload it to your /wp-content/
plugins/example-do-nothing directory on your web server.