Skip to content

Commit

Permalink
Merge pull request #1240 from greenpeace/add-cf-api-key-command
Browse files Browse the repository at this point in the history
PLANET-5619 Command to update CF key from config
  • Loading branch information
Inwerpsel authored Nov 30, 2020
2 parents 40eb615 + 30b0501 commit d29c195
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,32 @@ public function load_commands() {
return;
}

$command = static function ( $args, $assoc_args ) {
$activator_command = static function ( $args, $assoc_args ) {
Activator::run();
};
WP_CLI::add_command( 'p4-run-activator', $activator_command );

/**
* Put the CF API key into the options table, where the CF plugin uses it from.
*/
$put_cf_key_in_db = static function ( $args ) {
$hostname = $args[0];
if ( empty( $hostname ) ) {
WP_CLI::error( 'Please specify the hostname.' );
}

if ( ! defined( 'CLOUDFLARE_API_KEY' ) || empty( CLOUDFLARE_API_KEY ) ) {
WP_CLI::error( 'CLOUDFLARE_API_KEY constant is not set.' );
}

WP_CLI::add_command( 'p4-run-activator', $command );
$domain_parts = explode( '.', $hostname );

$root_domain = implode( '.', array_slice( $domain_parts, - 2 ) );
update_option( 'cloudflare_api_key', CLOUDFLARE_API_KEY );
update_option( 'automatic_platform_optimization', [ 'value' => 1 ] );
update_option( 'cloudflare_cached_domain_name', $root_domain );
};
WP_CLI::add_command( 'p4-cf-key-in-db', $put_cf_key_in_db );
}

/**
Expand Down

0 comments on commit d29c195

Please sign in to comment.