From f10180363deedae9688591689932ff8ad52c7b4a Mon Sep 17 00:00:00 2001 From: Sven Scharmentke <24257042+svnscha@users.noreply.github.com> Date: Sun, 30 Nov 2025 11:35:32 +0100 Subject: [PATCH 1/4] Updated packages (composer) --- composer.lock | 85 ++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 45 deletions(-) diff --git a/composer.lock b/composer.lock index 6082720..db3c10a 100644 --- a/composer.lock +++ b/composer.lock @@ -9,29 +9,29 @@ "packages-dev": [ { "name": "dealerdirect/phpcodesniffer-composer-installer", - "version": "v1.1.2", + "version": "v1.2.0", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/composer-installer.git", - "reference": "e9cf5e4bbf7eeaf9ef5db34938942602838fc2b1" + "reference": "845eb62303d2ca9b289ef216356568ccc075ffd1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/e9cf5e4bbf7eeaf9ef5db34938942602838fc2b1", - "reference": "e9cf5e4bbf7eeaf9ef5db34938942602838fc2b1", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/845eb62303d2ca9b289ef216356568ccc075ffd1", + "reference": "845eb62303d2ca9b289ef216356568ccc075ffd1", "shasum": "" }, "require": { "composer-plugin-api": "^2.2", "php": ">=5.4", - "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + "squizlabs/php_codesniffer": "^3.1.0 || ^4.0" }, "require-dev": { "composer/composer": "^2.2", "ext-json": "*", "ext-zip": "*", "php-parallel-lint/php-parallel-lint": "^1.4.0", - "phpcompatibility/php-compatibility": "^9.0", + "phpcompatibility/php-compatibility": "^9.0 || ^10.0.0@dev", "yoast/phpunit-polyfills": "^1.0" }, "type": "composer-plugin", @@ -101,31 +101,31 @@ "type": "thanks_dev" } ], - "time": "2025-07-17T20:45:56+00:00" + "time": "2025-11-11T04:32:07+00:00" }, { "name": "phpcsstandards/phpcsextra", - "version": "1.4.1", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", - "reference": "882b8c947ada27eb002870fe77fee9ce0a454cdb" + "reference": "b598aa890815b8df16363271b659d73280129101" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/882b8c947ada27eb002870fe77fee9ce0a454cdb", - "reference": "882b8c947ada27eb002870fe77fee9ce0a454cdb", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/b598aa890815b8df16363271b659d73280129101", + "reference": "b598aa890815b8df16363271b659d73280129101", "shasum": "" }, "require": { "php": ">=5.4", - "phpcsstandards/phpcsutils": "^1.1.2", - "squizlabs/php_codesniffer": "^3.13.4 || ^4.0" + "phpcsstandards/phpcsutils": "^1.2.0", + "squizlabs/php_codesniffer": "^3.13.5 || ^4.0.1" }, "require-dev": { "php-parallel-lint/php-console-highlighter": "^1.0", "php-parallel-lint/php-parallel-lint": "^1.4.0", - "phpcsstandards/phpcsdevcs": "^1.1.6", + "phpcsstandards/phpcsdevcs": "^1.2.0", "phpcsstandards/phpcsdevtools": "^1.2.1", "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" }, @@ -183,32 +183,32 @@ "type": "thanks_dev" } ], - "time": "2025-09-05T06:54:52+00:00" + "time": "2025-11-12T23:06:57+00:00" }, { "name": "phpcsstandards/phpcsutils", - "version": "1.1.2", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", - "reference": "b22b59e3d9ec8fe4953e42c7d59117c6eae70eae" + "reference": "d71128c702c180ca3b27c761b6773f883394f162" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/b22b59e3d9ec8fe4953e42c7d59117c6eae70eae", - "reference": "b22b59e3d9ec8fe4953e42c7d59117c6eae70eae", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/d71128c702c180ca3b27c761b6773f883394f162", + "reference": "d71128c702c180ca3b27c761b6773f883394f162", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", "php": ">=5.4", - "squizlabs/php_codesniffer": "^3.13.3 || ^4.0" + "squizlabs/php_codesniffer": "^3.13.5 || ^4.0.1" }, "require-dev": { "ext-filter": "*", "php-parallel-lint/php-console-highlighter": "^1.0", "php-parallel-lint/php-parallel-lint": "^1.4.0", - "phpcsstandards/phpcsdevcs": "^1.1.6", + "phpcsstandards/phpcsdevcs": "^1.2.0", "yoast/phpunit-polyfills": "^1.1.0 || ^2.0.0 || ^3.0.0" }, "type": "phpcodesniffer-standard", @@ -276,20 +276,20 @@ "type": "thanks_dev" } ], - "time": "2025-09-05T00:00:03+00:00" + "time": "2025-11-17T12:58:33+00:00" }, { "name": "squizlabs/php_codesniffer", - "version": "3.13.4", + "version": "3.13.5", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "ad545ea9c1b7d270ce0fc9cbfb884161cd706119" + "reference": "0ca86845ce43291e8f5692c7356fccf3bcf02bf4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/ad545ea9c1b7d270ce0fc9cbfb884161cd706119", - "reference": "ad545ea9c1b7d270ce0fc9cbfb884161cd706119", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/0ca86845ce43291e8f5692c7356fccf3bcf02bf4", + "reference": "0ca86845ce43291e8f5692c7356fccf3bcf02bf4", "shasum": "" }, "require": { @@ -306,11 +306,6 @@ "bin/phpcs" ], "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.x-dev" - } - }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" @@ -360,20 +355,20 @@ "type": "thanks_dev" } ], - "time": "2025-09-05T05:47:09+00:00" + "time": "2025-11-04T16:30:35+00:00" }, { "name": "wp-coding-standards/wpcs", - "version": "3.2.0", + "version": "3.3.0", "source": { "type": "git", "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", - "reference": "d2421de7cec3274ae622c22c744de9a62c7925af" + "reference": "7795ec6fa05663d716a549d0b44e47ffc8b0d4a6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/d2421de7cec3274ae622c22c744de9a62c7925af", - "reference": "d2421de7cec3274ae622c22c744de9a62c7925af", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/7795ec6fa05663d716a549d0b44e47ffc8b0d4a6", + "reference": "7795ec6fa05663d716a549d0b44e47ffc8b0d4a6", "shasum": "" }, "require": { @@ -381,17 +376,17 @@ "ext-libxml": "*", "ext-tokenizer": "*", "ext-xmlreader": "*", - "php": ">=5.4", - "phpcsstandards/phpcsextra": "^1.4.0", + "php": ">=7.2", + "phpcsstandards/phpcsextra": "^1.5.0", "phpcsstandards/phpcsutils": "^1.1.0", - "squizlabs/php_codesniffer": "^3.13.0" + "squizlabs/php_codesniffer": "^3.13.4" }, "require-dev": { "php-parallel-lint/php-console-highlighter": "^1.0.0", "php-parallel-lint/php-parallel-lint": "^1.4.0", - "phpcompatibility/php-compatibility": "^9.0", + "phpcompatibility/php-compatibility": "^10.0.0@dev", "phpcsstandards/phpcsdevtools": "^1.2.0", - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^8.0 || ^9.0" }, "suggest": { "ext-iconv": "For improved results", @@ -426,17 +421,17 @@ "type": "custom" } ], - "time": "2025-07-24T20:08:31+00:00" + "time": "2025-11-25T12:08:04+00:00" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { "php": ">=8.3" }, - "platform-dev": [], - "plugin-api-version": "2.6.0" + "platform-dev": {}, + "plugin-api-version": "2.9.0" } From 7d29a93c9579ab391af8fba42915587f32685569 Mon Sep 17 00:00:00 2001 From: Sven Scharmentke <24257042+svnscha@users.noreply.github.com> Date: Sun, 30 Nov 2025 10:58:44 +0000 Subject: [PATCH 2/4] Container Lifecycle Improved --- .devcontainer/Dockerfile | 1 + .devcontainer/devcontainer.json | 5 +-- .devcontainer/docker-compose.yml | 23 +++++++---- .devcontainer/post-create.sh | 70 ++++++++++++++++++++++++++++++-- 4 files changed, 84 insertions(+), 15 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 96720d7..b26ee22 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -15,6 +15,7 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ libzip-dev \ libxml2-dev \ libonig-dev \ + default-mysql-client \ && apt-get clean -y && rm -rf /var/lib/apt/lists/* # Install PHP extensions diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1bc31b1..a40921a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,8 +10,5 @@ ] } }, - "forwardPorts": [ - 24511 - ], "postCreateCommand": "bash .devcontainer/post-create.sh" -} \ No newline at end of file +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index ef13502..87368aa 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.8' - services: app: build: @@ -16,12 +14,18 @@ services: - type: volume source: vendor target: /workspace/vendor + - type: volume + source: wordpress_data + target: /var/www/html + - type: volume + source: wordpress_logs + target: /var/log/apache2 command: sleep infinity environment: - - MYSQL_HOST=db - - MYSQL_DATABASE=wordpress - - MYSQL_USER=wordpress - - MYSQL_PASSWORD=wordpress + - WORDPRESS_DB_HOST=db:3306 + - WORDPRESS_DB_NAME=wordpress + - WORDPRESS_DB_USER=wordpress + - WORDPRESS_DB_PASSWORD=wordpress wordpress: image: wordpress:php8.3-apache @@ -30,13 +34,15 @@ services: WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress WORDPRESS_DB_NAME: wordpress + WORDPRESS_DEBUG: 1 ports: - - "24511:80" + - "8000:80" depends_on: - db volumes: - wordpress_data:/var/www/html - - ../:/var/www/html/wp-content/plugins/template_wp_plugin:ro + - wordpress_logs:/var/log/apache2 + - ../:/var/www/html/wp-content/plugins/template-wp-plugin:ro db: image: mariadb:10.11 @@ -53,6 +59,7 @@ services: volumes: wordpress_data: + wordpress_logs: db_data: node_modules: vendor: diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index 75220a5..527868b 100644 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -1,6 +1,6 @@ #!/bin/bash -echo "Running post-create setup for WordPress Write AI Plugin..." +echo "Running post-create setup for WordPress Plugin..." # Change to workspace directory cd /workspace || exit 1 @@ -31,11 +31,75 @@ fi echo "Configuring git for dev container..." git config core.filemode false +# ======================================== +# Automated WordPress Installation +# ======================================== +echo "" +echo "Setting up WordPress..." + +# WordPress configuration +WP_URL="http://localhost:8000" +WP_TITLE="WordPress Dev" +WP_ADMIN_USER="admin" +WP_ADMIN_PASSWORD="admin" +WP_ADMIN_EMAIL="admin@example.com" + +# Wait for WordPress files to be available +echo "Waiting for WordPress files..." +attempt=0 +while [ ! -f "/var/www/html/wp-load.php" ]; do + attempt=$((attempt + 1)) + if [ $attempt -ge $max_attempts ]; then + echo "WordPress files not found after $max_attempts attempts, skipping WordPress setup." + exit 0 + fi + echo " Attempt $attempt/$max_attempts - waiting for WordPress files..." + sleep 2 +done +echo "WordPress files are ready!" + +# Check if WordPress is already installed +if wp core is-installed --path=/var/www/html --allow-root 2>/dev/null; then + echo "WordPress is already installed!" +else + # Install WordPress + echo "Installing WordPress..." + wp core install \ + --path=/var/www/html \ + --url="$WP_URL" \ + --title="$WP_TITLE" \ + --admin_user="$WP_ADMIN_USER" \ + --admin_password="$WP_ADMIN_PASSWORD" \ + --admin_email="$WP_ADMIN_EMAIL" \ + --skip-email \ + --allow-root + + if [ $? -eq 0 ]; then + echo "WordPress installed successfully!" + else + echo "WordPress installation failed. You may need to install manually." + fi +fi + +# Remove default plugins (Akismet and Hello Dolly) +echo "Removing default plugins..." +wp plugin delete akismet hello --path=/var/www/html --allow-root 2>/dev/null || true + +# Activate the plugin if it exists +PLUGIN_DIR="/var/www/html/wp-content/plugins/template-wp-plugin" +if [ -d "$PLUGIN_DIR" ]; then + echo "Activating plugin..." + wp plugin activate template-wp-plugin --path=/var/www/html --allow-root 2>/dev/null || true +fi + echo "" echo "==========================================" -echo "WordPress Write AI Plugin Development Environment Ready!" +echo "WordPress Plugin Development Environment Ready!" echo "==========================================" -echo "WordPress Site: http://localhost:24511" +echo "WordPress Site: $WP_URL" +echo "Admin URL: $WP_URL/wp-admin" +echo "Admin User: $WP_ADMIN_USER" +echo "Admin Password: $WP_ADMIN_PASSWORD" echo "" echo "Available tools:" echo "- PHP $(php --version | head -n1)" From 390c208203123103788f67298a5a3a805e75c1c3 Mon Sep 17 00:00:00 2001 From: Sven Scharmentke <24257042+svnscha@users.noreply.github.com> Date: Sun, 30 Nov 2025 12:09:07 +0100 Subject: [PATCH 3/4] Updated --- .devcontainer/post-create.sh | 2 ++ .github/prompts/ws-release.prompt.md | 2 +- .github/workflows/ci.yml | 2 +- .github/workflows/release.yml | 4 ++-- AGENTS.md | 4 ++-- README.md | 4 ++-- phpcs.xml | 11 ++++++++++- scripts/validate-versions.sh | 6 +++--- wp-plugin.php => template-wp-plugin.php | 0 9 files changed, 23 insertions(+), 12 deletions(-) rename wp-plugin.php => template-wp-plugin.php (100%) diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index 527868b..04101e3 100644 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -8,6 +8,7 @@ cd /workspace || exit 1 # Ensure proper ownership of volume directories echo "Setting up directory permissions..." sudo chown -R vscode:www-data /workspace/node_modules /workspace/vendor 2>/dev/null || true +sudo chown -R vscode:www-data /var/www/html 2>/dev/null || true # Install PHP dependencies via Composer echo "Installing PHP dependencies..." @@ -83,6 +84,7 @@ fi # Remove default plugins (Akismet and Hello Dolly) echo "Removing default plugins..." +wp plugin deactivate akismet hello --path=/var/www/html --allow-root 2>/dev/null || true wp plugin delete akismet hello --path=/var/www/html --allow-root 2>/dev/null || true # Activate the plugin if it exists diff --git a/.github/prompts/ws-release.prompt.md b/.github/prompts/ws-release.prompt.md index ce13727..4e171aa 100644 --- a/.github/prompts/ws-release.prompt.md +++ b/.github/prompts/ws-release.prompt.md @@ -37,7 +37,7 @@ Version Update Process: - Add new version entry with current date - Include all changes since last release - Categorize changes (Added, Changed, Deprecated, Removed, Fixed, Security) -2. Check current version in `wp-plugin.php` header +2. Check current version in `template-wp-plugin.php` header 3. If version in file doesn't match the new tag, update the Plugin Version header 4. Commit any version and changelog updates before creating the tag 5. Create the annotated git tag diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc20b87..f06f82d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -96,6 +96,6 @@ jobs: - name: Upload plugin artifact uses: actions/upload-artifact@v5 with: - name: wp-plugin + name: template-wp-plugin path: release/ retention-days: 30 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ae333b0..860959a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,12 +36,12 @@ jobs: ./scripts/validate-versions.sh - name: Create release archive - run: ./scripts/build-plugin.sh release wp-plugin.zip + run: ./scripts/build-plugin.sh release template-wp-plugin.zip - name: Create GitHub Release uses: softprops/action-gh-release@v2 with: - files: wp-plugin.zip + files: template-wp-plugin.zip generate_release_notes: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/AGENTS.md b/AGENTS.md index 3ce3b4a..af76838 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -20,7 +20,7 @@ This template follows absolute minimalism - start simple, add complexity only wh ## Minimal Plugin Structure Keep it simple: -- Single main plugin file: `wp-plugin.php` +- Single main plugin file: `template-wp-plugin.php` - Basic activation/deactivation hooks only - No complex class architecture unless required - No admin pages, assets, or translations unless needed @@ -28,7 +28,7 @@ Keep it simple: ## Development Workflow 1. Copy this template for new plugins -2. Rename main plugin file: `wp-plugin.php` → `your-plugin.php` +2. Rename main plugin file: `template-wp-plugin.php` → `your-plugin.php` 3. Update plugin headers (name, description, author) 4. Install dev dependencies: `composer install` 5. Add functionality incrementally as needed diff --git a/README.md b/README.md index ae5dc99..e58a2b8 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ cd my-new-plugin ### 2. Customize Your Plugin -1. **Rename the main plugin file**: `wp-plugin.php` → `your-plugin-name.php` +1. **Rename the main plugin file**: `template-wp-plugin.php` → `your-plugin-name.php` 2. **Update plugin headers** in your renamed file: - `Template WordPress Plugin` → `Your Plugin Name` @@ -76,7 +76,7 @@ your-plugin-name/ ├── composer.lock # Dependency lock file ├── LICENSE # AGPL-3.0-or-later license ├── README.md # This file -├── wp-plugin.php # Main plugin file (rename this) +├── template-wp-plugin.php # Main plugin file (rename this) └── vendor/ # Composer dependencies (after install) ``` diff --git a/phpcs.xml b/phpcs.xml index dfabcd7..06b521a 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -21,5 +21,14 @@ + + + + + + + + + - \ No newline at end of file + diff --git a/scripts/validate-versions.sh b/scripts/validate-versions.sh index 25f1771..8312661 100755 --- a/scripts/validate-versions.sh +++ b/scripts/validate-versions.sh @@ -2,14 +2,14 @@ set -e # Get main version from plugin header -VERSION=$(grep -oP "Version:\s*\K[\d\.]+" wp-plugin.php) +VERSION=$(grep -oP "Version:\s*\K[\d\.]+" template-wp-plugin.php) ERRORS=0 echo "Checking version consistency: $VERSION" # Check version constant (if exists) -if grep -q "define.*VERSION" wp-plugin.php; then - CONST_VERSION=$(grep -oP "define\s*\([^']*'[^']*VERSION[^']*',\s*'\K[\d\.]+" wp-plugin.php) +if grep -q "define.*VERSION" template-wp-plugin.php; then + CONST_VERSION=$(grep -oP "define\s*\([^']*'[^']*VERSION[^']*',\s*'\K[\d\.]+" template-wp-plugin.php) if [ "$VERSION" != "$CONST_VERSION" ]; then echo "❌ Plugin constant: $CONST_VERSION (should be $VERSION)" ERRORS=$((ERRORS + 1)) diff --git a/wp-plugin.php b/template-wp-plugin.php similarity index 100% rename from wp-plugin.php rename to template-wp-plugin.php From 0fbad74bafb97dc09fb41a17cf11a95c5dd6fa50 Mon Sep 17 00:00:00 2001 From: Sven Scharmentke <24257042+svnscha@users.noreply.github.com> Date: Sun, 30 Nov 2025 12:15:18 +0100 Subject: [PATCH 4/4] Script --- AGENTS.md | 22 ++- README.md | 77 +++++++++- scripts/init-repo.py | 346 +++++++++++++++++++++++++++++++++++++++++++ template.json | 34 +++++ 4 files changed, 470 insertions(+), 9 deletions(-) create mode 100644 scripts/init-repo.py create mode 100644 template.json diff --git a/AGENTS.md b/AGENTS.md index af76838..becee13 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -4,6 +4,22 @@ This template follows absolute minimalism - start simple, add complexity only when needed. +## Template Initialization + +For new plugins based on this template, use the automated initialization: + +1. Edit `template.json` with your plugin details +2. Run `python3 scripts/init-repo.py --dry-run` to preview changes +3. Run `python3 scripts/init-repo.py` to apply changes (resets changelog by default) +4. Add `--keep-changelog` flag to preserve existing changelog + +The `template.json` file contains all configurable values: +- Plugin name, slug, description, version, URI +- Author name and URI +- PHP namespace, function prefix, constant prefix +- Composer package name +- GitHub owner and repository + ## Code Standards ### PHP Code Quality @@ -27,9 +43,9 @@ Keep it simple: ## Development Workflow -1. Copy this template for new plugins -2. Rename main plugin file: `template-wp-plugin.php` → `your-plugin.php` -3. Update plugin headers (name, description, author) +1. Clone/fork this template for new plugins +2. Edit `template.json` with your plugin details +3. Run `python3 scripts/init-repo.py` to rebrand 4. Install dev dependencies: `composer install` 5. Add functionality incrementally as needed 6. Run `composer run lint` before commits diff --git a/README.md b/README.md index e58a2b8..cb352bd 100644 --- a/README.md +++ b/README.md @@ -20,20 +20,78 @@ Click "Use this template" on GitHub or clone this repository: ```bash git clone https://github.com/liasoft/template-wp-plugin.git my-new-plugin cd my-new-plugin +rm -rf .git && git init # Start fresh git history ``` -### 2. Customize Your Plugin +### 2. Customize Your Plugin (Automated) + +The easiest way to customize this template is using the initialization script: + +1. **Edit `template.json`** with your plugin details: + +```json +{ + "plugin": { + "name": "My Awesome Plugin", + "slug": "my-awesome-plugin", + "description": "Does awesome things for WordPress.", + "version": "1.0.0", + "uri": "https://github.com/yourname/my-awesome-plugin" + }, + "author": { + "name": "Your Name", + "uri": "https://yourwebsite.com" + }, + "php": { + "namespace": "MyAwesomePlugin", + "function_prefix": "my_awesome_plugin", + "constant_prefix": "MY_AWESOME_PLUGIN" + }, + "composer": { + "name": "yourname/my-awesome-plugin" + }, + "github": { + "owner": "yourname", + "repo": "my-awesome-plugin" + } +} +``` + +2. **Run the initialization script**: + +```bash +# Preview changes (dry run) +python scripts/init-repo.py --dry-run + +# Apply changes (resets changelog by default) +python scripts/init-repo.py + +# Apply changes but keep existing changelog +python scripts/init-repo.py --keep-changelog +``` + +The script will: +- Replace all template placeholders across all files +- Rename `template-wp-plugin.php` to `your-plugin-slug.php` +- Update version validation scripts +- Reset the changelog for a fresh start (use `--keep-changelog` to preserve it) + +### 2b. Customize Your Plugin (Manual) + +Alternatively, you can manually customize: 1. **Rename the main plugin file**: `template-wp-plugin.php` → `your-plugin-name.php` 2. **Update plugin headers** in your renamed file: - `Template WordPress Plugin` → `Your Plugin Name` - `A minimal boilerplate for WordPress plugins` → `Your plugin description` - - `Your Name` → Your actual name - - `https://yourwebsite.com` → Your website URL + - `Liasoft GmbH` → Your name + - Update all URLs to your repository 3. **Update function names** to match your plugin (replace `template_wp_plugin` prefix) +4. **Update these files**: `composer.json`, `README.md`, `CHANGELOG.md`, `phpcs.xml` + ### 3. Install Development Dependencies @@ -69,14 +127,21 @@ composer run lint:fix your-plugin-name/ ├── .editorconfig # Editor configuration ├── .github/ # GitHub configuration -│ └── prompts/ # Copilot workspace prompt files +│ ├── prompts/ # Copilot workspace prompt files +│ └── workflows/ # CI/CD workflows ├── .gitignore # Git ignore rules +├── assets/ # Plugin assets (banner, icons) +├── scripts/ # Development scripts +│ ├── build-plugin.sh # Build and package plugin +│ ├── init-repo.py # Template initialization script +│ └── validate-versions.sh # Version consistency checker ├── phpcs.xml # WordPress Coding Standards config ├── composer.json # PHP dependencies and scripts ├── composer.lock # Dependency lock file -├── LICENSE # AGPL-3.0-or-later license +├── template.json # Template configuration (edit this first!) +├── LICENSE # GPL-3.0-or-later license ├── README.md # This file -├── template-wp-plugin.php # Main plugin file (rename this) +├── template-wp-plugin.php # Main plugin file (rename this) └── vendor/ # Composer dependencies (after install) ``` diff --git a/scripts/init-repo.py b/scripts/init-repo.py new file mode 100644 index 0000000..9f88648 --- /dev/null +++ b/scripts/init-repo.py @@ -0,0 +1,346 @@ +#!/usr/bin/env python3 +""" +WordPress Plugin Template Initialization Script + +This script reads configuration from template.json and applies it to all +relevant files in the repository, effectively "rebranding" the plugin template. + +Usage: + 1. Clone the template repository + 2. Edit template.json with your plugin details + 3. Run: python scripts/init-repo.py + 4. (Optional) Run with --dry-run to preview changes without applying them + 5. (Optional) Run with --keep-changelog to preserve existing changelog +""" + +import json +import os +import re +import sys +import shutil +from pathlib import Path +from datetime import datetime + + +# Default template values (what we're replacing FROM) +TEMPLATE_DEFAULTS = { + "plugin": { + "name": "Template WordPress Plugin", + "slug": "template-wp-plugin", + "description": "A minimal boilerplate for WordPress plugins.", + "version": "1.0.3", + "uri": "https://github.com/liasoft/template-wp-plugin" + }, + "author": { + "name": "Liasoft GmbH", + "uri": "https://github.com/liasoft/template-wp-plugin" + }, + "php": { + "namespace": "TemplateWPPlugin", + "function_prefix": "template_wp_plugin", + "constant_prefix": "TEMPLATE_PLUGIN" + }, + "composer": { + "name": "liasoft/template-wp-plugin" + }, + "github": { + "owner": "liasoft", + "repo": "template-wp-plugin" + } +} + +# Files to process (relative to repo root) +FILES_TO_PROCESS = [ + "template-wp-plugin.php", # Main plugin file (will be renamed) + "README.md", + "CHANGELOG.md", + "composer.json", + "phpcs.xml", + "scripts/validate-versions.sh", + "scripts/build-plugin.sh", + ".github/workflows/ci.yml", + ".github/workflows/release.yml", +] + +# Files to skip during processing +FILES_TO_SKIP = [ + "template.json", + "scripts/init-repo.py", + "vendor/", + ".git/", + "node_modules/", +] + + +def load_config(config_path: Path) -> dict: + """Load the template.json configuration file.""" + if not config_path.exists(): + print(f"❌ Error: {config_path} not found!") + print("Please create template.json with your plugin configuration.") + sys.exit(1) + + with open(config_path, 'r', encoding='utf-8') as f: + return json.load(f) + + +def build_replacements(config: dict) -> list[tuple[str, str]]: + """Build a list of (old_value, new_value) replacement tuples.""" + defaults = TEMPLATE_DEFAULTS + replacements = [] + + # Plugin replacements + if config.get("plugin", {}).get("name") != defaults["plugin"]["name"]: + replacements.append((defaults["plugin"]["name"], config["plugin"]["name"])) + + if config.get("plugin", {}).get("slug") != defaults["plugin"]["slug"]: + replacements.append((defaults["plugin"]["slug"], config["plugin"]["slug"])) + + if config.get("plugin", {}).get("description") != defaults["plugin"]["description"]: + replacements.append((defaults["plugin"]["description"], config["plugin"]["description"])) + + if config.get("plugin", {}).get("uri") != defaults["plugin"]["uri"]: + replacements.append((defaults["plugin"]["uri"], config["plugin"]["uri"])) + + # Author replacements + if config.get("author", {}).get("name") != defaults["author"]["name"]: + replacements.append((defaults["author"]["name"], config["author"]["name"])) + + if config.get("author", {}).get("uri") != defaults["author"]["uri"]: + replacements.append((defaults["author"]["uri"], config["author"]["uri"])) + + # PHP naming replacements + if config.get("php", {}).get("namespace") != defaults["php"]["namespace"]: + replacements.append((defaults["php"]["namespace"], config["php"]["namespace"])) + + if config.get("php", {}).get("function_prefix") != defaults["php"]["function_prefix"]: + replacements.append((defaults["php"]["function_prefix"], config["php"]["function_prefix"])) + + if config.get("php", {}).get("constant_prefix") != defaults["php"]["constant_prefix"]: + replacements.append((defaults["php"]["constant_prefix"], config["php"]["constant_prefix"])) + + # Composer replacements + if config.get("composer", {}).get("name") != defaults["composer"]["name"]: + replacements.append((defaults["composer"]["name"], config["composer"]["name"])) + + # GitHub replacements + github_old = f"{defaults['github']['owner']}/{defaults['github']['repo']}" + github_new = f"{config.get('github', {}).get('owner', defaults['github']['owner'])}/{config.get('github', {}).get('repo', defaults['github']['repo'])}" + if github_old != github_new: + replacements.append((github_old, github_new)) + + return replacements + + +def should_skip_file(file_path: Path, repo_root: Path) -> bool: + """Check if a file should be skipped.""" + rel_path = str(file_path.relative_to(repo_root)) + + for skip_pattern in FILES_TO_SKIP: + if rel_path.startswith(skip_pattern) or skip_pattern in rel_path: + return True + + return False + + +def process_file(file_path: Path, replacements: list[tuple[str, str]], dry_run: bool = False) -> int: + """Process a single file with replacements. Returns count of replacements made.""" + if not file_path.exists(): + return 0 + + try: + with open(file_path, 'r', encoding='utf-8') as f: + content = f.read() + except UnicodeDecodeError: + # Skip binary files + return 0 + + original_content = content + replacement_count = 0 + + for old_value, new_value in replacements: + if old_value in content: + count = content.count(old_value) + content = content.replace(old_value, new_value) + replacement_count += count + + if content != original_content: + if not dry_run: + with open(file_path, 'w', encoding='utf-8') as f: + f.write(content) + return replacement_count + + return 0 + + +def rename_main_plugin_file(repo_root: Path, old_slug: str, new_slug: str, dry_run: bool = False) -> bool: + """Rename the main plugin file if slug changed.""" + old_file = repo_root / f"{old_slug}.php" + new_file = repo_root / f"{new_slug}.php" + + if old_file.exists() and old_slug != new_slug: + if not dry_run: + shutil.move(old_file, new_file) + return True + return False + + +def update_version_script(repo_root: Path, old_slug: str, new_slug: str, dry_run: bool = False) -> bool: + """Update the validate-versions.sh script with new plugin filename.""" + script_path = repo_root / "scripts" / "validate-versions.sh" + + if not script_path.exists(): + return False + + with open(script_path, 'r', encoding='utf-8') as f: + content = f.read() + + old_filename = f"{old_slug}.php" + new_filename = f"{new_slug}.php" + + if old_filename in content: + content = content.replace(old_filename, new_filename) + if not dry_run: + with open(script_path, 'w', encoding='utf-8') as f: + f.write(content) + return True + + return False + + +def reset_changelog(repo_root: Path, config: dict, dry_run: bool = False) -> None: + """Reset CHANGELOG.md for a fresh start.""" + changelog_path = repo_root / "CHANGELOG.md" + plugin_name = config.get("plugin", {}).get("name", "My Plugin") + version = config.get("plugin", {}).get("version", "1.0.0") + date = datetime.now().strftime("%Y-%m-%d") + + new_changelog = f"""# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [{version}] - {date} + +### Initial Release + +First release of {plugin_name}. + +#### Features + +- Initial plugin setup +""" + + if not dry_run: + with open(changelog_path, 'w', encoding='utf-8') as f: + f.write(new_changelog) + + +def find_all_files(repo_root: Path) -> list[Path]: + """Find all text files to process.""" + files = [] + + for file_path in repo_root.rglob('*'): + if file_path.is_file() and not should_skip_file(file_path, repo_root): + # Check for common text file extensions + if file_path.suffix in ['.php', '.md', '.json', '.xml', '.yml', '.yaml', '.sh', '.txt', '.css', '.js']: + files.append(file_path) + + return files + + +def main(): + """Main initialization routine.""" + # Parse arguments + dry_run = '--dry-run' in sys.argv + keep_changelog = '--keep-changelog' in sys.argv + + if dry_run: + print("🔍 DRY RUN MODE - No files will be modified\n") + + # Determine repo root (script is in scripts/) + script_dir = Path(__file__).parent.resolve() + repo_root = script_dir.parent + + print(f"📁 Repository root: {repo_root}") + print() + + # Load configuration + config_path = repo_root / "template.json" + config = load_config(config_path) + + print("📋 Configuration loaded from template.json") + print(f" Plugin Name: {config.get('plugin', {}).get('name', 'N/A')}") + print(f" Plugin Slug: {config.get('plugin', {}).get('slug', 'N/A')}") + print(f" Author: {config.get('author', {}).get('name', 'N/A')}") + print() + + # Build replacements + replacements = build_replacements(config) + + if not replacements: + print("ℹ️ No changes detected - template.json matches defaults.") + print(" Edit template.json with your plugin details and run again.") + return + + print(f"🔄 Found {len(replacements)} replacement(s) to make:") + for old_val, new_val in replacements: + # Truncate long values for display + old_display = old_val[:40] + "..." if len(old_val) > 40 else old_val + new_display = new_val[:40] + "..." if len(new_val) > 40 else new_val + print(f" '{old_display}' → '{new_display}'") + print() + + # Find and process all files + files = find_all_files(repo_root) + total_replacements = 0 + modified_files = [] + + print("📝 Processing files...") + for file_path in files: + count = process_file(file_path, replacements, dry_run) + if count > 0: + rel_path = file_path.relative_to(repo_root) + modified_files.append(str(rel_path)) + total_replacements += count + print(f" ✓ {rel_path} ({count} replacement(s))") + + # Rename main plugin file if needed + old_slug = TEMPLATE_DEFAULTS["plugin"]["slug"] + new_slug = config.get("plugin", {}).get("slug", old_slug) + + if old_slug != new_slug: + if rename_main_plugin_file(repo_root, old_slug, new_slug, dry_run): + print(f" ✓ Renamed {old_slug}.php → {new_slug}.php") + + if update_version_script(repo_root, old_slug, new_slug, dry_run): + print(f" ✓ Updated scripts/validate-versions.sh with new filename") + + # Reset changelog by default (unless --keep-changelog is specified) + if not keep_changelog: + reset_changelog(repo_root, config, dry_run) + print(" ✓ Reset CHANGELOG.md for fresh start") + + print() + print("=" * 50) + print(f"✅ Initialization complete!") + print(f" Files modified: {len(modified_files)}") + print(f" Total replacements: {total_replacements}") + + if dry_run: + print() + print("ℹ️ This was a dry run. Run without --dry-run to apply changes.") + else: + print() + print("📌 Next steps:") + print(" 1. Review the changes: git diff") + print(" 2. Install dependencies: composer install") + print(" 3. Run linter: composer run lint") + print(" 4. Commit your changes: git add -A && git commit -m 'chore: initialize plugin from template'") + if not keep_changelog: + print(" 5. Consider updating CHANGELOG.md with your initial features") + + +if __name__ == "__main__": + main() diff --git a/template.json b/template.json new file mode 100644 index 0000000..d05bd5a --- /dev/null +++ b/template.json @@ -0,0 +1,34 @@ +{ + "plugin": { + "name": "Template WordPress Plugin", + "slug": "template-wp-plugin", + "description": "A minimal boilerplate for WordPress plugins.", + "version": "1.0.3", + "uri": "https://github.com/liasoft/template-wp-plugin" + }, + "author": { + "name": "Liasoft GmbH", + "uri": "https://github.com/liasoft/template-wp-plugin" + }, + "php": { + "namespace": "TemplateWPPlugin", + "function_prefix": "template_wp_plugin", + "constant_prefix": "TEMPLATE_PLUGIN" + }, + "composer": { + "name": "liasoft/template-wp-plugin" + }, + "github": { + "owner": "liasoft", + "repo": "template-wp-plugin" + }, + "requirements": { + "php": "8.3", + "wordpress": "6.5", + "tested_up_to": "6.8" + }, + "license": { + "name": "GPL-3.0-or-later", + "uri": "https://www.gnu.org/licenses/gpl-3.0.html" + } +}