Working with Patches

This section of the handbook contains tutorials that will help you learn how to create, apply, and revert patches.

Patches are the only way that a contributor, like you, can submit code to the WordPress project.

Whether you are fixing a bugbug A bug is an error or unexpected result. Performance improvements, code optimization, and are considered enhancements, not defects. After feature freeze, only bugs are dealt with, with regressions (adverse changes from the previous version) being the highest priority. or contributing to a new feature, a patchpatch A special text file that describes changes to code, by identifying the files and lines which are added, removed, and altered. It may also be referred to as a diff. A patch can be applied to a codebase for testing. is required so the coreCore Core is the set of software required to run WordPress. The Core Development Team builds WordPress. developers and committers can consider your code for inclusion in the repository.

For betaBeta A pre-release of software that is given out to a large group of users to trial under real conditions. Beta versions have gone through alpha testing in-house and are generally fairly close in look, feel and function to the final product; however, design changes often occur as part of the process. testing the latest development version of WordPress, you will need to be able to apply patches that other contributors have created to determine if the patch fixes the issue.

SVN Client or Command Line Interface?

Many developers prefer to work with Subversion (SVNSVN Subversion, the popular version control system (VCS) by the Apache project, used by WordPress to manage changes to its codebase.) using the command line interface (CLICLI Command Line Interface. Terminal (Bash) in Mac, Command Prompt in Windows, or WP-CLI for WordPress.), while others prefer to use a GUI application. Both are acceptable, and will allow you to create, apply, and revert patches.

For command line users, there are programs such as Cygwin (Windows), Terminal (Mac), and Bash (Mac).

If you prefer to use a GUI application, the recommended SVN clients are TortoiseSVN (Windows, free/open-source), and Cornerstone (Mac, purchase).

Creating and Applying Patches with Grunt

If you like to automatically submit the created patch to an existing ticketticket Created for both bug reports and feature development on the bug tracker., there is an easy-to-use Grunt command available that can take care of both creating the patch and uploading it. In order to use the command, you need to have Node.js and Grunt-CLI globally installed, and you need to ensure that the WordPress development dependencies are installed locally, which you can do by running npm install.

Apply a patch from the command line

  1. Have a diff or a patch file in your working Directory, then run grunt patch. If multiple files are found, you’ll be asked which one to apply.
  2. Enter a ticket number, e.g.

grunt patch:15705

  1. Enter a ticket url, e.g.

grunt patch:https://core.trac.wordpress.org/ticket/15705

  1. Enter a patch url, e.g.

grunt patch:https://core.trac.wordpress.org/attachment/ticket/11817/13711.diff

  1. Enter a githubGitHub GitHub is a website that offers online implementation of git repositories that can easily be shared, copied and modified by other developers. Public repositories are free to host, private repositories require a paid subscription. GitHub introduced the concept of the ‘pull request’ where code changes done in branches by contributors can be reviewed and discussed before being merged be the repository owner. https://github.com/ url that points to a changeset such as a Pull Request, e.g.

grunt patch:https://github.com/muhammadfaizanhaidar/develop.wordpress/pull/23

Upload a patch from the command line

After you’ve made changes to your local WordPress develop repository, you can upload a patch file directly to a TracTrac An open source project by Edgewall Software that serves as a bug tracker and project management tool for WordPress. ticket. e.g. given the ticket number is 2907,

grunt upload_patch:2907

You can also store your WordPress.orgWordPress.org The community site where WordPress code is created and shared by the users. This is where you can download the source code for WordPress core, plugins and themes as well as the central location for community conversations and organization. https://wordpress.org/ credentials in environment variables. Please exercise caution when using this option, as it may cause your credentials to be leaked!

export WPORG_USERNAME=matt
export WPORG_PASSWORD=MyPasswordIsVerySecure12345
grunt uploadPatch:40000

Creating and Applying Patches with TortoiseSVN

Before starting, you need:

Creating a Patch with TortoiseSVN

1. Editing/Saving a File

Open the folder, and find the file you need to change. Open it in your favorite plain-text editor. Note: Do not use a rich-text editor such as Word or OpenOffice to edit the files.

Make the changes necessary, then save the file.

You will notice that the green checkmark has changed to a red exclamation point. That means the file has been changed, and is no longer in sync with the repo version.