-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-cli.php
128 lines (107 loc) · 3.39 KB
/
wp-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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* Class extends WP CLI with custom commands to manage plugin from command line.
*/
class LangBF_WP_CLI_Command extends WP_CLI_Command {
/**
* Subcommand to list all available commands.
*
* Examples:
* wp langbf help
*
* @subcommand help
*/
public function help( $args, $assoc_args ) {
WP_CLI::line( 'enable ' . __( 'Enables bar with lanuages', LANGBF_TD ) );
WP_CLI::line( 'disable ' . __( 'Disables bar with lanuages', LANGBF_TD ) );
WP_CLI::line( 'position <option> ' . sprintf( __( 'Sets position of bar where <option> can be: %s', LANGBF_TD ), 'top, bottom' ) );
WP_CLI::line( 'side <option> ' . sprintf( __( 'Sets side of flags where <option> can be: %s', LANGBF_TD ), 'left, right' ) );
WP_CLI::line( 'newwindow <option> ' . sprintf( __( 'Sets if links should be opened in new window where <option> can be: %s', LANGBF_TD ), 'yes, no' ) );
}
/**
* Subcommand to enable language bar.
*
* Examples:
* wp langbf enable
*
* @subcommand enable
*/
public function enable( $args, $assoc_args ) {
update_option( 'langbf_active', 'yes' );
$message = __( 'Enabled bar with lanuages!', LANGBF_TD );
WP_CLI::success( $message );
}
/**
* Subcommand to disable language bar.
*
* Examples:
* wp langbf disable
*
* @subcommand disable
*/
public function disable( $args, $assoc_args ) {
update_option( 'langbf_active', 'no' );
$message = __( 'Disabled bar with lanuages!', LANGBF_TD );
WP_CLI::success( $message );
}
/**
* Subcommand to set position of language bar.
*
* Examples:
* wp langbf position top
* wp langbf position bottom
*
* @subcommand position
*/
public function position( $args, $assoc_args ) {
$positions = array( 'top', 'bottom' );
if ( empty( $args[0] ) || ! in_array( $args[0], $positions ) ) {
$message = sprintf( __( 'Missing or invalid position param! Valid are: %s', LANGBF_TD ), implode( ', ', $positions ) );
WP_CLI::error( $message );
return;
}
update_option( 'langbf_position', $args[0] );
$message = __( 'Updated position of bar with lanuages!', LANGBF_TD );
WP_CLI::success( $message );
}
/**
* Subcommand to set side of language flags on the bar.
*
* Examples:
* wp langbf side left
* wp langbf side right
*
* @subcommand side
*/
public function side( $args, $assoc_args ) {
$sides = array( 'left', 'right' );
if ( empty( $args[0] ) || ! in_array( $args[0], $sides ) ) {
$message = sprintf( __( 'Missing or invalid side param! Valid are: %s', LANGBF_TD ), implode( ', ', $sides ) );
WP_CLI::error( $message );
return;
}
update_option( 'langbf_side', $args[0] );
$message = __( 'Updated side of language flags on the bar!', LANGBF_TD );
WP_CLI::success( $message );
}
/**
* Subcommand to set if links should be opened in new windows.
*
* Examples:
* wp langbf newwindow yes
* wp langbf newwindow no
*
* @subcommand newwindow
*/
public function newwindow( $args, $assoc_args ) {
$options = array( 'yes', 'no' );
if ( empty( $args[0] ) || ! in_array( $args[0], $options ) ) {
$message = sprintf( __( 'Missing or invalid new window param! Valid are: %s', LANGBF_TD ), implode( ', ', $options ) );
WP_CLI::error( $message );
return;
}
update_option( 'langbf_new_window', $args[0] );
$message = __( 'Updated new window option for opening links!', LANGBF_TD );
WP_CLI::success( $message );
}
}