Skip to content

Instantly share code, notes, and snippets.

@laxmariappan
Created August 1, 2022 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laxmariappan/28c47a53333505480f63b1be8071327d to your computer and use it in GitHub Desktop.
Save laxmariappan/28c47a53333505480f63b1be8071327d to your computer and use it in GitHub Desktop.
Sample WP CLI class
<?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