Skip to content

vuchkov/wordpress-custom-plugin-registers-gutenberg-block-and-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

The WordPress plugin repository is already moved to:

Please use the repo above^.


WordPress & Docker

Installation

Usage - custom plugin

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.json file 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.

Install WP-CLI Inside the WordPress Container

  • 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

Troubleshooting

  • 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

About

Dockerized Wordpress with custom plugin registers Gutenberg block and Rest API with ReactJS

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors