Applying patches to 3rd party WordPress plugins

I recently stumbled upon a bug in a third party plugin. I opened an issue on the wordpress.org support forum. I didn’t have much confidence in the author to fix the bug, as someone else mentioned the bug 1.5 years before. I needed a way to modify a 3rd party plugin’s codebase without manually having to apply the changes after each update/deploy.

I decided to fork the plugin repo and apply the changes myself. I opened a PR, but still had no confidence in the author to merge the PR anytime soon. I was searching for a way to automatically apply the changes to the plugin when deploying this website. I did some searching and found this composer package. To be able to apply the patch, we need a patch file obviously.

You can add .patch to the pull request’s url, and Github will automatically serve you the patch (https://github.com/hijiriworld/intuitive-custom-post-order/pull/46.patch).

We can now install the composer-patches package

composer require cweagans/composer-patches

We can then add the patch in our composer file:

...
"extra": {
  ...
  "patches": {
    "wpackagist-plugin/intuitive-custom-post-order": {
      "Fix for multisite": "https://github.com/hijiriworld/intuitive-custom-post-order/pull/46.patch"
    }
  }
},
...

Running composer install or composer update will now automatically apply the patch.

Geef een antwoord

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *

Overtuigd?

Neem dan contact op voor een offerte of vrijblijvend gesprek.
Stuur een e-mail naar [email protected] of maak gebruik van het contactformulier.