Created
August 11, 2020 07:41
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
print("\n==== WP-CFM Config Import Starting ====\n"); | |
// Activate the wp-cfm plugin | |
exec('wp plugin activate wp-cfm 2>&1'); | |
// Automagically import config into WP-CFM site upon code deployment | |
$env = (!empty($_ENV['PANTHEON_ENVIRONMENT']) && !in_array($_ENV['PANTHEON_ENVIRONMENT'], ['test', 'live'])) ? 'dev' : $_ENV['PANTHEON_ENVIRONMENT']; | |
$path = $_SERVER['DOCUMENT_ROOT'] . '/private/config/' . $env; | |
$files = array_diff(scandir($path), array('.', '..')); | |
// Import all config .json files in private/config | |
foreach ($files as $file) { | |
// Split filename apart. | |
$file_parts = pathinfo($file); | |
// Check for JSON files. | |
if (!empty($file_parts['extension']) && $file_parts['extension'] != 'json') { | |
continue; | |
} | |
// Import bundle. | |
exec('wp config pull ' . $file_parts['filename'] . ' 2>&1', $output); | |
if (count($output) > 0) { | |
$output = preg_replace('/\s+/', ' ', array_slice($output, 1, -1)); | |
$output = str_replace(' update', ' [update]', $output); | |
$output = str_replace(' create', ' [create]', $output); | |
$output = str_replace(' delete', ' [delete]', $output); | |
$output = implode("\n", $output); | |
$output = rtrim($output); | |
print($output); | |
} | |
} | |
// Flush the cache | |
exec('wp cache flush'); | |
print("\n==== WP-CFM Config Import Complete ====\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment