When developing plugins for WordPress, it's important to have a good list of resources to help guide you in the right direction. This list of resources is the developer's toolbox. In this chapter, you'll learn the most popular and helpful resources available for plugin development. You'll also review tools that every developer should use to help optimize the process of plugin development.
The best reference when developing plugins for WordPress is the core WordPress code. What better way to learn about the inner workings of WordPress, and discover new features, than to explore the code that powers every plugin you develop? Understanding how to navigate through the core WordPress code is a valuable resource when developing professional plugins. Also, contrary to online resources and the Codex, the core is always up‐to‐date.
Many of the core WordPress files feature inline documentation. This documentation, in the form of a code comment, gives specific details on how functions and code work. All PHP inline documentation is formatted using inspiration from the PHPDoc standard for PHP commenting, meaning there are some differences between the PHPDoc standard and the WordPress implementation of inline documentation. The following comment sample is the standard template for documenting a WordPress function:
/**
* Short Description
*
* Long Description
*
* @package WordPress
* @since version
*
* @param type $varname Description
* @return type Description
*/
Inline documentation is an invaluable resource when exploring functions in WordPress. The comment includes a short and long description, detailing the purpose of a specific function. It also features the WordPress version in which it was added. This helps determine what new functions are added in each release of WordPress.
Parameters are also listed, along with the data type of the parameter and a description of what the parameter should be. The return type and description are also listed. This helps you understand what value a specific function will return. For example, when creating a new post in WordPress, the newly created post ID would be returned if successful.
Now look at the following real inline documentation for the delete_option
(
)
function:
/**
* Removes option by name. Prevents removal of protected WordPress options.
*
* @since 1.2.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $option Name of option to remove. Expected to not be SQL-escaped.
* @return bool True, if option is successfully deleted. False on failure.
*/
function delete_option( $option ) {
The inline documentation features a clear description of the purpose of this function. You can see that the function is part of the WordPress package and was added in version 1.2.0. The comment also lists any PHP globals that are used within the function or method, which can include an optional description of the global.
The only parameter required for this function is $option
, which is described as the option name. Finally, the return value is boolean
; True
if successful and False
on failure.
Another important tag that may exist within the inline documentation is the @deprecated
tag. A deprecated function in WordPress is a function that should no longer be used. Typically, if a function is @deprecated
, a new function will exist that replaces it. Let's look at an example of the @deprecated
tag for the get_the_author_description()
function.
/**
* Retrieve the description of the author of the current post.
*
* @since 1.5.0
* @deprecated 2.8.0 Use get_the_author_meta()
* @see get_the_author_meta()
*
* @return string The author's description.
*/
function get_the_author_description() {
As you can see, the @deprecated
tag exists within the inline documentation. In this example, the appropriate new function to use is the get_the_author_meta()
function. The deprecated function was added to WordPress in 1.5.0 and deprecated in the 2.8.0 release. This is especially important information to verify that your plugin is using the most up‐to‐date functions within the WordPress core software.
For more information on the PHP Documentation Standards, visit the WordPress Handbook section at https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php
.
As with PHP, JavaScript files also include templated code documentation. WordPress follows the JSDoc 3 standard for inline JavaScript documentation. The format of the JSDoc 3 standard is similar to the WordPress PHP format, but there are some slight differences. To learn more about WordPress commenting in JavaScript, visit the handbook at https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/javascript
.
Inline documentation is an ongoing process. All new functions added to WordPress are documented using this process. Helping to document existing functions is a great way to dive into core contributing to WordPress.
Now that you understand how to use inline documentation to learn functions in WordPress, you need to know how to find those functions. To start, make sure you have downloaded the latest version of WordPress to your local computer. You will be searching through these code files for functions.
Every core file, excluding images, can be viewed in a text editor program. When choosing a text editor to use, make sure it supports searching within files. You can find an extensive list of text editors on the Codex at https://wordpress.org/support/article/glossary/#text-editor
.
When searching through the core WordPress files for a specific function, you need to make sure calls to that function are filtered out or you may get hundreds of results. The easiest way to do this is to include the word function at the start of your search. For example, to find wp_insert_post()
, simply search for function wp_insert_post.
Many of the functions you use in your plugins are located in specific core files. Exploring these files is a great way to find new and exciting functions to use in your plugins.
The wp‐includes
folder features many of the files used for public‐side functions: that is, functions used on the public side of your website.
The formatting.php
file contains all WordPress API formatting functions, such as the following:
esc_*()
: Includes all escaping functions in this fileis_email()
: Verifies that an email address is validwp_strip_all_tags()
: Strips all HTML tags, including script and style, from a stringget_url_in_content()
: Extracts and returns the first URL found in a text stringThe functions.php
file contains the main WordPress API functions. Plugins, themes, and the WordPress Core use these functions, for example:
*_option()
: Adds, updates, deletes, and retrieves optionscurrent_time()
: Retrieves the current time based on the time zone set in WordPresswp_nonce:*()
: Creates nonce values for forms and URLswp_upload_dir()
: Retrieves array containing the current upload directory's path and URLis_wp_version_compatible()
: Checks compatibility with the current version of WordPressis_php_version_compatible()
: Checks compatibility with the current version of PHPThe pluggable.php
file contains core functions that you can redefine in a plugin. This file is full of useful functions for your plugins, for example:
get_userdata()
: Retrieves all user data from the specified user IDwp_get_current_user()
: Retrieves user data for the currently logged‐in userget_avatar()
: Retrieves a user's avatarwp_mail
: Is the main function for sending email in WordPresswp_redirect()
: Redirects to another pagewp_rand()
: Generates a random numberThe plugin.php
file contains the WordPress Plugin API functions, such as the following:
add_action()
: Executes this hook at a defined point in the execution of WordPressadd_filter()
: Uses this hook to filter prior to saving in the database or displaying on the screenplugin_dir_*()
: Functions to determine a plugin's path and URLregister_activation_hook()
: Is called when a plugin is activatedregister_deactivation_hook()
: Is called when a plugin is deactivatedregister_uninstall_hook()
: Is called when a plugin is uninstalled and uninstall.php
does not exist in the plugin directoryThe post.php
file contains the functions used for posts in WordPress, as follows:
wp_*_post()
: Functions for creating, updating, and deleting postsget_posts()
: Returns a list of posts based on parameters specifiedget_pages()
: Returns a list of pages based on parameters specified*_post_meta()
: Functions to create, update, delete, and retrieve post metadataregister_post_type()
: Registers custom post types in WordPressget_post_types()
: Retrieves a list of all registered post typesset_post_thumbnail()
: Sets the post thumbnail (featured image) for a specific postwp_delete_attachment()
: Trashes or deletes an attachment based on the post IDThe user.php
file contains the functions used for users in WordPress, as follows:
get_current_user_id()
: Returns the ID of the currently logged‐in user*_user_meta()
: Functions for adding, updating, deleting, and retrieving user metadatawp_*_user()
: Functions for adding and updating a WordPress userThis is just a small list of the more popular functions and their locations. Many more functions are available to use when developing your plugins. When a new version of WordPress is released, it's always fun to explore these files to see what functions have been added and are available for use in your plugins.
One of the most important online resources for plugin development is the WordPress Plugin Developer Handbook. The handbook is the official online resource for plugin development documentation and is located at https://developer.wordpress.org/plugins
.
The handbook is a project created and supported by the WordPress Docs Team. This team is a volunteer group of contributors that help maintain the information contained within the handbook. It's a living resource in that it's continually updated to be as accurate as possible.
This resource is packed full of information about using, and developing with, WordPress. It includes an extensive feature and function reference with some helpful tutorials and examples demonstrating the more common functions in WordPress.
The Plugin Developer Handbook covers a wide range of plugin development topics. To quickly find a topic of interest, you can use the search field. There is also extensive navigation on the left with topics and subtopics covering a large variety of plugin development material.
The handbook is an exceptional resource when developing WordPress plugins. If you are interested in contributing to the handbook, reach out to the WordPress Docs Team at https://make.wordpress.org/docs
.
Another invaluable tool on WordPress.org
for plugin developers is the Code Reference. The Code Reference is a detailed handbook of WordPress functions, classes, methods, and hooks. You can easily search using the search field and filter the results by the type of item you are looking for.
The Code Reference is largely generated using the inline comments that we reviewed earlier in this chapter. Let's look at the add_option()
function as an example: https://developer.wordpress.org/reference/functions/add_option
.
As shown in Figure 16‐1, the top of the code reference page shows the function with all the available parameters. Next is a detailed description of exactly what the function does, in this case creating a new option value in the database. The parameters are then listed with each parameter type, whether it is required or not, a short description explaining the parameter, and the default value.
Next the return value is shown, if one exists. The source file is identified, so you know where the function is defined, in this case wp‐includes/option.php
as well as the code defining the function. Next we have the changelog, which identifies what version of WordPress introduced this function. The related section shows “Uses” and “Used by” functions. The final section is the “User Contributed Notes” section. This is the one area where a user can log in and submit example code and notes to expand the entry. As you can see, this visual resource may be an easier way to digest the information that exists within the WordPress Core software.
Visit the Code Reference at https://developer.wordpress.org/reference
.
Another important resource, yet slightly older, is the WordPress Codex. The Codex is an online wiki for WordPress documentation and is located at https://codex.wordpress.org
.
The Codex is packed full of information about using, and developing with, WordPress. It includes an extensive function reference with some helpful tutorials and examples demonstrating the more common functions in WordPress.
You can search the Codex in a few different ways. The most common way is to use the Codex search located at https://wordpress.org/search
or to enter your search terms in the search box located in the header of WordPress.org
. The default search for the Codex is everything, but you can also search the Support Forums, Developer Documentation, or Support Docs, as shown in Figure 16‐2.
The Codex also features an extensive glossary. This can help you become familiar with terms used in the Codex, as well as in WordPress. You can access the glossary at https://wordpress.org/support/article/glossary
.
The Codex home page also features an index of articles organized by topic. The articles are ordered by level of difficulty, with an article specific to the latest version of WordPress near the top. This article details new features, functions, changes, and so on, in the latest version of WordPress. It's always helpful to read this article to become familiarized with any changes to functions and methods for developing plugins in WordPress.
One big benefit of the Codex is the function reference section located at https://codex.wordpress.org/Function_Reference
. This section lists all functions in the Codex for the more popular WordPress API functions. This page is a must‐bookmark for any WordPress plugin developer.
Each individual function reference page contains a description of the function, basic usage example, parameters required for the function, and return values. Think of these function reference pages as quick and easily readable inline documentation on a function. Most function pages also feature an example, or more, demonstrating practical uses of that particular function.
Many different websites are available to help in researching and understanding specific functionality in WordPress. These sites can help as new versions of WordPress are released with new functionality that can be used in your plugins.
PHPXref is a cross‐referencing documentation generator. Quite simply, it is a developer tool that can scan a project directory and translate the files processed into readable cross‐referenced HTML files. It automatically processes PHPDoc commenting to produce documentation for the functions included.
An online hosted version of PHPXref is also available, which is more specifically for WordPress. The online version is located at https://phpxref.ftwr.co.uk/wordpress
.
Visiting the WordPress PHPXref site, you'll be confronted with what looks like a Windows Explorer layout, as shown in Figure 16‐3.
As you can see, the standard WordPress folder displays on the left with the core subdirectories and root files listed. As an example, click into the wp‐includes
directory and click the plugin.php
file. Clicking this link brings up a summary view of the current file selected, in this case plugin.php
. This summary view has useful information including a list of every function in the file, as shown in Figure 16‐4.
Getting a top‐level glance at all functions in a WordPress core file is a great way to find new functions and even locate existing functions for reference. Clicking any listed function takes you to the section of the page detailing the usage of the function. This information is extracted from the inline documentation saved in the WordPress Core file. If the function is not documented in WordPress, this section will be empty. You can also easily view the source of any file by clicking the Source View link near the header of the page.
It's easy to see how useful the WordPress PHPXref site is for a developer. This is another required tool to add to your resource arsenal.
The WordPress hooks database, which was created and is supported by Adam Brown, is the essential resource for discovering hooks in WordPress. Adam built a system that digs through all WordPress core files and extracts every action and filter hook that exists in WordPress. He has been indexing these values since WordPress 1.2.1 and updates the hooks database with each new major version of WordPress.
One of the best features of the hooks database is you can view all new hooks added in each version of WordPress. Hooks are one of the most powerful features that you can use when creating plugins in WordPress. Clicking any hook name produces a hook detail screen showing where the hook is defined in the WordPress Core code.
To visit the hooks database, visit https://adambrown.info/p/wp_hooks
.
There are also many different community resources available to help with WordPress development. These resources can help you expand your knowledge of plugin development, troubleshoot plugin issues, and work with new features in WordPress.
The Make WordPress section of WordPress.org
is a collection of websites and team groups dedicated to contributing to different parts of the WordPress project. You can view all teams on the official website at https://make.wordpress.org
. These are important WordPress teams for plugin developers to follow:
As you can see, there are many different teams dedicated to the growth and success of the WordPress project. The teams consist largely of volunteers who help coordinate and run project initiatives. You can view an aggregated list of team meetings at https://make.wordpress.org/meetings
.
WordPress.org features a large support forum for topics ranging from using WordPress to plugin development. You can visit the support forums at https://wordpress.org/support
.
Multiple forum sections can help expand your knowledge on plugin development and can support any public plugins you have released. The following are the forum sections specific to plugins:
https://wordpress.org/support/forum/wp-advanced
: Discussions are more advanced and complex than usual.https://wordpress.org/support/forum/multisite
: Anything and everything regarding the Multisite feature.https://wordpress.org/support/forum/plugins-and-hacks
: Plugin support questions. If you release a plugin to the Plugin Directory, users can submit support issues specific to your plugin.Often it's nice to have a live conversation when seeking help for plugins or about WordPress development. WordPress uses Slack for live chat and has a number of active chat rooms or channels. To join the WordPress Slack Workspace, you need to follow the instructions at https://make.wordpress.org/chat
.
These Slack channels are an awesome resource for real‐time help when developing plugins in WordPress. Many WordPress experts hang out in these rooms and enjoy helping others learn WordPress.
When developing plugins, and releasing to the public, you need to stay current on new features and functionality coming in the new version of WordPress. This can help you verify not only if your plugin is compatible with the latest version but also what new features your plugins can take advantage of. One of the best ways to track WordPress development is through the Make WordPress Core site at https://make.wordpress.org/core
.
The Make WordPress Core site is a blog that focuses on the core development of WordPress. You can also find out about the weekly developer chats that take place in the Slack channel #core. These chats discuss the current status of the upcoming WordPress version, feature debates and discussions, and much more.
WordPress.org features an ideas section for creating and rating ideas for future versions of WordPress. This is actually a great resource for gathering ideas for plugins. Many of the ideas submitted could be created using a plugin. The more popular an idea is, the more popular the plugin will most likely be.
The WordPress Ideas area is at https://wordpress.org/ideas
.
There are some great websites that focus on WordPress developer–related news and articles. Many of these sites feature development‐focused tutorials and tips that can be used when creating your plugins. The following sections explore useful community news sites that are available.
The WordPress.org Blog, called WordPress News, is the best place to stay current on WordPress news. The blog centers around WordPress core release information but also includes other important WordPress‐related news. You can view the official blog at https://wordpress.org/news/
and subscribe to the feed at https://wordpress.org/news/feed
.
WordPress Planet is a blog post aggregator located on WordPress.org. This includes posts from WordPress core contributors and active community members. This news feed, together with the WordPress.org Blog feed, is also featured in the WordPress Events and News Dashboard widget of every WordPress‐powered website by default.
WordPress Planet is located at http://planet.wordpress.org
.
As a premium club, Post Status is a news website dedicated to the WordPress ecosystem for professionals and enthusiasts. Post Status members are invited to a member‐only Slack Workplace that is an amazing resource when developing professional plugins for WordPress. There are multiple Slack channels available for help including #development, #javascript, and #club. These channels feature many advanced WordPress plugin developers available to help answer questions or give general guidance.
You can learn more about the Post Status Club by visiting its website at https://poststatus.com
.
Know the Code provides online training courses for anyone who wants to specialize in WordPress development. With hands‐on code building labs, the goal of Know the Code is to empower every WordPress developer to learn deeply about architecture, programming fundamentals, testing, validation, code quality, and more.
You can visit Know the Code at https://knowthecode.io
.
LinkedIn Learning features some amazing online courses taught by professionals in the industry. Topics range from basic plugin development to advanced courses including actions and filters, creating editor blocks, custom workflows, building apps with the REST API, and more. Visit https://www.linkedin.com/learning/topics/wordpress
to find out more.
Twitter is also a great resource for following WordPress developers, contributors, and the entire community. More specifically, the Twitter account @wordpress is the official WordPress account. This is a quick and easy way to stay current with news and information about WordPress. You can also follow your favorite book authors on Twitter at @williamsba, @justintadlock, and @jjj!
Another great resource is local WordPress events. When learning to create plugins in WordPress, it can help to find other enthusiastic developers near you to learn from and work with.
WordCamps are locally organized conferences covering anything and everything WordPress. Many WordCamps feature plugin‐development‐specific presentations given by some of the top plugin developers in the community. These presentations are a great way to learn new and advanced techniques to use in your plugins. To find a WordCamp near you, visit https://central.wordcamp.org
.
WordPress Meetups are also a great way to meet local developers in your area. Meetups generally happen more often, typically on a monthly basis, and are a local gathering of WordPress enthusiasts. Meetups are also generally smaller, more focused groups allowing for more in‐depth and personal conversations to take place. To find a local WordPress Meetup, visit https://www.meetup.com/pro/wordpress
.
When developing plugins for WordPress, you want to use specific tools to make your life much easier.
WordPress is web software; therefore, you will spend much of your time debugging plugins in your web browser. Some browsers stand above the rest when it comes to developer features. The two more popular development browsers are Firefox and Google Chrome. Both of these browsers feature development tools and can be expanded with additional tools to make debugging and troubleshooting much easier.
Firefox features powerful web development tools called the Firefox Developer Tools. These tools enable you to easily edit, debug, and monitor HTML, CSS, and even JavaScript. Firefox also supports Extensions enabling you to enhance the features in Firefox. You can learn more about Firefox Developer Tools at https://developer.mozilla.org/en-US/docs/Tools
.
Google Chrome is also a great development browser. Chrome features a built‐in set of tools called Chrome DevTools. These tools can enable you to edit and debug HTML, CSS, and JavaScript in real time. You can also install extensions in Chrome that add additional functionality to the browser. You can learn more about Chrome DevTools at https://developers.google.com/web/tools/chrome-devtools
.
Creating plugins for WordPress is as simple as creating a PHP file. PHP files are actually text files with a .php
extension. Because of this, you can develop PHP files using any basic text editor. Although text editors can certainly get the job done, they won't offer the more advanced features such as syntax highlighting, function lookup, spell‐check, and so on.
NetBeans IDE is a popular editor that is an open source development environment that runs on Java. Because of this, it can run on any platform that supports the Java Virtual Machine including Windows, macOS, Linux, and Solaris. NetBeans supports PHP with syntax highlighting, PHP debugging using Xdebug, remote and local project development, and many more features. For more information and to download NetBeans, visit https://netbeans.org
.
PhpStorm is another popular IDE that supports Mac, Windows, and Linux. A major reason this IDE is great is the direct WordPress integration support. PhpStorm also has built‐in developer tools including version control systems, support for remote deployments, database/SQL, command‐line tools, Docker, and Composer support. To learn more and download PhpStorm, visit https://www.jetbrains.com/phpstorm
.
Notepad++ is a popular open source text editor that runs on Windows, macOS, and Linux. The editor is a lightweight text editor, similar to standard Notepad, but offers many features including syntax highlighting, macros and plugins, autocompletion, regular expression find and replace, and more. To download Notepad++, visit http://notepad-plus-plus.org
.
TextMate is a GUI text editor for macOS. It's a popular editor among developers because it features some programming‐centric features. Some of these features include nested scopes, bundles (snippet, macro, and command groupings), project management, and more. You can download TextMate at https://macromates.com
.
Another popular text editor is Sublime Text. One popular feature is the Goto Definition, which allows you to quickly find where a class, method, or function is defined within the WordPress code in a single click. This is extremely handy when building plugins as you can quickly consult the core code as needed. Sublime Text is available for Mac, Windows, and Linux at https://www.sublimetext.com
.
Developed by Microsoft, Visual Studio Code is another great popular, free, and open source option. Visual Studio Code is lightweight like Sublime Text but offers many of the same features as bigger IDEs like PhpStorm. The editor supports Windows, Mac, and Linux at https://code.visualstudio.com
.
When developing plugins, you need to decide whether you plan to run a local instance of WordPress on your computer or use an external web server. If using an external server, you need to use some method to push your files to your server. The most popular method is using SFTP.
File Transfer Protocol (FTP) is a standard network protocol used to copy files from your computer to another computer, or a web server in this case. For FTP, FileZilla is a free, open source FTP client that works on Windows, macOS, and Linux. You can learn more about FileZilla and can download the client at https://filezilla-project.org
.
Secure File Transfer Protocol (SFTP) is also a popular method for deploying files to a server. The major difference between FTP and SFTP is that SFTP is encrypted. This means any account info, usernames, passwords, and files you transfer are sent over an encrypted transport. Many popular FTP clients, including FileZilla, also support SFTP.
Secure Shell (SSH) is a third option for transferring files to a web server. SSH is more than just a way to transfer files. For example, you can interact with MySQL using SSH. A popular SSH client is PuTTY, which runs on Windows and UNIX platforms and can be found at https://www.putty.org
. Mac users can use the built‐in shell called Terminal when working with SSH.
On occasion you may need to directly work with the WordPress database. The most common method to do this is by using phpMyAdmin, which is a free tool, written in PHP, which provides a simple web interface to view and manage a MySQL database. Most web hosts have this tool installed by default.
Using phpMyAdmin, you can easily view what data your plugin adds to WordPress tables. This can significantly help speed up the debug process. You can also run phpMyAdmin on your computer by downloading the software package at https://www.phpmyadmin.net/downloads
.
As a plugin developer, you need a solid set of tools in your developer toolbox. Every developer's toolbox is unique and customized to your tastes and server setup. Becoming comfortable with your developer tools can help you be comfortable when creating professional plugins in WordPress. If you don't have a set of preferred tools, you should ask around and see what other developers use. It's always fun to talk with other programmers to see what tools they use and recommend.
When developing, news and community websites are just as important as your tools. These sites can help you expand your knowledge on plugin development, learn about new features and proper usage of those features, and become a part of the greatest community on the Web: the WordPress Community. Code on!
3.14.130.24