Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
# DOCKER_HTTPS_PORTS=443:443
# DOCKER_CONF_NGINX_PATH=./conf/dist/nginx-conf
# DOCKER_CONF_CERTS_PATH=./conf/dist/certs/
# DOCKER_CONF_PHP_PATH=./conf/dist/php-conf/upload.ini
# DOCKER_CONF_PHP_PATH=./conf/upload.ini
# DOCKER_CONF_INIT_PATH=./conf/init/

# DOCKER_WORDPRESS_MULTISITE_USE_SUBDOMAINS=false
# DOCKER_PHP_RESTART=unless-stopped

Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

/conf/*
!/conf/dist
!/conf/init
/conf/init/*
!/data/plugins
/data/plugins/*

/docker-compose.*.yml
!docker-compose.default.yml
Expand Down Expand Up @@ -95,3 +99,5 @@ package-lock.json

data/sql

!.gitkeep

29 changes: 28 additions & 1 deletion apps/init/init.lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,46 @@ is_plugin_installed() {
return $?
}

is_theme_installed() {
wp theme is-installed "$1" --allow-root
return $?
}

# Function to install and activate a plugin if not already installed
install_and_activate_plugin() {
local plugin_name="$1"
local plugin_slug="$2"
local plugin_source="$3"

if [ -z "$plugin_source" ]; then
plugin_source=$plugin_slug
fi

if ! is_plugin_installed "$plugin_slug"; then
echo "Installing and activating plugin: $plugin_name..."
wp plugin install "$plugin_slug" --activate --allow-root
wp plugin install "$plugin_source" --activate --allow-root
else
echo "Plugin $plugin_name is already installed."
fi
}

install_and_activate_theme() {
local theme_name="$1"
local theme_slug="$2"
local theme_source="$3"

if [ -z "$theme_source" ]; then
theme_source=$theme_slug
fi

echo "Installing and activating theme: $theme_name from $theme_source..."
if ! is_theme_installed "$theme_slug"; then
wp theme install "$theme_source" --activate --allow-root
else
echo "Theme $theme_name is already installed."
fi
}

# Special handling for plugin activations that should only be done once
handle_plugin_activation_once() {
local plugin_slug="$1"
Expand Down
49 changes: 39 additions & 10 deletions apps/init/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ error_handler() {
# Trap errors and call the error_handler function
trap 'error_handler' ERR

# List of plugins to install
# Array semplice con nome e slug separati da "|"
# List of plugins to install and activate
# Format: "Plugin Name|plugin-source"
# Source can be: slug (from WP repo), URL, or file path
plugins_install=(
"WooCommerce|woocommerce"
"WPGraphQL|wp-graphql"
Expand All @@ -19,11 +20,32 @@ plugins_install=(
"Advanced Custom Fields|advanced-custom-fields"
)

# List of plugins to activate only once
# List of themes to install
# Format: "Theme Name|theme-source"
# Source can be: slug (from WP repo), URL, or file path
themes_install=()

# List of plugins to activate only once (already present in container)
plugins_activate_only=(
"ACore WP Plugins|acore-wp-plugins"
)

# Load external plugin configurations from mounted directory
EXTERNAL_CONFIG_DIR="/conf/init"
if [ -d "$EXTERNAL_CONFIG_DIR" ]; then
echo "Loading external plugin configurations from $EXTERNAL_CONFIG_DIR..."

# Load all .conf files
for config_file in "$EXTERNAL_CONFIG_DIR"/*.conf; do
if [ -f "$config_file" ]; then
echo "Loading configuration from: $config_file"
source "$config_file"
fi
done
else
echo "No external plugin configurations found at $EXTERNAL_CONFIG_DIR. Using defaults only."
fi

CURPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Wait for the database to be available
Expand Down Expand Up @@ -65,26 +87,33 @@ if ! wp core is-installed --allow-root; then
fi
fi

wp maintenance-mode activate --allow-root
wp maintenance-mode activate --allow-root || echo "Maintenance mode already activated or failed to activate."

# Install and activate plugins
echo "Installing and activating plugins..."
echo "Installing and activating plugins & themes..."

source "$CURPATH/init.lib.sh"

# Install and activate each plugin in the list
for plugin in "${plugins_install[@]}"; do
# Dividi il nome e lo slug
IFS='|' read -r plugin_name plugin_slug <<< "$plugin"
# Split plugin name and source
IFS='|' read -r plugin_name plugin_slug plugin_source <<< "$plugin"

echo "Installing $plugin_name ($plugin_slug)..."
install_and_activate_plugin "$plugin_name" "$plugin_slug"
echo "Installing $plugin_name ($plugin_source)..."
install_and_activate_plugin "$plugin_name" "$plugin_slug" "$plugin_source"
done

# Install themes if any
for theme in "${themes_install[@]}"; do
IFS='|' read -r theme_name theme_slug theme_source <<< "$theme"
echo "Installing theme $theme_name ($theme_source)..."
install_and_activate_theme "$theme_name" "$theme_slug" "$theme_source"
done

# Handle Acore WP Plugins activation
for plugin in "${plugins_activate_only[@]}"; do
IFS='|' read -r plugin_name plugin_slug <<< "$plugin"

echo "Activating $plugin_name ($plugin_slug) only once..."
handle_plugin_activation_once "$plugin_slug"
done
Expand Down
2 changes: 2 additions & 0 deletions conf/init/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This directory is for external plugin configurations
# Third-party projects can mount their plugin configuration files here
Empty file added data/plugins/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ services:
- ./src/acore-wp-plugin:/var/www/html/wp-content/plugins/acore-wp-plugins
- ${DOCKER_WORDPRESS_SRC_PATH:-wordpress-src}:/var/www/html
- ./apps/init/:/usr/local/bin/acore-init/
- ${DOCKER_CONF_INIT_PATH:-./conf/init}:/conf/init:ro
env_file:
# environment variables are retrieved by this file
# NOTE: you can add more variables to the .env file but
Expand Down Expand Up @@ -96,6 +97,7 @@ services:
volumes:
- ${DOCKER_CONF_NGINX_PATH:-./conf/dist/nginx-conf}:/etc/nginx/conf.d/
- ${DOCKER_CONF_CERTS_PATH:-./conf/dist/certs/}:/etc/nginx/certs/
- ${DOCKER_CONF_CERTS_PATH:-./data/plugins/}:/tmp/plugins
- ./var/logs:/var/log/nginx
- ${DOCKER_WORDPRESS_SRC_PATH:-wordpress-src}:/var/www/html:ro
extra_hosts:
Expand Down
86 changes: 86 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,90 @@ NOTE: by default sql files will be exported inside the /data/sql folder

If you want to install the acore-wp-plugin as a standalone plugin, you can follow the instructions in the [acore-wp-plugin repository](https://github.com/azerothcore/acore-cms-wp-plugin).

## Plugin and Theme Configuration System (Docker only)

ACore CMS includes a flexible configuration system that allows you to install WordPress plugins and themes with docker initialization scripts (you can find them in the `/apps/init` directory).

### Configuration Directory

External configurations are loaded from the `/conf/init/` directory, which can be mounted from your host system. This directory should contain `.conf` files that define which plugins and themes to install and activate.

### Configuration Format

Create `.conf` files in your `conf/init/` directory with the following format:

```bash
#!/bin/bash

# Add plugins to install and activate
# Format: "Plugin Name|plugin-source"
# Source can be: slug (from WP repo), URL, or file path
plugins_install+=(
"WooCommerce|woocommerce"
"Custom Plugin|custom-plugin|https://example.com/plugin.zip"
"Local Plugin|local-plugin|/tmp/plugins/local-plugin.zip"
)

# Add themes to install and activate
# Format: "Theme Name|theme-source"
# Source can be: slug (from WP repo), URL, or file path
themes_install+=(
"Twenty Twenty-One|twentytwentyone"
"Custom Theme|custom-theme|https://example.com/theme.zip"
"Local Theme|local-theme|/tmp/themes/local-theme.zip"
)

# Add plugins to activate only (already present in container)
plugins_activate_only+=(
"Existing Plugin|existing-plugin-slug"
)
```

### Sources

The system supports multiple sources for plugins and themes:

1. **WordPress Repository**: Use the slug
```bash
plugins_install+=("WooCommerce|woocommerce")
themes_install+=("Twenty Twenty-One|twentytwentyone")
```

2. **URLs**: Direct download links to zip files
```bash
plugins_install+=("Plugin Name|plugin-slug|https://releases.example.com/plugin.zip")
themes_install+=("Theme Name|theme-slug|https://releases.example.com/theme.zip")
```

3. **Local Files**: Zip files mounted into the container
```bash
plugins_install+=("Local Plugin|local-plugin|/tmp/plugins/local-plugin.zip")
themes_install+=("Local Theme|local-theme|/tmp/themes/local-theme.zip")
```

### Local zip files

You can place your plugin or theme zip files in the `/data/plugins/` or `/data/themes/` folders (which are mounted as `/tmp/plugins` and `/tmp/themes` in the container) and reference them in your configuration:

```bash
#!/bin/bash

plugins_install+=(
"Custom Plugin|custom-plugin|https://example.com/plugin.zip"
"Local Plugin|local-plugin|/tmp/plugins/local-plugin.zip"
)

themes_install+=(
"Custom Theme|custom-theme|https://example.com/theme.zip"
"Local Theme|local-theme|/tmp/themes/local-theme.zip"
)
```

### Default Plugins and Themes

ACore CMS comes with a default set of plugins and themes that are always installed:
- Plugins: WooCommerce, WPGraphQL, WPGraphQL ACF, myCred, Advanced Custom Fields, ACore WP Plugins (activation only)
- Themes: None by default

External configurations add to or can override these defaults by modifying the `plugins_install`, `themes_install`, and `plugins_activate_only` arrays.