Skip to content

Instantly share code, notes, and snippets.

@kyletaylored
Created August 11, 2020 07:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kyletaylored/7d14db08a5ced89693901ff04b99970e to your computer and use it in GitHub Desktop.
<?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