Please use the repo above^.
- Clone the repo:
git clone ... - Run docker:
docker-compose up -d - WordPress site: http://localhost:8000
- PhpMyAdmin: http://localhost:8080
The plugin folder is latest-posts-block in the wp-content/plugins directory.
Inside the folder are the following files:
latest-posts-block.php(main plugin file)build/index.js(ReactJS code for the Gutenberg block)build/index.asset.php(generated by WordPress build process)includes/rest-api.php(REST API endpoint)includes/block-registration.php(block registration logic)
Build the ReactJS Code:
- Install dependencies:
npm install @wordpress/scripts --save-dev - Add a
package.jsonfile with the following content:
{
"scripts": {
"build": "wp-scripts build",
"start": "wp-scripts start"
},
"devDependencies": {
"@wordpress/scripts": "^24.0.0"
}
}
- Run the build process:
npm run build
Test the Plugin:
- Activate the plugin in the WordPress admin dashboard.
- Add the "Latest Posts Block" to a page or post.
- Configure the number of posts to display using the block settings.
- Go to WP container
docker exec -it wordpress_app bash
- Install WP-CLI:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp
- Now you can use WP-CLI commands, for example:
wp core version
wp plugin list
- Remove the existing containers and restart everything:
docker-compose down -v # Stop and remove containers + volumes
docker volume prune -f # (optional) Remove Orphaned Volumes
docker-compose up -d # Start fresh
- Setup wp-config.php database setting:
docker exec -it wordpress_app bash
apt update && apt install nano -y
nano /var/www/html/wp-config.php
edit the DB settings, save, and restart the container:
docker-compose restart wordpress
#or
docker-compose restart
or Copy the File to Your Local Machine, Edit It, and Copy It Back:
docker cp wordpress_app:/var/www/html/wp-config.php ./wp-config.php
nano wp-config.php # Edit the file locally
docker cp wp-config.php wordpress_app:/var/www/html/wp-config.php
- Check DB & App logs:
docker logs wordpress_app # or wordpress_db
- Change permissions inside docker container:
docker exec -it wordpress_app bash
chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www/html
exit
docker-compose restart wordpress