forked from wp-sync-db/wp-sync-db-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-sync-db-cli.php
54 lines (45 loc) · 1.7 KB
/
wp-sync-db-cli.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/*
Plugin Name: WP Sync DB CLI
GitHub Plugin URI: slang800/wp-sync-db-cli
Description: An extension to WP Sync DB, allows you to execute migrations using a function call or via WP-CLI
Author: Sean Lang
Version: 1.0b1
Author URI: http://slang.cx
Network: True
*/
require_once 'version.php';
$GLOBALS['wpsdb_meta']['wp-sync-db-cli']['folder'] = basename( plugin_dir_path( __FILE__ ) );
function wp_sync_db_cli_loaded() {
if ( ! class_exists( 'WPSDB_Addon' ) ) return;
require_once __DIR__ . '/class/wpsdb-cli.php';
// register with wp-cli if it's running, and command hasn't already been defined elsewhere
if ( defined( 'WP_CLI' ) && WP_CLI && ! class_exists( 'WPSDBCLI' ) ) {
require_once __DIR__ . '/class/command.php';
}
load_plugin_textdomain( 'wp-sync-db-cli', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
global $wpsdb_cli;
$wpsdb_cli = new WPSDB_CLI( __FILE__ );
}
add_action( 'plugins_loaded', 'wp_sync_db_cli_loaded', 20 );
function wpsdb_migrate( $profile ) {
global $wpsdb_cli;
if( empty( $wpsdb_cli ) ) {
return new WP_Error( 'wpsdb_cli_error', __( 'WP Sync DB CLI class not available', 'wp-sync-db-cli' ) );
}
return $wpsdb_cli->cli_migration( $profile );
}
function wpsdb_cli_connection_info() {
global $wpsdb_cli;
if( empty( $wpsdb_cli ) ) {
return new WP_Error( 'wpsdb_cli_error', __( 'WP Sync DB CLI class not available', 'wp-sync-db-cli' ) );
}
return $wpsdb_cli->cli_connection_info();
}
function wpdsb_create_profile( $name, $assoc_args ) {
global $wpsdb_cli;
if( empty( $wpsdb_cli ) ) {
return new WP_Error( 'wpsdb_cli_error', __( 'WP Sync DB CLI class not available', 'wp-sync-db-cli' ) );
}
return $wpsdb_cli->cli_create_profile( $name, $assoc_args );
}