-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
170 additions
and
33 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/** | ||
* @package ACFFieldOpenstreetmap\WPCLI | ||
* @version 1.0.0 | ||
* 2018-09-22 | ||
*/ | ||
|
||
namespace ACFFieldOpenstreetmap\WPCLI\Commands; | ||
|
||
use ACFFieldOpenstreetmap\Core; | ||
|
||
class MapProxy extends \WP_CLI_Command { | ||
|
||
/** | ||
* Init proxy dir in wp-content/maps/ | ||
* | ||
* [--force] | ||
* : Overwrite existing files | ||
* --- | ||
* default: 0 | ||
* --- | ||
* | ||
* ## EXAMPLES | ||
* | ||
* wp map-proxy install | ||
*/ | ||
public function install( $args, $assoc_args ) { | ||
$assoc_args = wp_parse_args($assoc_args, [ | ||
'force' => false, | ||
]); | ||
$proxy = Core\MapProxy::instance(); | ||
$result = $proxy->setup_proxy_dir( $assoc_args['force'] ); | ||
if ( is_wp_error( $result ) ) { | ||
\WP_CLI::error( $result->get_error_message() ); | ||
} else { | ||
\WP_CLI::success( "Create proxy directory in wp-content/maps/" ); | ||
} | ||
} | ||
|
||
/** | ||
* remove proxy dir in wp-content/maps/ | ||
* | ||
* ## EXAMPLES | ||
* | ||
* wp map-proxy uninstall | ||
* | ||
*/ | ||
public function uninstall( $args, $assoc_args ) { | ||
$proxy = Core\MapProxy::instance(); | ||
$result = $proxy->reset_proxy_dir(); | ||
if ( is_wp_error( $result ) ) { | ||
\WP_CLI::error( $result->get_error_message() ); | ||
} else { | ||
\WP_CLI::success( "Removed proxy directory" ); | ||
} | ||
} | ||
|
||
/** | ||
* Generate local proxy configuration | ||
* | ||
* ## EXAMPLES | ||
* | ||
* wp map-proxy configure | ||
* | ||
*/ | ||
public function configure( $args, $assoc_args ) { | ||
|
||
$proxy = Core\MapProxy::instance(); | ||
$result = $upload_dir = wp_upload_dir( null, false ); | ||
$proxy->save_proxy_config( $upload_dir['basedir'] ); | ||
|
||
if ( is_wp_error( $result ) ) { | ||
\WP_CLI::error( $result->get_error_message() ); | ||
} else { | ||
\WP_CLI::success( "Create proxy config in ". $upload_dir['basedir'] ); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
/** | ||
* @package ACFFieldOpenstreetmap\WPCLI | ||
* @version 1.0.0 | ||
* 2018-09-22 | ||
*/ | ||
|
||
namespace ACFFieldOpenstreetmap\WPCLI; | ||
|
||
if ( ! defined('ABSPATH') ) { | ||
die('FU!'); | ||
} | ||
|
||
use ACFFieldOpenstreetmap\Core; | ||
|
||
class WPCLI extends Core\Singleton { | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function __construct() { | ||
\WP_CLI::add_command( 'map-proxy install', [ new Commands\MapProxy(), 'install' ], [ | ||
'shortdesc' => 'Install map proxy directory', | ||
'is_deferred' => false, | ||
] ); | ||
\WP_CLI::add_command( 'map-proxy uninstall', [ new Commands\MapProxy(), 'uninstall' ], [ | ||
'shortdesc' => 'remove map proxy directory', | ||
'is_deferred' => false, | ||
] ); | ||
\WP_CLI::add_command( 'map-proxy configure', [ new Commands\MapProxy(), 'configure' ], [ | ||
'shortdesc' => 'Save local map proxy configuration', | ||
'is_deferred' => false, | ||
] ); | ||
} | ||
} |
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