metabolism/wordpress-core-installer
Composer installer extension that adds type:wordpress-core support for installer-paths, enabling johnpbloch/wordpress-core to be installed into your chosen directory (e.g., web/edition/) instead of the default location.
Install Dependencies
composer require metabolism/wordpress-core-installer johnpbloch/wordpress-core
Ensure composer/installers (≥2.0) is also installed (auto-included via metabolism/wordpress-core-installer).
Configure composer.json
Add the installer-paths entry under extra to define where WordPress should be installed:
{
"extra": {
"installer-paths": {
"web/edition/": ["type:wordpress-core"]
}
}
}
web/edition/ with your target directory (relative to project root).First Use Case Run:
composer install
WordPress core files will now be installed to web/edition/ automatically.
Multi-Environment Setups
Use environment-specific composer.json files (e.g., composer.dev.json, composer.prod.json) to override installer-paths:
// composer.prod.json
{
"extra": {
"installer-paths": {
"public_html/": ["type:wordpress-core"]
}
}
}
Custom WordPress Version
Specify a version constraint in require:
{
"require": {
"johnpbloch/wordpress-core": "6.4.*"
}
}
Post-Install Hooks
Use Composer’s post-install-cmd or post-update-cmd to run scripts (e.g., database setup, theme activation):
{
"scripts": {
"post-install-cmd": [
"php artisan wordpress:setup --path=web/edition/"
]
}
}
Service Provider Integration Dynamically detect WordPress paths in a Laravel service provider:
use Metabolism\WordpressCoreInstaller\Installer;
public function boot()
{
$installer = new Installer();
$wordpressPath = $installer->getInstallPath('web/edition/');
config(['wordpress.path' => $wordpressPath]);
}
Artisan Commands Extend Laravel’s Artisan to interact with WordPress:
// app/Console/Commands/WordpressCommand.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Metabolism\WordpressCoreInstaller\Installer;
class WordpressCommand extends Command
{
protected $signature = 'wordpress:info';
protected $description = 'Show WordPress installation details';
public function handle()
{
$installer = new Installer();
$path = $installer->getInstallPath('web/edition/');
$this->info("WordPress installed at: {$path}");
}
}
Environment Configuration
Use Laravel’s .env to override paths:
WORDPRESS_PATH=web/edition
Then access it via:
$path = env('WORDPRESS_PATH');
Path Resolution Conflicts
installer-paths keys are absolute relative paths (no ./ or ../). Example:
"web/edition/" // Correct
"./web/edition" // Fails
composer show -i to verify installed paths.Composer Installers Version Mismatch
composer/installers:^1.0, downgrade to ~1.0 or upgrade to ~2.0 (as of v1.1.2 of this package).composer require composer/installers:^2.0.WordPress Core Updates
wp-config.php or wp-content/. Back up manually or use a script:
composer update johnpbloch/wordpress-core --with-all-dependencies
Permissions Issues
wp-content/). Set permissions post-install:
chmod -R 755 web/edition/
chown -R www-data:www-data web/edition/ # Adjust user/group as needed
Verify Installation Check if the installer is registered:
composer show metabolism/wordpress-core-installer
Look for installer-paths in the output.
Enable Composer Debug Mode
Run Composer with -vvv to trace installation:
composer install -vvv
Check for Overrides
Conflicts may arise if multiple packages define installer-paths. Use:
composer config extra.installer-paths
To inspect merged configurations.
Custom Installer Logic
Extend the installer by subclassing Metabolism\WordpressCoreInstaller\Installer:
namespace App\Installers;
use Metabolism\WordpressCoreInstaller\Installer as BaseInstaller;
class CustomWordpressInstaller extends BaseInstaller
{
public function getInstallPath($path)
{
$path = parent::getInstallPath($path);
// Add custom logic (e.g., append subdirectory)
return $path . 'custom/';
}
}
Register it in composer.json:
{
"extra": {
"installer-classes": {
"type:wordpress-core": "App\\Installers\\CustomWordpressInstaller"
}
}
}
Pre/Post-Install Scripts Use Composer scripts to automate post-install tasks:
{
"scripts": {
"post-install-cmd": [
"@php artisan config:clear",
"@php artisan cache:clear"
]
}
}
CI/CD Integration
For GitHub Actions/GitLab CI, ensure composer install runs in a clean environment:
# .github/workflows/deploy.yml
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install --no-dev --optimize-autoloader
- run: chmod -R 755 web/edition/
How can I help you explore Laravel packages today?