Skip to content

Commit

Permalink
Add how to update/manage plugins from external repositories doc (#9256)
Browse files Browse the repository at this point in the history
* add git updater docs

* add section for using terminus and wp plugin install for non-git repos

* add contributor and reviewed date

* GitHub Updater -> Git Updater

* add user prompt

* update install instructions

* update plugin setup instructions

* update plugin example

* whitepace

* point to the git updater page instead of github

* copy edits

* add link to wp-cli doc

* add link to write access doc

* change the link

* add section on Composer

* add contributors

* bump date

* add jq-based option

* more info about --force flag

* copy edits for composer

* and themes...

* copy edits

---------

Co-authored-by: Steve Persch <[email protected]>
  • Loading branch information
jazzsequence and stevector authored Oct 17, 2024
1 parent 0dc8478 commit 39bd190
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: WordPress Configurations Guide
subtitle: Manage Custom Code for WordPress with Plugins
description: Learn how to manage custom plugins or themes for WordPress sites with GitHub Updater or WP Pusher.
description: Learn how to manage custom plugins or themes for WordPress sites with Git Updater or WP Pusher.
contenttype: [guide]
innav: [false]
categories: [config]
Expand All @@ -10,15 +10,16 @@ audience: [development]
product: [--]
integration: [plugins]
tags: [workflow, code]
contributors: [afragen, petersuhm]
contributors: [afragen, petersuhm, jazzsequence]
reviewed: "2024-10-14"
permalink: docs/guides/wordpress-configurations/wordpress-custom-code
---

This section provides information on how to manage custom plugins and themes on your WordPress Pantheon site.

Extending WordPress with custom code is a common part of the development lifecycle. It's essential that extensions are maintained independently from your sites and projects to optimize workflows and to allow custom code to be reused easily. You should also separate function from design to allow changes to persist when you swap themes. This method allows you to avoid dropping code into the current theme's `functions.php` file and pasting snippets when you want to reuse code in another project.

You can manage custom code separate from your projects within site-specific [plugins](https://codex.wordpress.org/Writing_a_Plugin). This allows you to scope out an update strategy to distribute changes easily. [GitHub Updater](https://github.com/afragen/github-updater) or [WP Pusher](https://wppusher.com/) are good options for this workflow.
You can manage custom code separate from your projects within site-specific [plugins](https://codex.wordpress.org/Writing_a_Plugin). This allows you to scope out an update strategy to distribute changes easily. [Git Updater](https://github.com/afragen/git-updater) or [WP Pusher](https://wppusher.com/) are good options for this workflow.

<Alert title="Note" type="info">

Expand All @@ -34,55 +35,55 @@ Pantheon does not support Git submodules (placing a Git repository within a subd

Refer this [blog post](https://pantheon.io/blog/wordpress-development-git) for more information on separating custom code.

## GitHub Updater
## Git Updater

[GitHub Updater](https://github.com/afragen/github-updater) is an open-source plugin developed by [Andy Fragen](https://thefragens.com) 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. GitHub Updater displays update notifications within the WordPress dashboard for public and private repositories.
[Git Updater](https://github.com/afragen/git-updater) is an open-source plugin developed by [Andy Fragen](https://git-updater.com/) that extends the existing notification and update mechanisms within WordPress to plugins and themes hosted outside of the official WordPress repository on GitHub, Bitbucket, GitLab, Gitea or GitHub Gists. Git Updater displays update notifications within the WordPress dashboard for public and private repositories.

1. Modify your plugin and/or theme to add support for the GitHub Updater by providing the required declarations. The following [plugin example](https://github.com/afragen/github-updater/#plugins) should be placed within the plugin's header:
1. Add the [relevant header line](https://git-updater.com/knowledge-base/usage/) to your plugin or theme header block to add support for the Git Updater depending on where your code is hosted.(`GitHub Plugin URI`, `). The following [plugin example](https://git-updater.com/knowledge-base/usage/#articleTOC_2) should be placed within the plugin's header:

```bash
/*
Plugin Name: GitHub Updater
Plugin URI: https://github.com/afragen/github-updater
Description: A plugin to automatically update GitHub, Bitbucket or GitLab hosted plugins and themes. It also allows for remote installation of plugins or themes into WordPress.
Version: 1.0.0
Author: Andy Fragen
License: GNU General Public License v2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Domain Path: /languages
Text Domain: github-updater
GitHub Plugin URI: https://github.com/afragen/github-updater
GitHub Branch: master
*/
/**
* Plugin Name: My Cool Plugin
* Plugin URI: https://github.com/wpdeveloper/my-cool-plugin
* Description: A cool plugin that does cool things.
* Version: 1.0.0
* Author: WordPress Developer
* License: GNU General Public License v2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* GitHub Plugin URI: https://github.com/wpdeveloper/my-cool-plugin
* GitHub Languages: https://github.com/wpdeveloper/my-cool-plugin-translations
*/
```

[Theme declarations](https://github.com/afragen/github-updater#themes) are made similarly within the `styles.css` file.
[Theme declarations](https://git-updater.com/knowledge-base/usage/#articleTOC_3) are made similarly within the `styles.css` file.

As an alternative to adding declarations within the headers of plugins and themes, you can use the [GitHub Updater Additions](https://github.com/afragen/github-updater-additions) plugin, which will add the appropriate data via hooks in GitHub Updater.
As an alternative to adding declarations within the headers of plugins and themes, you can use the [Additions functionality inside the Git Updater plugin](https://git-updater.com/knowledge-base/git-updater-additions/), which will add the appropriate data via hooks in Git Updater.

1. Set the Dev environment's connection mode to SFTP within the Pantheon Dashboard or via [Terminus](/terminus):

```bash{promptUser: user}
terminus connection:set <site>.<env> sftp
```

1. Download the [latest release](https://github.com/afragen/github-updater/releases) of the GitHub Updater plugin (select the **zip** option).
1. Download the [latest release](https://github.com/afragen/git-updater/releases) of the Git Updater plugin.

1. Unzip the archive and rename the folder to `github-updater`, then re-zip the file.
1. Install the plugin by uploading the zip file within the WordPress Dashboard on the Dev environment (`/wp-admin/plugin-install.php?tab=upload`).

1. Install the plugin by uploading the renamed zip file within the WordPress Dashboard on the Dev environment (`/wp-admin/plugin-install.php?tab=upload`).
1. Activate Git Updater from the Plugin page (`/wp-admin/plugins.php`).

1. Activate GitHub Updater from the Plugin page (`/wp-admin/plugins.php`).
1. Navigate to **Settings**, select **Git Updater**, and then select **Install Plugin**/**Install Theme** to install your custom extensions.

1. Navigate to **Settings**, select **GitHub Updater**, and then select **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.
Alternatively, you can install the Git Updater plugin directly from the command line using Terminus:

```bash{promptUser: user}
terminus wp <site>.<env> -- plugin install https://github.com/afragen/git-updater/releases/download/12.6.0/git-updater-12.6.0.zip
```
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](https://codex.wordpress.org/Transients_API), or wait for them to reset automatically.
## WP Pusher
[WP Pusher](https://wppusher.com/) provides a similar method to GitHub Updater 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. This means that modifications to existing custom extensions are not required.
[WP Pusher](https://wppusher.com/) provides a similar method to Git Updater 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. This means that modifications to existing custom extensions are not required.
1. [Download WP Pusher](https://wppusher.com/).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
title: WordPress Configurations Guide
subtitle: Installing and Updating Plugins and Themes from Third-Party Sources
description: Learn how to set up plugins and themes that are set up in external repositories.
contributors: [jazzsequence, pwtyler, stevector]
contenttype: [guide]
innav: [false]
categories: [config]
cms: [wordpress]
audience: [development]
product: [--]
integration: [plugins]
tags: [code, plugins]
reviewed: "2024-10-16"
permalink: docs/guides/wordpress-configurations/installing-updating-from-third-party-sources
---

This section provides guidance on how to manage plugins that use third-party sources beyond the WordPress plugin ressources. Such places include GitHub, Bitbucket, GitLab or self-hosted sources.

<Alert title="Note" type="info" >

All the guidance in this document is intended to be used in conjunction with Dev or Multidev environments on Pantheon where version-controlled files can be changed directly. [Pantheon's security practices lock down file permissions in the Test and Live environments]("guides/filesystem/files-directories#write-access-on-environments").

</Alert>

## Using Git Updater to install and manage plugins (and themes) from Git repositories

[Git Updater](https://github.com/afragen/git-updater) is a plugin that allows you to install and update plugins and themes from GitHub, Bitbucket, GitLab, or other self-hosted Git repositories. It provides both a mechanism that plugins can use to suggest updates from a Git-based repository as well as a user interface to install plugins from a Git repository that has not been previously configured to do so. Plugins and themes that use Git Updater can then be updated directly from the WordPress dashboard.

Before you begin, make sure the Dev or Multidev environment in which you are working is set to [SFTP mode](/connection-modes).
That mode can be changed either from the Pantheon dashboard or by using the Terminus `connection:set` command.

```bash{promptUser: user}
terminus connection:set <site>.<env> sftp
```

### Installing the Git Updater plugin

Download the latest zip file for the Git Updater plugin from the [Git Updater website](https://git-updater.com/) or use [WP-CLI through Terminus](https://docs.pantheon.io/guides/wp-cli) to install the plugin from its zip file in the GitHub repository releases page:

```bash{promptUser: user}
terminus wp <site>.<env> -- plugin install https://github.com/afragen/git-updater/releases/download/12.6.0/git-updater-12.6.0.zip --force
```

Once installed, an option for Git Updater will appear under Settings in your WordPress admin dashboard.
Clicking into it for the first time will prompt you to enter a license key or activate the free version.
Once you've gone through the initial prompts, you will be presented with the default admin page for Git Updater which includes out-of-the-box support for GitHub-based plugins and themes.
![Git Updater Settings](../../../images/wordpress-configurations/08-git-updater-admin.png)


### Installing a plugin or theme from a Git repository

To install a plugin or a theme from a GitHub repository, click on the "Install Plugin" or "Install Theme" tab and enter the Plugin URI (in the format `<vendor>/<plugin-name>` e.g. `pantheon-systems/pantheon-hud` ), the repository branch (default is `master`) and the remote repository host (either GitHub or a zip file).
You can also specify a GitHub Personal Access Token for private GitHub repositories. Then click Install Plugin/Theme.
![Git Updater Install Plugin](../../../images/wordpress-configurations/08-git-updater-install-plugin.png)

### Updating plugins through Git Updater

Themes and Plugins use a `GitHub Plugin URI` or `GitHub Theme URI` header string in the main plugin file (for plugins) or `style.css` (for themes) in order for the Git Updater to work to update those plugins or themes out of the box.

It is also possible for plugins or themes to receive updates from GitHub or other sources using the Git Updater even if this header is not present by using the Additions tab.

To add a plugin that gets updates from a Git repository but lacks the GitHub Plugin or Theme URI plugin header line, click on the Additions tab, enter the main plugin file name as the Repository Slug (e.g. `pantheon-hud/pantheon-hud.php`), the repository URI (in the format `<vendor>/<plugin-name>`, e.g. `pantheon-systems/pantheon-hud`), the branch (default is `master`), and whether the plugin or theme should look use a Release Asset (defaults to no release asset). Then click Save Changes.

![Git Updater Additions](../../../images/wordpress-configurations/08-git-updater-additions.png)

The Git Updater plugin will now check for updates from the specified repository and branch and will update the plugin or theme as necessary from that source rather than the default behavior.

### Using Git Updater with non-GitHub Repositories

Git Updater supports other repository hosts such as BitBucket, GitLab, Gitea and even GitHub Gists. To add support for any of these, go to the API Add-Ons page while your site is in SFTP mode and click Install & Activate for the add-on of your choice.

![Git Updater API Add-Ons](../../../images/wordpress-configurations/08-git-updater-api-addons.png)

## Using plugins and themes with their own self-hosted update mechanism

Some plugins and themes have their own self-hosted update mechanism that allows them to receive updates from a third-party source. Usually, you can find a download link from the relevant plugin or theme author and upload the zip file to your WordPress site or unzip locally and add to your Pantheon site using SFTP or Git.

However, you can also use WP-CLI through Terminus to install the plugin or theme from the source directly if there is a direct URL that can be used. The code below shows how to install Advanced Custom Fields from the Advanced Custom Fields site:

```bash
terminus wp <site>.<env> -- plugin install https://www.advancedcustomfields.com/latest/ --force
```

Adding the `--force` flag will ensure that the latest version of Advanced Custom Fields is installed even if a plugin with the same slug already exists on your site. (For more information, see the [WP-CLI documentation for `plugin install`](https://developer.wordpress.org/cli/commands/plugin/install/).

## Using Composer to source plugins and packages

Composer is a dependency manager for PHP similar to NPM for JavaScript projects.
A `composer.json` file can be dropped into any project (including an existing WordPress site) to download packages from a specific source.
Most often that package comes from a version-controlled repository (e.g. GitHub) through [Packagist](https://packagist.org).
The [Composer documentation provides guidance](https://getcomposer.org/doc/05-repositories.md) on how to add projects that may not already be Composer-based or set up in Packagist so that virtually any source can be added to a `composer.json` file.
For more information about using WordPress and Composer, refer to our [Integrated Composer documentation](https://docs.pantheon.io/guides/integrated-composer).
For an example of how to use a custom Composer repository for a premium plugin, see our [Object Cache Pro documentation for our WordPress (Composer Managed) upstream](https://docs.pantheon.io/object-cache/wordpress#installation-and-configuration-for-composer-managed-wordpress-sites).

For WordPress, [WPackagist.org](https://wpackagist.org) acts as a Composer-based mirror of the WordPress.org plugin and theme repository.
WPackagist allows Composer-based WordPress installs to require any plugin or theme that exists in the WordPress repository. Referencing plugins through WPackagist will pull code from WordPress.org.
For the purpose of this document, we will focus only on including packages from third-party sources.

### Adding a plugin from Packagist.org

Some packages, like our own [Pantheon Advanced Page Cache](https://github.com/pantheon-systems/pantheon-advanced-page-cache) plugin are distributed both through the [WordPress plugin repository](https://wordpress.org/plugins/pantheon-advanced-page-cache) and [Packagist](https://packagist.org/packages/pantheon-systems/pantheon-advanced-page-cache).

Before you start, make sure you have the `composer/installers` package in your `composer/json` file.
[`composer/installers`](https://packagist.org/packages/composer/installers) is a core Composer plugin that adds support for additional types of packages beyond the default package types.
In the context of WordPress and Composer, Installers adds support for the `wordpress-plugin`, `wordpress-theme` and `wordpress-muplugin` package types – which means that when packages of those types are installed via Composer, they are stored in `wp-content/plugins`, `wp-content/themes` or `wp-content/mu-plugins`, respectively (as opposed to the default `/vendor` folder for other Composer packages).

If you do not have the Installers package already installed, you can require it with composer using the following command:

```bash{promptUser: user}
composer require –dev composer/installers
```

Now, if you would like to source a Composer-based plugin through Packagist, you can do so by running `composer require <vendor>/<package>`, for example:

```bash{promptUser: user}
composer require pantheon-systems/pantheon-advanced-page-cache
```

You can use the search on Packagist.org to look for packages if you know the name of the plugin or the vendor (likely the plugin author) to see if there is built-in support for Composer-based installation.
However, Composer also supports other VCS-based sources or even static zip files. [Refer to the documentation](https://getcomposer.org/doc/05-repositories.md#vcs) for more information about those types of advanced configuration.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 39bd190

Please sign in to comment.