-
Notifications
You must be signed in to change notification settings - Fork 104
/
class-anspress-cli.php
92 lines (81 loc) · 2.08 KB
/
class-anspress-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
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
88
89
90
91
92
<?php
/**
* This file holds all custom wp cli commands of AnsPress.
*
* @since 4.0.5
* @package AnsPress
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Implements custom wp-cli commands.
*/
class AnsPress_Cli extends WP_CLI_Command {
/**
* Prints current version of AnsPress.
*
* ## EXAMPLES
*
* wp anspress version
*
* @when after_wp_load
*/
public function version() {
WP_CLI::success( 'Currently installed version of AnsPress is ' . AP_VERSION );
}
/**
* Upgrade AnsPress 3.x data to 4.x.
*
* Warning! This will delete/edit/rename lots of mysql rows and
* tables, so make sure to do a full backup before running this command.
*
* ## OPTIONS
*
* [--yes]
* : Passing this will not ask for backup confirm.
*
* ## EXAMPLES
*
* wp anspress upgrade --yes
*
* @when after_wp_load
*
* @param array $args Arguments.
* @param mixed $assoc_args Options.
*/
public function upgrade( $args, $assoc_args ) {
print( "=== Starting upgrade process ===\n\r" );
// Confirm before proceeding.
WP_CLI::confirm( 'Make sure you had backed up your website before starting upgrade process. Do you wish to proceed further?', $assoc_args );
AnsPress_Upgrader::get_instance();
print( "\n\r=== Upgrade process completed ===\n\r" );
}
/**
* Activate an addon.
*
* ## OPTIONS
*
* <addon>
* : Addon file name to activate.
*
* ## EXAMPLES
*
* wp anspress activate_addon free/avatar.php
*
* @when after_wp_load
* @param array $args Arguments.
* @param mixed $assoc_args Options.
*/
public function activate_addon( $args, $assoc_args ) {
if ( empty( $args[0] ) ) {
return WP_CLI::error( __( 'You must pass a addon name i.e. free/avatar.php', 'anspress-question-answer' ) );
}
$addon_name = $args[0];
$ret = ap_activate_addon( $args[0] );
if ( false === $ret ) {
return WP_CLI::error( __( 'Unable to activate addon. May be its already active or wrong name passed.', 'anspress-question-answer' ) );
}
WP_CLI::success( __( 'Successfully enabled addon', 'anspress-question-answer' ) );
}
}