forked from mAAdhaTTah/wordpress-github-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.php
More file actions
87 lines (76 loc) · 1.99 KB
/
Copy pathcli.php
File metadata and controls
87 lines (76 loc) · 1.99 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* WP_CLI Commands
*/
class WordPress_GitHub_Sync_CLI {
/**
* Controller object
* @var WordPress_GitHub_Sync_Controller
*/
public $controller;
/**
* Wire up controller object on init
*/
public function __construct() {
$this->controller = new WordPress_GitHub_Sync_Controller;
}
/**
* Exports an individual post
* all your posts to GitHub
*
* ## OPTIONS
*
* <post_id|all>
* : The post ID to export or 'all' for full site
*
* <user_id>
* : The user ID you'd like to save the commit as
*
* ## EXAMPLES
*
* wp wpghs export all 1
* wp wpghs export 1 1
*
* @synopsis <post_id|all> <user_id>
*/
public function export( $args, $assoc_args ) {
list( $post_id, $user_id ) = $args;
if ( ! is_numeric( $user_id ) ) {
WP_CLI::error( __( 'Invalid user ID', WordPress_GitHub_Sync::$text_domain ) );
}
update_option( '_wpghs_export_user_id', (int) $user_id );
if ( 'all' === $post_id ) {
WP_CLI::line( __( 'Starting full export to GitHub.', WordPress_GitHub_Sync::$text_domain ) );
$this->controller->export_all();
} elseif ( is_numeric( $post_id ) ) {
WP_CLI::line( __( 'Exporting post ID to GitHub: ', WordPress_GitHub_Sync::$text_domain ). $post_id );
$this->controller->export_post( (int) $post_id );
} else {
WP_CLI::error( __( 'Invalid post ID', WordPress_GitHub_Sync::$text_domain ) );
}
}
/**
* Imports the post in your GitHub repo
* into your WordPress blog
*
* ## OPTIONS
*
* <user_id>
* : The user ID you'd like to save the commit as
*
* ## EXAMPLES
*
* wp wpghs import 1
*
* @synopsis <user_id>
*/
public function import( $args, $assoc_args ) {
list( $user_id ) = $args;
if ( ! is_numeric( $user_id ) ) {
WP_CLI::error( __( 'Invalid user ID', WordPress_GitHub_Sync::$text_domain ) );
}
update_option( '_wpghs_export_user_id', (int) $user_id );
WP_CLI::line( __( 'Starting import from GitHub.', WordPress_GitHub_Sync::$text_domain ) );
$this->controller->import_master();
}
}