Managing Custom Code for WordPress with Plugins

Extending WordPress with custom code is a common part of the development lifecycle. In order to optimize workflows, it's essential that extensions are maintained independently from your sites and projects so that custom code is easily reused. You'll also want to separate function from design, so that changes persist when swapping themes. This means no more dropping code into the current theme's functions.php file and no more pasting snippets when you want to reuse code in another project.

Instead, manage custom code separate from your projects within site-specific plugins. Then scope out an update strategy to easily distribute changes, such as GitHub Updater or WP Pusher.

Note

Pantheon does not support Git submodules (placing a Git repository within a subdirectory of your site’s repository).

Before You Begin

For more details on separating custom code, see this related blog post.

GitHub Updater

GitHub Updater is an open-source plugin developed by Andy Fragen that extends the existing notification and update mechanisms within WordPress to plugins and themes hosted outside of the official WordPress repository on GitHub, Bitbucket, or GitLab. This will display update notifications within the WordPress dashboard for public and private repositories.

Modify your plugin and/or theme to add support for the GitHub Updater by providing the required declarations. The following plugin example should be placed within the plugin's header:

As an alternative to adding declarations within the headers of plugins and themes, you can use the GitHub Updater Additions plugin, which will add the appropriate data via hooks in GitHub Updater.

Set the Dev environment's connection mode to SFTP within the Pantheon Dashboard or via Terminus: terminus connection:set <site>.<env> sftp

Download the latest release of the GitHub Updater plugin (select the zip option).

Unzip the archive and rename the folder to github-updater, then re-zip the file.

Install the plugin by uploading the renamed zip file within the WordPress Dashboard on the Dev environment (/wp-admin/plugin-install.php?tab=upload).

Activate GitHub Updater from the Plugin page (/wp-admin/plugins.php).

Navigate to Settings > GitHub Updater > Install Plugin/Install Theme to install your custom extensions. Alternatively, you can upload your plugin/theme using the same method described above for installing the GitHub Updater plugin.

Notifications within the WordPress dashboard will now include updates to your custom code. If expected updates are not found within /wp-admin/update-core.php, click Check Again to clear transients, or wait for them to reset automatically.

WP Pusher

WP Pusher provides a similar method for managing your custom code, but with some key differences. WP Pusher is free for open source code hosted in public repositories. Supporting private repositories requires you to purchase a license. Currently, update notifications are not displayed within the WordPress dashboard, but you can configure the plugin to automatically install updates on Pantheon following a push to the remote repository (e.g. GitHub, Bitbucket, or GitLab). There are no declarations required within your plugin or theme, so modifications to existing custom extensions are not required.