Making use of Composer for WordPress Plugins or Themes

Every time someone finds ways to develop their development process easily with tools to support development, I think I love Composer, it shows the level of maturity of development I want. Application libraries and scripts are very easy to use.

The number of libraries  available in Packagist. is amazing. All of these can be included in the plugin Composer. Packagist is a large composer archive. Basically it collects all kinds of PHP packages that can be installed by the Composer. On the other hand, Composer handles dependency management that works together with applications.

This is a procedure that I took to make this WordPress plug-in compatible with Composer , so I can easily import it into your library third party. This article will show you how to install and get started with Composer on Ubuntu 16.04 LTS.

We’ll be using facebook/graph-sdk from main Packagist main composer repository and to install custom plug-ins as a composer dependencies from WPackagist throughout this example, before we download and install Composer, we need to make sure our server has all dependencies installed.

Install Composer dependencies:

Install Composer :

To test your installation, run and output looks like below:

The composer can now be used. You can add facebook / graph-sdk plugin dependencies from packagist.

When adding facebook / graph-sdk-plugin dependency, the composer.json file should should look similar to the example below.

To install / update dependencies user below commands

Now use facebook-SDK with WordPress plug-ins and themes like below example

If you want to use a plug-in or script (i.e. other than a packagist.) in a custom repository (i.e. wpackagist), add the composer.json to the repository and use the wpackagist-plugin or wpackagist-theme as the vendor’s name and execute the “composer update” to install dependencies, here the example composer.json file.

Finally, the composer is a great tool to speed up the development of WordPress projects. The problems that it solves often occur in most projects. like package or plugins dependency resolution, automatic package or plug-ins download, all package or plug-ins updates, etc.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.