-
-
Save laxmariappan/28c47a53333505480f63b1be8071327d to your computer and use it in GitHub Desktop.
Sample WP CLI class
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 | |
/* | |
Plugin Name: WDS Migration | |
Plugin URI: | |
Description: Migration via custom WP CLI commands. | |
Version: 1.0 | |
Author: Lax Mariappan | |
Author URI: https://www.webdevstudios.com | |
Text Domain: migrate | |
*/ | |
/** | |
* Migration class with commands and helper functions. | |
* | |
* @since 1.0 | |
*/ | |
class WDS_Migration { | |
/** | |
* Export content. | |
* | |
* @return void | |
* @since 1.0 | |
* @author Lax Mariappan <lax@webdevstudios.com> | |
*/ | |
public function export(){ | |
\WP_CLI::log( 'Export' ); | |
} | |
/** | |
* Import content. | |
* | |
* @return void | |
* @since 1.0 | |
* @author Lax Mariappan <lax@webdevstudios.com> | |
*/ | |
public function import(){ | |
$site = $this->get_site_name(); | |
\WP_CLI::line( \WP_CLI::colorize( '%y imported ' . $site . ' site content, check logs for errors. %n' ) ); | |
} | |
/** | |
* Get current site name. | |
* | |
* @return void | |
* @since 1.0 | |
* @author Lax Mariappan <lax@webdevstudios.com> | |
*/ | |
private function get_site_name(){ | |
$full_url = get_site_url( get_current_blog_id() ); | |
$site_name = basename( $full_url ); | |
return $site_name; | |
} | |
} | |
function wds_cli_register_commands() { | |
\WP_CLI::add_command( 'migrate', 'WDS_Migration' ); | |
} | |
add_action( 'cli_init', 'wds_cli_register_commands' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment