We will cover the following topics in this chapter:
- Installing a web server on your computer
- Downloading and configuring a local WordPress installation
- Creating a local Subversion repository
- Importing initial files to a local Subversion repository
- Checking out files from a Subversion repository
- Committing changes to a Subversion repository
- Installing a dedicated code/text editor
Before we start writing our first WordPress plugin, it is important to have a good set of tools in place that will allow you to work locally on your computer and be more efficient in your work. While it is possible to perform some development tasks with the built-in tools that are provided with the operating system, creating a solid local development environment will help you develop plugins quickly and have full control over your server settings to be able to test different configurations.
This chapter proposes a set of free tools that can easily be installed on your computer, regardless of your preferred operating system, to facilitate the development of your future WordPress plugins. These tools include a local web server to speed up page access and avoid sending files constantly to a remote server, a version control system to keep incremental backups of your work, and a code editor to enhance your editing capabilities. In addition to installing and learning how to use these...
The first step to configure a local development environment is to install a local web server on your computer. This will transform your computer into a system capable of displaying web pages and performing all tasks related to rendering a WordPress website locally.
Having a local web server has many benefits, as follows:
- It provides a quick response to the frequent page refreshes that are made as plugin code is written, tested, and refined, since all information is processed locally
- It removes the need to constantly upload new plugin file versions to a remote web server to validate code changes
- It allows development to take place when no internet connection is available (for example, when traveling on an airplane)
- It offers a worry-free programming environment, where you cannot bring down a live website with a programming error or an infinite loop
There are many free packages available online that contain all of the web server components necessary to run...
The next component of our local development environment is to install WordPress on your local web server to run a fully working website and have all of its files hosted locally.
WordPress has always prided itself with its easy five minutes installation process. Installing it on a local web server is even easier and quicker than it would be on a live remote server. This recipe covers the creation of a MySQL database to store all data related to our new WordPress installation and the actual setup process.
This recipe assumes that you have a local web server installed on your computer. This web server can be a fresh install performed using the previous recipe or can be from a previous installation. The steps in the following section are written with a focus on new local web servers. If you have created a new account to access the MySQL database or changed the root user's password, some of the steps will change slightly. The...
Version control is an important part of any code development project, to keep track of a project's history, to have full and organized backups, and to be able to easily roll back changes to get back to a known working state. Version control is also the best and most efficient way to share code and other files when developing a project in a team environment. In addition to being a great version control system that is easy to use and configure, Subversion (often referred to as SVN) is also the technology that manages all submissions on the official WordPress plugin directory. Therefore, by setting up and using a local Subversion repository during your initial plugin development, you will immediately be ready to share your creations with the community.
- Visit the TortoiseSVN website (https://tortoisesvn.net/downloads.html) and download the free Subversion client for your version of Windows (32-bit or 64-bit).
Once you have a local repository in place, this recipe describes the steps required to add files and start tracking their revisions over time. To have the flexibility to create multiple plugins, as discussed throughout this cookbook, without having to worry about adding each of them to the repository individually, we will add the entire WordPress plugin directory to your local repository.
You should have already installed a Subversion client on your computer and created a local repository, as described in the Creating a local Subversion repository recipe. These steps will be slightly different based on the Subversion client that you have selected and your operating system.
After performing an initial import of the files to a Subversion repository, the files need to be checked out to really start working in a version control environment. This recipe explains how to check out files from your local repository and what the resulting file structure changes will be.
You should have already installed a Subversion client, created a local repository, and imported files before following this recipe. These steps will be slightly different based on the Subversion client that you have selected and the operating system you are using.
- Navigate to the WordPress plugin directory of your local installation in the file explorer if you are not already there.
- Right-click in the white space of the directory window and select the
SVN Checkout...
menu item. - Enter the file location of your local Subversion repository in the
URL of repository
field (for example,file:///c:/WPSVN
), if it is not already specified...
During the course of a project, plugin files will typically be created, modified, or deleted. These changes should be transmitted regularly to the Subversion repository to have proper backups of all the files in a project. A good practice is to commit changes at least once a day, with more frequent commit operations taking place when specific milestones are reached in the implementation of a plugin's features.
This recipe indicates how to manage file creation, modification, and deletion operations to keep everything organized and mirrored in the Subversion repository.
You should have already installed a Subversion client, created a local repository, and imported and checked out files before performing the steps in this recipe. These steps will be slightly different based on the Subversion client that you have selected and the operating system you are using.
Most operating systems provide a built-in text editor. While it is possible to create WordPress plugins using such a simple tool, it is highly recommended to install a dedicated code editor on your computer to simplify your plugin development work.
Of course, not all code editors are equal. Here are some of the features that you should look for when selecting a code editing application:
- PHP syntax highlighting
- Completion of PHP function names
- Ability to search in multiple files simultaneously
- Ability to highlight all instances of search keyword(s) or selected text
- Line numbering
- Ability to resize the editor text or specify a replacement font
- Possibility of opening multiple files simultaneously
The following editors contain most or all of these key features. Most are free tools, but some are paid applications:
On the Windows platform:
- Programmer's Notepad (http://www.pnotepad.org)
- Notepad++ (https://notepad-plus-plus.org/)
- Visual Studio Code...