Slide 1

Slide 1 text

Front End Workflow Automation for Theme and Plugin Development a.k.a. How to Make the Computer do the Boring Stuff

Slide 2

Slide 2 text

Milos Soskic Founder & Designer @ Citrus Mist citrus-mist.com @citrusmist

Slide 3

Slide 3 text

This is a DevOps talk

Slide 4

Slide 4 text

WTH !#?###?!????!

Slide 5

Slide 5 text

Designer talking DevOps! or why should you listen to me...

Slide 6

Slide 6 text

Small outfit I wear many hats 1 2 3 4 1 Created by Alex Berkowitz from the Noun Project 2 Created by Nicolas Molès from the Noun Project 3 Created by Evert Jan Boon from the Nount Project 4 Created by Norbert de Graaf from the Noun Project

Slide 7

Slide 7 text

2014 12 total WP installs 8 new 6 on shared hosting

Slide 8

Slide 8 text

… and I have a CompSci degree

Slide 9

Slide 9 text

WP projects mainly brochure type sites for small and medium businesses. Have an opinion on design Less so on build quality Even less on best practices Small changes end up taking time due to process – minify, concat, upload etc.

Slide 10

Slide 10 text

Even I think my time is better spent doing something else I want it, but I don't want to think about it too much

Slide 11

Slide 11 text

Do Some Work › Optmise Imgs, JS & CSS › Upload via FTP › Export DB › Upload DB › Search & Replace CodeKit () Transmit phpMyAdmin Search Replace }

Slide 12

Slide 12 text

4 Different pieces of software excluding text editor & graphics

Slide 13

Slide 13 text

Facepalm! Cognitively expensive Error prone Boring & cumbersome

Slide 14

Slide 14 text

There must be another way!

Slide 15

Slide 15 text

Requirements WP scaffolding LiveReload Preprocessing Code linting Theme scaffolding Theme asset optimising Plugin scaffolding Plugin asset optimising Install dev plugins Deploy to staging & proudction Conditional asset loading

Slide 16

Slide 16 text

Yeoman, Grunt, Bower & WP-CLI

Slide 17

Slide 17 text

Requirements WP scaffolding LiveReload Preprocessing Code linting Theme scaffolding Theme asset optimisation Plugin scaffolding Plugin asset optimisation Install dev plugins Deploy to staging & proudction Conditional asset loading •Solved •WIP

Slide 18

Slide 18 text

Am I just swapping one toolbox for another?

Slide 19

Slide 19 text

YES BUT Achieves much more Streamlined interface, albeit CLI

Slide 20

Slide 20 text

Yeoman: scaffolding – smart templates Grunt: task runner – automator Requires: node.js, PHP 5.3.2+, Cygwin on Win Bower: front-end pkg manager WP-CLI: mange WP from Terminal

Slide 21

Slide 21 text

WP scaffolding, LiveReload, Preprocessing, Code linting, Theme scaffolding, Theme asset optimisation 1 STEP

Slide 22

Slide 22 text

In The Terminal npm install -g yo generator-wordpress cd your-empty-folder yo wordpress Requires: node.js with npm Note the forked theme repo https://github.com/citrusmist/YeoPress

Slide 23

Slide 23 text

What Just Happened? DL-ed WordPress Created wp-config with nice defaults Initiated a git repo DL-ed a starter theme Made a first commit http://yourchosenurl.dev

Slide 24

Slide 24 text

There Is More Vagrant w/ puppet Custom dirs WP as submodule

Slide 25

Slide 25 text

In The Terminal: cd wp-content/themes/chosen_theme_name npm install grunt } Compile SASS LiveReload JSHint Uglify JS Also Supports: Compass, Stylus, RequireJS

Slide 26

Slide 26 text

Watching for changes

Slide 27

Slide 27 text

When a file is updated

Slide 28

Slide 28 text

grunt build }Compile SASS JSHint Uglify JS ImgMin SVGMin

Slide 29

Slide 29 text

Conditional asset loading 2 STEP

Slide 30

Slide 30 text

wp-config.php local staging production if (file_exists(dirname(__FILE__) . '/wp-config-local.php')) { // Local Environment define('WP_ENV', 'local'); define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); include(dirname(__FILE__) . '/wp-config-local.php'); } elseif (file_exists(dirname(__FILE__) . '/wp-config-staging.php')) { // Staging Environment define('WP_ENV', 'staging'); include(dirname(__FILE__) . '/wp-config-staging.php'); } elseif (file_exists(dirname(__FILE__) . '/wp-config-production.php' )) { // Production Environment define('WP_ENV', 'production'); include(dirname(__FILE__) . '/wp-config-production.php'); } { { {

Slide 31

Slide 31 text

wp-config-{env}.php define('DB_NAME', 'db_user'); define('DB_USER', 'db_pass'); define('DB_PASSWORD', 'yourSafePass'); define('DB_HOST', 'localhost'); $table_prefix = 'wp_';

Slide 32

Slide 32 text

functions.php if(WP_ENV == 'local') { wp_register_script('livereload', 'http://highrise.dev:35729/livereload.js?snipver=1', null, false, true ); wp_register_script('myplugin', get_bloginfo('template_url') . '/js/bespoke/myplugin.js', null, array('jquery'), true ); wp_register_script( 'main', get_bloginfo('template_url') . '/js/main.js', null, array('jquery', 'myplugin'), true ); wp_enqueue_script('livereload'); } elseif (WP_ENV == 'staging' || WP_ENV == 'production') { wp_register_script('main', get_bloginfo('template_url') . '/js/main.min.js', null, array('jquery'), true ); } wp_enqueue_script('main'); original optimised { {

Slide 33

Slide 33 text

vendor bower package store bespoke your plugins / modules main.js main / bootstrap file main.min.js above contents optimised }

Slide 34

Slide 34 text

Exclude wp-config-* from version control!

Slide 35

Slide 35 text

Deployment to staging and production 3 STEP

Slide 36

Slide 36 text

SERVER SETUP Passwordless SSH access from local machine ssh staging.url -username cd path/to/siteroot git clone -b develop git@github. com:user/reponame git-flow master: latest stable dev: stable dev feature/*: feature specific Staging • develop Production • master

Slide 37

Slide 37 text

In The Terminal cd path/to/wp git clone https://github.com/c10b10/wp-cli-deploy touch wp-cli.local.yml wp-cli.local.yml require: - wp-cli-deploy/deploy.php

Slide 38

Slide 38 text

wp-config-deploy.php define('STAGING_URL', 'your.staging.url'); define('STAGING_WP_PATH', '/path/to/wp/root'); define('STAGING_HOST', 'your.staginghost.com'); define('STAGING_USER', 'staging_user'); define('STAGING_PORT', '22'); define('STAGING_PATH', '/path/to/site/root'); define('STAGING_UPLOADS_PATH', '/path/to/uploads/folder'); define('STAGING_THEMES_PATH', '/path/to/themes/folder'); define('STAGING_PLUGINS_PATH', 'path/to/pluglins/folder'); define('STAGING_DB_HOST', 'localhost'); define('STAGING_DB_NAME', 'stage_db_name'); define('STAGING_DB_USER', 'stage_db_user'); define('STAGING_DB_PASSWORD', 'stage_db_pass'); define('STAGING_EXCLUDES', 'node_modules/');

Slide 39

Slide 39 text

Inlcude wp-config-deploy.php from wp-config.php

Slide 40

Slide 40 text

THE PAYOFF

Slide 41

Slide 41 text

In The Terminal wp deploy push staging --what=themes wp deploy push staging --what=plugins wp deploy push staging --what=uploads wp deploy pull staging --what=themes wp deploy pull staging --what=plugins wp deploy pull staging --what=uploads upload download { {

Slide 42

Slide 42 text

… and my favourites

Slide 43

Slide 43 text

wp deploy push staging --what=db Export local DB Search & replace Upload to server Substitute remote DB Export remote DB DL remote DB Search & replace Substitute local DB wp deploy pull staging --what=db } }

Slide 44

Slide 44 text

Mega useful for Checking your work over a real network (without having to commit) Testing on handhelds Working on site w/ content strategist Deployment on shared hosting (but not limited to)

Slide 45

Slide 45 text

WHERE NEXT? WP scaffolding LiveReload Preprocessing Code linting Theme scaffolding Theme asset optimisation Plugin scaffolding Plugin asset optimisation Install dev plugins Deploy to staging & proudction Conditional asset loading

Slide 46

Slide 46 text

WPZest Wrapper around YeoPress Automates steps 1-3 excl. server setup Plugin scaffolding based on WP Plugin Boilerplate Plugin asset optimisation (coming soon) https://github.com/artificer/ generator-wpzest Live demo at the pub?

Slide 47

Slide 47 text

Would love to hear your ideas about what should go in it

Slide 48

Slide 48 text

Resources YeoPress https://github.com/wesleytodd/YeoPress WP-CLI http://wp-cli.org WP-CLI-Deploy https://github.com/c10b10/wp-cli-deploy Bower http://bower.io Grunt http://gruntjs.com Yeoman http://yeoman.io WP Plugin Boilerplate https://github.com/tommcfarlin/WordPress- Plugin-Boilerplate

Slide 49

Slide 49 text

THANK YOU!