Introduction
Composer is a package manager for PHP and is widely used especially with PHP frameworks.
Composer offers the possibility to install PHP code from other sources (dependencies) to the own project and to manage the installed versions.
Although WordPress does not offer official support for Composer, it can still be used to install plugins, themes, and even the WordPress core in some setups, and manage updates.
The following guide explains how to install Borlabs Cookie to an existing Composer setup for WordPress. The installation of other Borlabs plugins may differ in individual cases, for example, Borlabs Cache and Borlabs Font Blocker do not require authentication. Below are examples of how to set up these plugins.
Instruction
The first thing to do is to add the repository. To do this, add the following code to the repositories
object in composer.json
.
"repositories": [
{
"type": "composer",
"url": "https://borlabs-cookie.composer.borlabs.io/composer"
}
]
After the repository is added, the actual dependency must be added in the require
object in composer.json
.
"require": {
"borlabs/borlabs-cookie": “^3",
}
The “^3" means that the composer update
will always update to the latest Borlabs cookie version.
For authentication, the Composer API key must now be stored.
The Composer API key can be viewed in the Borlabs Service Dashboard in the license detail page. (See screenshot)
If an auth.json
file is not yet created in the same folder as composer.json
, it must be created with the following content:
{
"http-basic": {
"borlabs-cookie.composer.borlabs.io": {
"username": "irrelevant",
"password": "YOUR-COMPOSER-API-KEY"
}
}
}
The YOUR-COMPOSER-API-KEY
placeholder must be replaced with the Composer API key from the Borlabs Service Dashboard.
auth.json
file must never be committed because it contains Secrets. After all this is completed, composer update
should install Borlabs Cookie in the latest version.
Configuration for each plugin
Array & Object Syntax
Our examples use array syntax, if you want to use object syntax instead, you need to modify our examples as follows:
Array
"require": {
"borlabs/borlabs-cache": "^1",
},
"repositories": [
{
"type": "composer",
"url": "https://borlabs-cache.composer.borlabs.io/composer"
}
]
Object
"require": {
"borlabs/borlabs-cache": "^1",
},
"repositories": {
"borlabs-cache": {
"type": "composer",
"url": "https://borlabs-cache.composer.borlabs.io/composer"
}
}
Borlabs Cache
composer.json:
"require": {
"borlabs/borlabs-cache": "^1",
},
"repositories": [
{
"type": "composer",
"url": "https://borlabs-cache.composer.borlabs.io/composer"
}
]
Borlabs Cookie
composer.json:
"require": {
"borlabs/borlabs-cookie": "^1",
},
"repositories": [
{
"type": "composer",
"url": "https://borlabs-cookie.composer.borlabs.io/composer"
}
]
auth.json:
{
"http-basic": {
"borlabs-cookie.composer.borlabs.io": {
"username": "irrelevant",
"password": "YOUR-COMPOSER-API-KEY"
}
}
}
Borlabs Font-Blocker
composer.json:
"require": {
"borlabs/borlabs-font-blocker": "^1",
},
"repositories": [
{
"type": "composer",
"url": "https://borlabs-font-blocker.composer.borlabs.io/composer"
}
]
Borlabs Opt-in for WPForms
composer.json:
"require": {
"borlabs/borlabs-opt-in-wpforms": "^1",
},
"repositories": [
{
"type": "composer",
"url": "https://borlabs-opt-in-wpforms.composer.borlabs.io/composer"
}
]
auth.json
{
"http-basic": {
"borlabs-opt-in-wpforms.composer.borlabs.io": {
"username": "irrelevant",
"password": "YOUR-COMPOSER-API-KEY"
}
}
}
Complete composer setup
This article only covers adding composer to an existing composer setup. If you want to start using composer for WordPress, we recommend this article: https://www.smashingmagazine.com/2019/03/composer-wordpress/