Enpii Base
Enpii Base plugin to WordPress development, this requires ACF plugin to work
by dev@enpii.com, nptrac@yahoo.com · github.com/npbtrac/wp-plugin-enpii-base · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/npbtrac/wp-plugin-enpii-base/archive/refs/heads/master.zipReadme
Installation
- Commands to set up the development environment
cp .env.example .env docker pull composer docker run --rm --interactive --tty --volume $PWD:/app composer composer install docker-compose up -d - Run the WP CLI command to prepare the necessary things
docker-compose exec wordpress wp enpii-base prepare_wp_app
Explaination
dev-dockeris the folder for docker related stuffsdev-docker/wordpresswould be the document root for the webserver default host (it's/var/www/htmlin the container)- In the container
wordpressdevuseris the user to own the files and foldernobodyis ths user of the webserver (for uploading files or create files using the web requests)
Working with the containers
- To SSH to the wordpress containers
docker-compose exec --user=devuser wordpress sh
The local website will work with http://127.0.0.1:10108/ (or the port you put in env file)
Development
- Remember to enable git case sensitive for files
git config core.ignorecase false - Add
XDEBUG_MODE=offbeforecomposerto turn off XDebug to speedup the composer
Base concepts
- This plugin will create a laravel application
wp_app()(a DI container https://code.tutsplus.com/tutorials/digging-in-to-laravels-ioc-container--cms-22167) contains everything we need. - Each plugin or theme will act as a Service Provider https://laravel.com/docs/7.x/providers
- We are trying to implement Domain Driven Development (DDD) and Command Query Responsibility Segregation (CQRS)
- Each handler is a class (1 class only for 1 handler). An action may contain many hanlders.
Working with composer
- We should use
~1.0.3when require a package (only update if bugfixing released) - We use
mozart(https://packagist.org/packages/coenjacobs/mozart) package to put the dependencies to a separate folder for the plugin to avoid the conflicts- We should use
mozartglobally - After running
composer update, you need to runmozart compose(this should be run manually). If issues found related to some composer issues e.g. wrong included files, wrong path (due to the moving of files) ... you need to runcomposer update(orcomposer dump-autoload) one more time after fixingcomposer.jsonfile.
- We should use
- In case we want to upgrade laravel framework (it's a crazy thing), you need to add
"laravel/framework": "7.30.6"to the dependencies then remove that line andcomposer.lockafter running mozart then runcomposer updateagain.
Process to perform the composer and mozart:
- Remove the
autoload -> filespart in composer.json XDEBUG_MODE=off composer installorXDEBUG_MODE=off composer updatecomposer dump-autoloadmozart compose- Undo the removing
autoload -> files composer dump-autoload
Or you can do the alternative way
XDEBUG_MODE=off composer install --no-autoloaderorXDEBUG_MODE=off composer update --no-autoloadermozart composecomposer dump-autoload
After using mozart, remember to manually repair the namespace in:
LogManager, use namespaceas MonologParseLogConfiguration(same as above)Symfony\Component\Routing\Route, find the keywordcompiler_classand update that option value to the one with the namespace- Replace all
app()->wp_app(),collect()->wp_app_collect()
Naming Convention
- Spaces, indentation are defined in
.editorconfig - We follow WordPress conventions https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#naming-conventions
- Variables, functions, methods should be named in snake_eye rules e.g.
$current_date,get_latest_posts(not$currentDateorgetLatestPosts) - Classes, Traits, Interfaces, enum names should be named with capitalized words separated by underscores e.g.
Top_Gun,A_Simple_Payment_Gateway(notTopGunorASimplePaymentGateway)
- Variables, functions, methods should be named in snake_eye rules e.g.
- Running phpcs to find coding standard issues
- With docker (we need to use php 7.4 to avoid errors)
# Run the docker pull once if you haven't run that before docker pull npbtrac/php:7.4-x86 # For arm # docker pull npbtrac/php:7.4-arm docker run --rm --interactive --tty -v $PWD:/var/www/html npbtrac/php:7.4-arm ./vendor/bin/phpcs - Or if you have your executable php 7.4 on your machine (we need to use php 7.4 to avoid errors)
/path/to/your/php7.4/executable/file ./vendor/bin/phpcs
- With docker (we need to use php 7.4 to avoid errors)
- Running phpcbf to fix code style issues
- With docker (we need to use php 7.4 to avoid errors)
# Run the docker pull once if you haven't run that before docker pull serversideup/php:8.0-cli docker run --rm --interactive --tty -v $PWD:/var/www/html serversideup/php:8.0-cli ./vendor/bin/phpcbf <path-to-file-need-to-be-fixed> - Or if you have your executable php 7.4 on your machine (we need to use php 7.4 to avoid errors)
/path/to/your/php8.0/executable/file ./vendor/bin/phpcbf <path-to-file-need-to-be-fixed>Testing
- With docker (we need to use php 7.4 to avoid errors)
- To run unit test
composer codecept unit
Install plugins and themes via the WP Admin Dashbboard
-
We need to ensure needed folders are there (only run once)
docker compose exec --user=devuser wordpress mkdir -p /var/www/html/wp-content/uploads >/dev/null 2>&1 docker compose exec --user=devuser wordpress mkdir -p /var/www/html/wp-content/upgrade >/dev/null 2>&1 docker compose exec --user=devuser wordpress mkdir -p /var/www/html/wp-content/cache >/dev/null 2>&1 docker compose exec --user=devuser wordpress chmod -R 777 /var/www/html/wp-content/cache /var/www/html/wp-content/uploads /var/www/html/wp-content/upgrade -
To install plugins and themes via the Admin Dashboard, you need to follow these steps:
- Add this part to
wp-config.php(afterThat's all ...line)define( 'FS_METHOD', 'direct' ); define( 'FS_CHMOD_DIR', (0755 & ~ umask()) ); define( 'FS_CHMOD_FILE', (0644 & ~ umask()) ); - Allow the file writting folders first
For plugins:
docker compose exec --user=devuser wordpress chmod g+w /var/www/html/wp-content/plugins/
For themes:
docker compose exec --user=devuser wordpress chmod g+w /var/www/html/wp-content/themes/-
Start to perform plugins, themes installation
-
Revoke the write permission
docker compose exec --user=devuser wordpress chmod g-w /var/www/html/wp-content/plugins/ docker compose exec --user=devuser wordpress chmod g-w /var/www/html/wp-content/themes/ -
Remove the previous part added to
wp-config.php(item 1)
- Add this part to
License
The Enpii Base plugin is open-sourced software licensed under the MIT license.