Update README
This commit is contained in:
83
README.md
83
README.md
@@ -96,7 +96,7 @@ Run setup commands to install wordpress and required plugins with composer:
|
||||
|
||||
### Backend
|
||||
|
||||
- Project structure
|
||||
#### Project structure
|
||||
|
||||
Project structure is inspired with [Roots Bedrock structure](https://roots.io/bedrock/).
|
||||
|
||||
@@ -111,8 +111,8 @@ Project structure is inspired with [Roots Bedrock structure](https://roots.io/be
|
||||
├── vendor # → Composer packages (never edit)
|
||||
├── app # → wp-content equivalent
|
||||
│ ├── mu-plugins # → Must use plugins
|
||||
│ ├── plugins # → Plugins
|
||||
├── wiaas # → Our code goes here
|
||||
│ └── plugins # → Plugins
|
||||
│ ├── wiaas # → Our code goes here
|
||||
│ ├── themes # → Themes
|
||||
│ └── uploads # → Uploads
|
||||
├── wp-config.php # → Required by WP (never edit)
|
||||
@@ -131,41 +131,90 @@ This approach enables:
|
||||
- Secure passwords with [wp-password-bcrypt](https://github.com/roots/wp-password-bcrypt)
|
||||
- Composer as task runner for automatic wordpress db updates
|
||||
|
||||
- Dependencies management
|
||||
#### Dependencies management
|
||||
|
||||
Wordpress core (`"johnpbloch/wordpress"`) and wordpress plugins code are managed with `composer.json` file.
|
||||
|
||||
But using combination of [Composer scripts](https://getcomposer.org/doc/articles/scripts.md) and [WP CLI commands](https://developer.wordpress.org/cli/commands/)
|
||||
we can automate database updates as well (mainly plugin activation and db updates after plugin version change);
|
||||
|
||||
##### Adding new plugin
|
||||
For adding new plugin from wordpress official repo add `"wpackagist-plugin/{plugin_name}": "{plugin_version}"` to `composer.json`.
|
||||
|
||||
composer require wpackagist-plugin/{plugin_name} --version={plugin_version}
|
||||
|
||||
Then add package to `"activate-plugins"` composer script in `composer.json` file in order in which you wish them to be activated.
|
||||
|
||||
"scripts": {
|
||||
"activate-plugins": [
|
||||
...,
|
||||
wp plugin activate woocommerce {plugin_name}
|
||||
]
|
||||
}
|
||||
|
||||
If plugin exposes wp cli command for database updates add it to `"update-db"` composer script in `composer.json` file
|
||||
(ex: woocommerce plugin exposes `wp wc update` which will apply pending database plugins for woocommerce).
|
||||
Make sure that wiaas always applies its changes last.
|
||||
|
||||
"scripts": {
|
||||
"update-db": [
|
||||
"wp core update-db",
|
||||
"composer activate-plugins",
|
||||
...
|
||||
{add wp cli command here},
|
||||
"wp wiaas update-db"
|
||||
]
|
||||
}
|
||||
|
||||
For updating wordpress core or plugins, update version for package
|
||||
wordpress core database changes will be applied with `wp core update-db` cli command ).
|
||||
|
||||
After any of these actions run:
|
||||
|
||||
composer update # → Will download latest code
|
||||
composer update # → Will download latest code and update lock file
|
||||
composer update-db # → Activate plugins and calls all exposed wp cli commands for db updates
|
||||
|
||||
For removing plugin that has no db changes just remove it from composer.json and execute `composer update` which will remove its code;
|
||||
|
||||
##### Removing existing plugin
|
||||
|
||||
For removing plugin that has no db changes just remove it from composer.json with:
|
||||
|
||||
composer remove wpackagist-plugin/{plugin_name}
|
||||
|
||||
After that remove it from `"activate-plugins"` and `"update-db"` scripts.
|
||||
|
||||
If plugin has database changes that we wish to be removed that is oneoff migration that can be done from
|
||||
admin panel or using `wp plugin deactivate {plugin_name} && composer remove wpackagist-plugin/{plugin_name}` script.
|
||||
admin panel or using script:
|
||||
|
||||
wp plugin deactivate {plugin_name} && composer remove wpackagist-plugin/{plugin_name}
|
||||
|
||||
WP CLI is very powerful tool for writing automation scripts without need to track and copy mysql dumps.
|
||||
But if need arises we can think about using tool for db migration scripts.
|
||||
|
||||
- Wiaas plugin
|
||||
|
||||
Our code is placed inside `backend/app/plugins/wiaas` folder.
|
||||
This folder will be managed by git and commited to repository (check `backend/.gitignore`).
|
||||
|
||||
Wiaas exposes `wp wiaas update-db` command to WP CLI which will execute pending db updates for wiaas.
|
||||
##### Wiaas plugin
|
||||
|
||||
Our code is placed inside `backend/app/plugins/wiaas` folder.
|
||||
|
||||
###### Wiaas plugin folder structure:
|
||||
|
||||
├── includes # → Location for src files
|
||||
│ ├── cli # → CLI commands exposed to WP CLI
|
||||
│ └── db-updates # → DB updates
|
||||
│ ├── wiaas-db-updates-functions.php # → Contains functions for db updates
|
||||
├── wiaas.php # → Entry point
|
||||
|
||||
|
||||
This folder will be managed by git and commited to repository (check `backend/.gitignore`).
|
||||
|
||||
###### Wiaas plugin DB changes
|
||||
|
||||
Wiaas exposes WP CLI command which will execute pending db updates for wiaas:
|
||||
|
||||
wp wiaas update-db
|
||||
|
||||
|
||||
If your feature requires some database updates that can be easiliy executed from wordpress code, then:
|
||||
1) Place this update to `wiaas/includes/db-updates/wiaas-db-update-functions.php` as a function named `wiaas_db_update_{name}
|
||||
2) Add this function to `wiaas/includes/class-wiaas-db-update.php` with its timestamp.
|
||||
|
||||
If your feature requires some database updates that can be easiliy executed from wordpress code, then
|
||||
place this update to `wiaas/includes/db-updates/wiaas-db-update-functions.php` as a function named `wiaas_db_update_{name}`.
|
||||
Then add this function to `wiaas/includes/class-wiaas-db-update.php` with its timestamp.
|
||||
This way after `composer update-db` is executed your database update will be applied.
|
||||
|
||||
Reference in New Issue
Block a user