using composer to create manageable wordpress websites

Post on 13-Apr-2017

648 Views

Category:

Internet

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Using Composer to create manageable WordPress websites

Anna LadoshkinaWordCamp Europe, 24/06/2016

I’ve been making websites for NGOs for 7 years

@foralien bureau / Teplitsa. Technologies for social good

You may need it if…

You are developing websites on PHP (with WordPress)

You would like to use modern development tool

You would like to have more organized projects

You would like to start easily

You hear that buzzword all the time, but…

What’s dependency?

Suppose:

You have a project that depends on a number of libraries. Some of those libraries depend on other libraries.

Composer:

Enables you to declare the libraries you depend on. Finds out versions of packages and installs them (into your project)

How to install?

PHP 5.3.x and command line

Follow instruction at https://getcomposer.org/doc/00-intro.md

Add composer.json to the project folder

Composer.json?

$ composer init

{ "name": "foralien/my_pack", "description": "Test package", "authors": [ { "name": "Anna Ladoshkina", "email": "webdev@foralien.com" } ], "require": {}}

Where to find packages?

Composer-specific repositories https://packagist.org/

GitHub (other open-source repositories) https://github.com/

Create yourself author/package_name

packagist.org

Add them one by one…

$ composer config repositories.foo vcs https://github.com/foo/bar

$ composer require package

More on command-line interface: https://getcomposer.org/doc/03-cli.md

…or specify them all in composer.json

"repositories": [ { "type": "composer", "url" : "http://some-packagist.org" }, { "type": "vcs", "url": "https://github.com/username/repo" }, { "type": "artifact", "url": "local_folder/" } ],"require" : { "author/package": "1.0", "another_author/package" : "4.4"}

More on composer.json schema: https://getcomposer.org/doc/04-schema.md

$ composer install

Have some coffee and check /vendor folder

Even for WordPress?

What’s the problem?

Common WordPress website project

- core files - wp-config.php - wp-content/plugins

- wp-content/themes

- wp-content/languages - wp-content/uploads

A few questions to ask

What should be under version control?

- What are dependencies? - Where are Composer-compatible repositories? - What to do with vendor folder?

Give me an example

https://roots.io/ Bedrock - WordPress boilerplate

http://composer.rarst.net Unofficial companion to Composer documentation for WordPress developers

Step by step

Core is dependency

plugins languages

themes

What are dependencies?

Tune project structureWordPress in subfolder

https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

Move wp-content folder

https://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content_folder

In settings

In wp-config.php

define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/wp-content' );

define( 'WP_CONTENT_URL', '//domain.com/wp-content' );

WordPress specific repositories

core plugins

languages

Where are Composer-compatible repositories?

WordPress core at https://packagist.org/

Plugins at wpackagist.org

Language-packs at wp-languages.github.io

Local folder /artifacts

myproject/myplugin-2.0.zip

— plugins code — composer.json

Add them into composer.json

"repositories": [ { "type": "composer", "url" : "http://wpackagist.org" }, { "type": "composer", "url": "http://wp-languages.github.io" },]

Config custom paths for dependencies

core plugins

languages

What to do with vendor folder?

Paths in composer.json

"config" : { "vendor-dir": "wp-content/vendor", },"extra" : { "wordpress-install-dir": "core", "dropin-paths": { "wp-content/languages/":

["vendor:koodimonni-language"] }}

Finally add dependencies into…

…require or requires-dev sections

"require" : { "composer/installers" : "~1.0", "johnpbloch/wordpress" : ">=4.4", "wpackagist-plugin/wordpress-seo" : "@stable", "koodimonni-language/core-ru_ru" : "*" , "myproject/myplugin" : "2.0",},"require-dev" : { "wpackagist-plugin/menu-exporter" : "@stable", "wpackagist-plugin/wordpress-importer" : "@stable" }

$ composer install

composer.lock$ composer update

@foralien bureau / foralien.comThank you

Anna Ladoshkina

www.facebook.com/anna.ladoshkinawebdev@foralien.com

top related