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.
Installing a dedicated code editor/text editor
Getting ready
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 (https://code.visualstudio.com)
On the Mac platform:
- TextMate (https://macromates.com)
- TextWrangler (https://www.barebones.com/products/TextWrangler)
On the Linux platform:
- Screem (http://www.screem.org/)
Cross-platform:
- Sublime Text (https://www.sublimetext.com)
This recipe explains how to install a dedicated code editor and shows basic editor operations. It provides detailed steps using Programmer's Notepad for Windows.
How to do it...
- Download the installation package for one of the text editors listed previously.
- Run the installation program for the editor and select the default settings.
- Launch the text editor.
- Open the hello.php file from the plugin directory of your local WordPress installation. You will see that different parts of the code are displayed in different colors based on the type of code.
- Double-click on a word to select it. You will see any other instance of that same word highlighted across the file contents:
- Select the View | Line Numbers menu item (or similarly named item based on your selected text editor) to display line numbers in the editor.
How it works...
Code editors have built-in parsers that enable them to identify the parts of the code that are comments, PHP language functions, text strings, and a variety of other elements. Having these elements colored on the screen makes it much easier to read through code and to see that a function's name is not spelled correctly, or to quickly identify comments.
Another functionality that is crucial when developing plugins for WordPress is the ability to see line numbers in the editor. This function comes in handy, especially when PHP code errors come up, since the filename and line of code that was being processed at the time of the error are normally displayed. In most code editors, the developer can either scroll to the specific line or enter the line number in a quick Go To dialog box to jump to that line right away.