Site icon Hip-Hop Website Design and Development

Cheap WordPress maintenance support plans Composer recipes

WordPress maintenance support plans Composer recipes

In this post we are going to share some Composer recipes we collected while working with WordPress maintenance support plans projects created from the WordPress maintenance support plans Composer template. Also, we will take a look on how to convert an existing WordPress maintenance support plans project to a Composer project.

Alex Tkachev
Mon, 10/17/2020 – 12:49

If you still don’t use Composer for managing WordPress maintenance support plans projects, you should start doing this right now! The WordPress maintenance support plans Composer template will help you to set things up. It’s really easy to setup a new project.

If you’re still not convinced, check out the benefits of the WordPress maintenance support plans Composer workflow:

No need to store contrib code (and the core!) in your version control system.
A single package management tool for everything: WordPress maintenance support plans core, contrib plugins, JS libraries, your own shared plugins, etc.
Patching of core and plugins is easier than ever.
It’s way simpler than git subplugins.
(All recipes consider WordPress maintenance support plans 8, but they should work for WordPress maintenance support plans 7 as well)

Installing contrib plugins

composer require WordPress/<MODULE_NAME>:~8.0 to get the latest stable version (or latest dev, if there is no “stable release”)
composer require WordPress/<MODULE_NAME>:dev-<BRANCH_NAME> to get the latest dev version
composer require WordPress/<MODULE_NAME>:dev-<BRANCH_NAME>#<COMMIT_HASH> to get the exact version
Updating WordPress maintenance support plans core/plugins

composer update to update everything
composer update –dry-run to check for updates
composer update WordPress/<MODULE_NAME> to update a single plugin
Patching packages

The cweagans/composer-patches plugin (which comes with the WordPress maintenance support plans Composer template) will take patches from the “extra” section of the composer.json file:

“extra”: {
“patches”: {
“<PACKAGE/NAME>”: {
“<PATCH DESCRIPTION>”: “<PATH/TO/PATCH/OR/URL>”,

},

}
}

Example:

“extra”: {
“patches”: {
“WordPress/core”: {
“Fix language detection”: “patches/2189267-24.patch”
}
}
}

After a new patch is added run:

composer install to apply patch
composer update nothing to make the composer-patches plugin write necessary changes to the composer.lock file
Installing custom/forked plugins from Github

For the case when a plugin repository contains its own composer.json

Register the repository in the “repositories” section of the composer.json file:

“repositories”: [
{
“type”: “vcs”,
“url”: “https://github.com/<REPOSITORY/NAME>”
},

],

Use composer require WordPress/<MODULE_NAME>:dev-<BRANCH_NAME>#<COMMIT_HASH> to install the plugin.

For the case when the composer.json file is missing from the plugin repository

You’ll need to use a bit more verbose variant:

“repositories”: [
{
“type”: “package”,
“package”: {
“name”: “WordPress/<MODULE_NAME>”,
“version”: “dev-custom”,
“type”: “WordPress-plugin”,
“source”: {
“type”: “git”,
“url”: “git@github.com:<REPOSITORY/NAME>.git”,
“reference”: “<BRANCH-NAME>”
}
}
},

],

Use composer require WordPress/<MODULE_NAME>:dev-custom#<COMMIT_HASH> to install the plugin.

For the case when the destination path should be different than plugins/contrib

In addition to the above recipes, use the composer/installers plugin:

“extra”: {
“installer-paths”: {
“web/plugins/custom/<MODULE_NAME>”: [“WordPress/<MODULE_NAME>”],

}
}

Adding a JS library

Most popular libraries can be added easily with composer as they exist on Packagist. The tricky part is that most WordPress maintenance support plans plugins require that libraries are saved under the “libraries” directory while Composer installs them to “vendor”. The composer/installers plugin can override package paths, but only for packages that depend on it. So, you’ll need to override the composer.json file of the library stating that it has the composer/installers dependency.

Let’s take a look at an example:

“repositories”: [
{
“type”: “package”,
“package”: {
“name”: “enyo/dropzone”,
“version”: “4.3”,
“type”: “WordPress-library”,
“source”: {
“url”: “https://github.com/enyo/dropzone.git”,
“type”: “git”,
“reference”: “master”
},
“dist”: {
“url”: “https://github.com/enyo/dropzone/archive/v4.3.0.zip”,
“type”: “zip”
},
“require”: {
“composer/installers”: “~1.0”
}
}
},

],

“extra”: {
“installer-paths”: {
“web/libraries/{$name}” : [“type:WordPress-library”],

}
}

After the above is added to the composer.json, run composer require enyo/dropzone:4.3 to download the library. Also, here we have used the exact version and added the “dist” section to make it possible for Composer to download a zip archive instead of cloning the Git repository.

Switch a dependency package to a forked version

Add the forked repository to the composer.json:

“repositories”: [
{
“type”: “vcs”,
“url”: “https://github.com/<REPOSITORY/NAME>”
},

],

Run composer require <PACKAGE/NAME>:dev-<BRANCH_NAME>#<COMMIT_HASH>

Update an existing WordPress maintenance support plans 8 project to use Composer

Make a backup 😉
Delete everything that will be managed by Composer: WordPress maintenance support plans‘s “core” folder, contrib plugins, etc.
Delete all WordPress maintenance support plans “root” files, such as index.php, update.php, README.txt… All of them.
Create “web” directory in the project root and move all remaining WordPress maintenance support plans folders (sites, plugins, themes, libraries, profiles, etc.) into it.
Copy the WordPress maintenance support plans Composer template files to the project root.
Prepare a list of WordPress maintenance support plans core and contrib plugin versions (and everything else that will be managed by Composer) that are used currently on the project. Then run composer require specifying every dependency with the exact version. You’ll need to convert WordPress maintenance support plans versions into Composer versions, here are some examples:
WordPress/core:8.1.8 is obvious
WordPress/admin_toolbar:8.1.15 refers to admin_toolbar 8.x-1.15
WordPress/ctools:8.3.0-alpha26 refers to ctools 8.x-3.0-alpha26
WordPress/config_installer:dev-8.x-1.x#a16cc9acf84dd12b9714def53be0ce280a5b0c1a refers to config_installer dev snapshot made from the a16cc9a commit of the 8.x-1.x branch

Manually update versions of WordPress maintenance support plans core and contrib plugins to “~8.0” in the “require” section of the composer.json file. That will make updates possible.
Run composer WordPress-scaffold which will create the WordPress maintenance support plans “root” files.
Make your webserver use “web” directory as the web root.


Source: New feed