O SlideShare utiliza cookies para otimizar a funcionalidade e o desempenho do site, assim como para apresentar publicidade mais relevante aos nossos usuários. Se você continuar a navegar o site, você aceita o uso de cookies. Leia nosso Contrato do Usuário e nossa Política de Privacidade.
O SlideShare utiliza cookies para otimizar a funcionalidade e o desempenho do site, assim como para apresentar publicidade mais relevante aos nossos usuários. Se você continuar a utilizar o site, você aceita o uso de cookies. Leia nossa Política de Privacidade e nosso Contrato do Usuário para obter mais detalhes.
Custom code? Git is mandatory. Control: code’s history Onboard other developers.
Test updates => roll back
Git: All WP WordPress core Free plugins Premium plugins Custom theme and custom plugins … ignore Media Uploads and config
code changes locally, push to you remote repo pull on prod
Break git Impossible to fetch new code Force you to commit your files from server. No more testing locally before commiting to Git.
Suddenly, Git makes your life harder, not easier.
Let’s mess up the Git repository on a regular basis!
Most devs decide:
Not use auto updates even for security bug fixes Never click the admin panel Update button on server
We’ve used Git for all projects for 10 years.
Not auto updates.
But: WP is so widely used, that hackers attack
Fast security updates is crucial.
We tried to create an automated setup using the WP core auto update options.
But it didn’t play well with our Git setup :(
Also tested some plugins
Easy Updates Manager: select which plugins to auto update. But: It has no Git support.
We actually reached out with a Pull Request, but they decided to not go with it.
In Drupal, custom code is separated from contrib code
This means you can add one folder to Git, and ignore the other.
Also, Drupal has a shell – DRUSH. Dev tool for the terminal, just like WP-CLI.
Drush provides functionality to update your site using a single configuration file.
Before we continue:
It’s really nice.
What is a build file?
Often used by web apps. Complex dependencies. Or: it can help you maintain WP.
We created something similar, and we call it WP-CLI Build.
Open source package by Frontkom.
Name is not sexy. Not your wife – it’s a wp tool.
It’s a tool developers use with WP-CLI.
It’s on Github, so anyone can start using it today. LIke it? Star it?
How do we get started, Foad?
Well this tool is extending WP-CLI, so first you need to install wp-cli.
If you haven’t, go install WP CLI locally and on your server
Then run the package install command
Let’s look at what it can do for us.
Our tool has two main commands. The first: build-generate In the root of an existing WP website, run this command. It will generate your build file and a very special .gitignore file. What the files will look like, depends on your active plugins, theme and custom code.
Thanks to the “build-generate” command, it will list all active plugins and theme with their current version numbers. Then you can edit the version in the build file. Ask yourself how likely it is that an update will break the site, and proceed with one of four choices:
Latest version Latest patch within minor version Latest minor within major version 1 Fixed version – you rely on this version for critical API-stuff
And oh: it supports both Yaml and JSON formats, so you can use the format your are most comfortable with.
Another important file: .gitignore.
We wanted to : use the UI to quickly update plugins on server without messing up the Git repo. I even wanted to automate it.
The WP plugins folder is shared between custom plugins, premium plugins and free plugins.
How do you tell WP to ignore the free plugins and just Git index the custom ones? That is really hard, so we found a simpler solution:
Let’s create a negative .gitignore file that ignores absolutely everything.
build-generate creates a file with lots of rules.
The slash asterisk rule tells Git to literally ignore everything. Index nothing!
Then it carefully adds back in: your active custom plugins and custom theme.
You don’t need to remember this; it’s added automatically on build-generate.
If a .gitignore already exists, it will simply add this block above whatever is there.
Makes your Git repository pretty.
Before: A million files that are already maintained on wordpress.org.
Much fewer files: easy overview and maintenance. Central to goal of Git friendly auto updates.
The second command is: build
This will take your build file and download whatever it finds there.
it builds your site and brings it all together.
Enough theory: Demo time!
Show us how this helps us in real life, Foad.
Here we have an existing website deployed using FTP, we want to bring it to GIT
Let’s go into the root directory where WP website lives, run the command: build-generate and take the code to Github [play video]
The other use case is to install an instance on local machine or staging server or maybe deploy to production server.
First we clone GIT repository
Then run wp build command
Need to mention I’ve imported the database
Some of plugins are potential to have breaking changes, so they should be updated manually.
Here there is updates available for Timber Library
I’m updating it via WP command
Then test website if everything works and make sure don’t have any errors in our error log
Foad: It is time to automate the update process.
First we configure build.json file.
Then on the server, we create a shell command to run ‘wp build’. Don’t forget to give it correct permission. In this case, 755.
Then set up cron job using crontab command.
PA: To quote myself: This way of handling updates gives you:
A git friendly way to handle wp updates
A Git Friendly Way to
Handle WP Updates
Per André Rønsen, CTO & partner
Foad Yousefi, Developer