| @@ -1,52 +1,66 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * Multi Device Switcher Command |
| 4 | + * | |
| 5 | + * @package Multi_Device_Switcher | |
| 4 | 6 | */ |
| 7 | + | |
| 8 | +/** | |
| 9 | + * Core class Multi_Device_Switcher_Command | |
| 10 | + * | |
| 11 | + * @since 1.0.0 | |
| 12 | + */ | |
| 5 | 13 | class Multi_Device_Switcher_Command extends WP_CLI_Command { |
| 6 | 14 | |
| 7 | - private $options = 'multi_device_switcher_options'; | |
| 15 | + /** | |
| 16 | + * Public variable. | |
| 17 | + * | |
| 18 | + * @access public | |
| 19 | + * | |
| 20 | + * @var string $option_name The option name | |
| 21 | + */ | |
| 22 | + public $option_name = 'multi_device_switcher_options'; | |
| 8 | 23 | |
| 9 | 24 | /** |
| 10 | - * get status of settings | |
| 25 | + * Get status of settings | |
| 11 | 26 | * |
| 12 | 27 | * ## EXAMPLES |
| 13 | 28 | * |
| 14 | 29 | * wp multi-device status |
| 15 | - * | |
| 16 | - */ | |
| 30 | + */ | |
| 17 | 31 | public function status( $args, $assoc_args ) { |
| 18 | - $options = get_option( $this->options ); | |
| 19 | - $rows = array(); | |
| 32 | + $options = get_option( $this->option_name ); | |
| 33 | + $rows = array(); | |
| 20 | 34 | |
| 21 | 35 | $slug_table = array( 'None' => '' ); |
| 22 | - $themes = wp_get_themes(); | |
| 36 | + $themes = wp_get_themes(); | |
| 23 | 37 | foreach ( $themes as $theme_slug => $header ) { |
| 24 | 38 | $slug_table[ $header->get( 'Name' ) ] = $theme_slug; |
| 25 | 39 | } |
| 26 | 40 | |
| 27 | 41 | $rows[] = array( |
| 28 | - 'Device' => 'smartphone (Smart Phone)', | |
| 29 | - 'Theme' => $options['theme_smartphone'], | |
| 30 | - 'Slug' => $slug_table[ $options['theme_smartphone'] ], | |
| 42 | + 'Device' => 'smartphone (Smart Phone)', | |
| 43 | + 'Theme' => $options['theme_smartphone'], | |
| 44 | + 'Slug' => $slug_table[ $options['theme_smartphone'] ], | |
| 31 | 45 | 'UserAgent' => $options['userAgent_smart'], |
| 32 | 46 | ); |
| 33 | 47 | $rows[] = array( |
| 34 | - 'Device' => 'tablet (Tablet PC)', | |
| 35 | - 'Theme' => $options['theme_tablet'], | |
| 36 | - 'Slug' => $slug_table[ $options['theme_tablet'] ], | |
| 48 | + 'Device' => 'tablet (Tablet PC)', | |
| 49 | + 'Theme' => $options['theme_tablet'], | |
| 50 | + 'Slug' => $slug_table[ $options['theme_tablet'] ], | |
| 37 | 51 | 'UserAgent' => $options['userAgent_tablet'], |
| 38 | 52 | ); |
| 39 | 53 | $rows[] = array( |
| 40 | - 'Device' => 'mobile (Mobile Phone)', | |
| 41 | - 'Theme' => $options['theme_mobile'], | |
| 42 | - 'Slug' => $slug_table[ $options['theme_mobile'] ], | |
| 54 | + 'Device' => 'mobile (Mobile Phone)', | |
| 55 | + 'Theme' => $options['theme_mobile'], | |
| 56 | + 'Slug' => $slug_table[ $options['theme_mobile'] ], | |
| 43 | 57 | 'UserAgent' => $options['userAgent_mobile'], |
| 44 | 58 | ); |
| 45 | 59 | $rows[] = array( |
| 46 | - 'Device' => 'game (Game Platforms)', | |
| 47 | - 'Theme' => $options['theme_game'], | |
| 48 | - 'Slug' => $slug_table[ $options['theme_game'] ], | |
| 60 | + 'Device' => 'game (Game Platforms)', | |
| 61 | + 'Theme' => $options['theme_game'], | |
| 62 | + 'Slug' => $slug_table[ $options['theme_game'] ], | |
| 49 | 63 | 'UserAgent' => $options['userAgent_game'], |
| 50 | 64 | ); |
| 51 | 65 | |
| 52 | 66 | foreach ( $options as $custom_switcher_option => $custom_switcher_theme ) { |
| @@ -56,16 +70,16 @@ | ||
| 56 | 70 | |
| 57 | 71 | $custom_switcher_name = preg_replace( '/^custom_switcher_theme_/', '', $custom_switcher_option ); |
| 58 | 72 | |
| 59 | 73 | $rows[] = array( |
| 60 | - 'Device' => $custom_switcher_name, | |
| 61 | - 'Theme' => $options[ 'custom_switcher_theme_' . $custom_switcher_name ], | |
| 62 | - 'Slug' => $slug_table[ $options[ 'custom_switcher_theme_' . $custom_switcher_name ] ], | |
| 74 | + 'Device' => $custom_switcher_name, | |
| 75 | + 'Theme' => $options[ 'custom_switcher_theme_' . $custom_switcher_name ], | |
| 76 | + 'Slug' => $slug_table[ $options[ 'custom_switcher_theme_' . $custom_switcher_name ] ], | |
| 63 | 77 | 'UserAgent' => $options[ 'custom_switcher_userAgent_' . $custom_switcher_name ], |
| 64 | 78 | ); |
| 65 | 79 | } |
| 66 | 80 | |
| 67 | - $default_theme = wp_get_theme()->get( 'Name' ); | |
| 81 | + $default_theme = wp_get_theme()->get( 'Name' ); | |
| 68 | 82 | $default_theme .= ' | '; |
| 69 | 83 | $default_theme .= get_stylesheet(); |
| 70 | 84 | WP_CLI::line( 'Active Theme: ' . $default_theme ); |
| 71 | 85 | |
| @@ -70,9 +84,9 @@ | ||
| 70 | 84 | WP_CLI::line( 'Active Theme: ' . $default_theme ); |
| 71 | 85 | |
| 72 | 86 | WP_CLI\Utils\format_items( 'table', $rows, array( 'Device', 'Theme', 'Slug', 'UserAgent' ) ); |
| 73 | 87 | |
| 74 | - $line = ''; | |
| 88 | + $line = ''; | |
| 75 | 89 | $line .= 'PC Switcher: '; |
| 76 | 90 | $line .= $options['pc_switcher'] ? 'on' : 'off'; |
| 77 | 91 | $line .= "\n"; |
| 78 | 92 | $line .= 'default CSS: '; |
| @@ -81,9 +95,9 @@ | ||
| 81 | 95 | WP_CLI::line( $line ); |
| 82 | 96 | } |
| 83 | 97 | |
| 84 | 98 | /** |
| 85 | - * get or switch a theme | |
| 99 | + * Get or Switch a theme | |
| 86 | 100 | * |
| 87 | 101 | * ## OPTIONS |
| 88 | 102 | * |
| 89 | 103 | * <device> |
| @@ -108,34 +122,38 @@ | ||
| 108 | 122 | * # switch twentyfifteen in theme of smartphone using theme argument |
| 109 | 123 | * wp multi-device theme smartphone --theme='Twenty Fifteen' |
| 110 | 124 | * |
| 111 | 125 | * @synopsis <device> [<slug>] [--theme=<theme>] |
| 112 | - */ | |
| 126 | + */ | |
| 113 | 127 | public function theme( $args, $assoc_args ) { |
| 114 | - $name = isset( $args[0] ) ? $args[0] : null; | |
| 115 | - $slug = isset( $args[1] ) ? $args[1] : null; | |
| 128 | + $name = isset( $args[0] ) ? $args[0] : null; | |
| 129 | + $slug = isset( $args[1] ) ? $args[1] : null; | |
| 116 | 130 | $theme = isset( $assoc_args['theme'] ) ? $assoc_args['theme'] : null; |
| 117 | 131 | |
| 118 | - $options = get_option( $this->options ); | |
| 132 | + $options = get_option( $this->option_name ); | |
| 119 | 133 | |
| 120 | 134 | if ( isset( $slug ) ) { |
| 121 | - if ( '' == $slug || 'None' == $slug ) { | |
| 135 | + if ( '' === $slug || 'None' === $slug ) { | |
| 122 | 136 | $theme = 'None'; |
| 123 | 137 | } |
| 124 | 138 | } |
| 125 | 139 | |
| 126 | 140 | $slug_table = array( 'None' => '' ); |
| 127 | - $themes = wp_get_themes(); | |
| 141 | + $themes = wp_get_themes(); | |
| 128 | 142 | foreach ( $themes as $theme_slug => $header ) { |
| 129 | 143 | $slug_table[ $header->get( 'Name' ) ] = $theme_slug; |
| 130 | - if ( $slug == $theme_slug ) { | |
| 144 | + if ( $slug === $theme_slug ) { | |
| 131 | 145 | $theme = $header->get( 'Name' ); |
| 132 | 146 | } |
| 133 | 147 | } |
| 134 | 148 | |
| 149 | + if ( isset( $slug ) && is_null( $theme ) ) { | |
| 150 | + WP_CLI::error( $slug . ' theme is not installed' ); | |
| 151 | + } | |
| 152 | + | |
| 135 | 153 | if ( isset( $theme ) ) { |
| 136 | 154 | $default_theme = wp_get_theme()->get( 'Name' ); |
| 137 | - if ( $default_theme == $theme ) { | |
| 155 | + if ( $default_theme === $theme ) { | |
| 138 | 156 | WP_CLI::error( $theme . ' theme is in active' ); |
| 139 | 157 | } |
| 140 | 158 | |
| 141 | 159 | if ( ! isset( $slug_table[ $theme ] ) ) { |
| @@ -141,21 +159,21 @@ | ||
| 141 | 159 | if ( ! isset( $slug_table[ $theme ] ) ) { |
| 142 | 160 | WP_CLI::error( $theme . ' theme is not installed' ); |
| 143 | 161 | } |
| 144 | 162 | |
| 145 | - if ( in_array( $name, array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ) ) ) { | |
| 146 | - if ( 'smart' == $name ) { | |
| 163 | + if ( in_array( $name, array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ), true ) ) { | |
| 164 | + if ( 'smart' === $name ) { | |
| 147 | 165 | $name = 'smartphone'; |
| 148 | 166 | } |
| 149 | 167 | $options[ 'theme_' . $name ] = $theme; |
| 150 | 168 | |
| 151 | - update_option( $this->options, $options ); | |
| 169 | + update_option( $this->option_name, $options ); | |
| 152 | 170 | WP_CLI::success( 'switch ' . $name . ' theme to ' . $theme ); |
| 153 | 171 | } |
| 154 | - else if ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) { | |
| 172 | + elseif ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) { | |
| 155 | 173 | $options[ 'custom_switcher_theme_' . $name ] = $theme; |
| 156 | 174 | |
| 157 | - update_option( $this->options, $options ); | |
| 175 | + update_option( $this->option_name, $options ); | |
| 158 | 176 | WP_CLI::success( 'switch ' . $name . ' theme to ' . $theme ); |
| 159 | 177 | } |
| 160 | 178 | else { |
| 161 | 179 | WP_CLI::error( $name . ' don\'t exist' ); |
| @@ -160,16 +178,17 @@ | ||
| 160 | 178 | else { |
| 161 | 179 | WP_CLI::error( $name . ' don\'t exist' ); |
| 162 | 180 | } |
| 163 | 181 | } |
| 182 | + // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found | |
| 164 | 183 | else { |
| 165 | - if ( in_array( $name, array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ) ) ) { | |
| 166 | - if ( 'smart' == $name ) { | |
| 184 | + if ( in_array( $name, array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ), true ) ) { | |
| 185 | + if ( 'smart' === $name ) { | |
| 167 | 186 | $name = 'smartphone'; |
| 168 | 187 | } |
| 169 | 188 | WP_CLI::success( $options[ 'theme_' . $name ] . ' | ' . $slug_table[ $options[ 'theme_' . $name ] ] ); |
| 170 | 189 | } |
| 171 | - else if ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) { | |
| 190 | + elseif ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) { | |
| 172 | 191 | WP_CLI::success( $options[ 'custom_switcher_theme_' . $name ] . ' | ' . $slug_table[ $options[ 'custom_switcher_theme_' . $name ] ] ); |
| 173 | 192 | } |
| 174 | 193 | else { |
| 175 | 194 | WP_CLI::error( $name . ' don\'t exist' ); |
| @@ -177,9 +196,9 @@ | ||
| 177 | 196 | } |
| 178 | 197 | } |
| 179 | 198 | |
| 180 | 199 | /** |
| 181 | - * get or set UserAgent | |
| 200 | + * Get or Set UserAgent | |
| 182 | 201 | * |
| 183 | 202 | * ## OPTIONS |
| 184 | 203 | * |
| 185 | 204 | * <device> |
| @@ -197,29 +216,29 @@ | ||
| 197 | 216 | * # set UserAgent in theme of tablet |
| 198 | 217 | * wp multi-device useragent tablet 'iPad, Kindle, Sony Tablet, Nexus 7' |
| 199 | 218 | * |
| 200 | 219 | * @synopsis <device> [<UserAgent>] |
| 201 | - */ | |
| 220 | + */ | |
| 202 | 221 | public function useragent( $args, $assoc_args ) { |
| 203 | - $name = isset( $args[0] ) ? $args[0] : null; | |
| 222 | + $name = isset( $args[0] ) ? $args[0] : null; | |
| 204 | 223 | $useragent = isset( $args[1] ) ? $args[1] : null; |
| 205 | 224 | |
| 206 | - $options = get_option( $this->options ); | |
| 225 | + $options = get_option( $this->option_name ); | |
| 207 | 226 | |
| 208 | 227 | if ( isset( $useragent ) ) { |
| 209 | - if ( in_array( $name, array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ) ) ) { | |
| 210 | - if ( 'smartphone' == $name ) { | |
| 228 | + if ( in_array( $name, array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ), true ) ) { | |
| 229 | + if ( 'smartphone' === $name ) { | |
| 211 | 230 | $name = 'smart'; |
| 212 | 231 | } |
| 213 | 232 | $options[ 'userAgent_' . $name ] = $useragent; |
| 214 | 233 | |
| 215 | - update_option( $this->options, $options ); | |
| 234 | + update_option( $this->option_name, $options ); | |
| 216 | 235 | WP_CLI::success( 'set ' . $name . ' UserAgent to ' . $useragent ); |
| 217 | 236 | } |
| 218 | - else if ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) { | |
| 237 | + elseif ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) { | |
| 219 | 238 | $options[ 'custom_switcher_userAgent_' . $name ] = $useragent; |
| 220 | 239 | |
| 221 | - update_option( $this->options, $options ); | |
| 240 | + update_option( $this->option_name, $options ); | |
| 222 | 241 | WP_CLI::success( 'set ' . $name . ' UserAgent to ' . $useragent ); |
| 223 | 242 | } |
| 224 | 243 | else { |
| 225 | 244 | WP_CLI::error( $name . ' don\'t exist' ); |
| @@ -224,16 +243,17 @@ | ||
| 224 | 243 | else { |
| 225 | 244 | WP_CLI::error( $name . ' don\'t exist' ); |
| 226 | 245 | } |
| 227 | 246 | } |
| 247 | + // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found | |
| 228 | 248 | else { |
| 229 | - if ( in_array( $name, array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ) ) ) { | |
| 230 | - if ( 'smartphone' == $name ) { | |
| 249 | + if ( in_array( $name, array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ), true ) ) { | |
| 250 | + if ( 'smartphone' === $name ) { | |
| 231 | 251 | $name = 'smart'; |
| 232 | 252 | } |
| 233 | 253 | WP_CLI::success( $options[ 'userAgent_' . $name ] ); |
| 234 | 254 | } |
| 235 | - else if ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) { | |
| 255 | + elseif ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) { | |
| 236 | 256 | WP_CLI::success( $options[ 'custom_switcher_userAgent_' . $name ] ); |
| 237 | 257 | } |
| 238 | 258 | else { |
| 239 | 259 | WP_CLI::error( $name . ' don\'t exist' ); |
| @@ -241,9 +261,9 @@ | ||
| 241 | 261 | } |
| 242 | 262 | } |
| 243 | 263 | |
| 244 | 264 | /** |
| 245 | - * reset Settings to Default UserAgent | |
| 265 | + * Reset Settings to Default UserAgent | |
| 246 | 266 | * |
| 247 | 267 | * ## EXAMPLES |
| 248 | 268 | * |
| 249 | 269 | * wp multi-device reset |
| @@ -248,24 +268,24 @@ | ||
| 248 | 268 | * |
| 249 | 269 | * wp multi-device reset |
| 250 | 270 | * |
| 251 | 271 | * @synopsis |
| 252 | - */ | |
| 272 | + */ | |
| 253 | 273 | public function reset( $args, $assoc_args ) { |
| 254 | - $options = get_option( $this->options ); | |
| 274 | + $options = get_option( $this->option_name ); | |
| 255 | 275 | $default_options = multi_device_switcher_get_default_options(); |
| 256 | 276 | |
| 257 | - $options['userAgent_smart'] = $default_options['userAgent_smart']; | |
| 277 | + $options['userAgent_smart'] = $default_options['userAgent_smart']; | |
| 258 | 278 | $options['userAgent_tablet'] = $default_options['userAgent_tablet']; |
| 259 | 279 | $options['userAgent_mobile'] = $default_options['userAgent_mobile']; |
| 260 | - $options['userAgent_game'] = $default_options['userAgent_game']; | |
| 280 | + $options['userAgent_game'] = $default_options['userAgent_game']; | |
| 261 | 281 | |
| 262 | - update_option( $this->options, $options ); | |
| 282 | + update_option( $this->option_name, $options ); | |
| 263 | 283 | WP_CLI::success( 'reset Settings to Default UserAgent' ); |
| 264 | 284 | } |
| 265 | 285 | |
| 266 | 286 | /** |
| 267 | - * add Custom Switcher | |
| 287 | + * Add Custom Switcher | |
| 268 | 288 | * |
| 269 | 289 | * ## OPTIONS |
| 270 | 290 | * |
| 271 | 291 | * <device> |
| @@ -293,15 +313,14 @@ | ||
| 293 | 313 | * # add example Custom Switcher. set twentyfifteen theme and UserAgent using theme argument |
| 294 | 314 | * wp multi-device add example --theme='Twenty Fifteen' |
| 295 | 315 | * |
| 296 | 316 | * @synopsis <device> [<slug>] [<UserAgent>] [--theme=<theme>] |
| 297 | - */ | |
| 298 | - | |
| 317 | + */ | |
| 299 | 318 | public function add( $args, $assoc_args ) { |
| 300 | - $name = isset( $args[0] ) ? $args[0] : null; | |
| 301 | - $slug = isset( $args[1] ) ? $args[1] : null; | |
| 319 | + $name = isset( $args[0] ) ? $args[0] : null; | |
| 320 | + $slug = isset( $args[1] ) ? $args[1] : null; | |
| 302 | 321 | $useragent = isset( $args[2] ) ? $args[2] : null; |
| 303 | - $theme = isset( $assoc_args['theme'] ) ? $assoc_args['theme'] : null; | |
| 322 | + $theme = isset( $assoc_args['theme'] ) ? $assoc_args['theme'] : null; | |
| 304 | 323 | |
| 305 | 324 | if ( ! preg_match( '/^[A-Za-z0-9]{1,20}$/', $name ) ) { |
| 306 | 325 | WP_CLI::error( '20 characters max, alphanumeric' ); |
| 307 | 326 | } |
| @@ -306,26 +325,26 @@ | ||
| 306 | 325 | WP_CLI::error( '20 characters max, alphanumeric' ); |
| 307 | 326 | } |
| 308 | 327 | |
| 309 | 328 | $slug_table = array( 'None' => '' ); |
| 310 | - $themes = wp_get_themes(); | |
| 329 | + $themes = wp_get_themes(); | |
| 311 | 330 | foreach ( $themes as $theme_slug => $header ) { |
| 312 | 331 | $slug_table[ $header->get( 'Name' ) ] = $theme_slug; |
| 313 | - if ( ! isset( $assoc_args['theme'] ) && $slug == $theme_slug ) { | |
| 332 | + if ( ! isset( $assoc_args['theme'] ) && $slug === $theme_slug ) { | |
| 314 | 333 | $theme = $header->get( 'Name' ); |
| 315 | 334 | } |
| 316 | 335 | } |
| 317 | 336 | |
| 318 | - $options = get_option( $this->options ); | |
| 319 | - if ( in_array( $name, array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ) ) ) { | |
| 320 | - WP_CLI::error( 'can\'t add Default Switcher' ); | |
| 337 | + $options = get_option( $this->option_name ); | |
| 338 | + if ( in_array( $name, array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ), true ) ) { | |
| 339 | + WP_CLI::error( 'Default Switcher can\'t add' ); | |
| 321 | 340 | } |
| 322 | - else if ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) { | |
| 341 | + elseif ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) { | |
| 323 | 342 | WP_CLI::error( 'Custom Switcher already exists' ); |
| 324 | 343 | } |
| 325 | 344 | else { |
| 326 | 345 | $default_theme = wp_get_theme()->get( 'Name' ); |
| 327 | - if ( $default_theme == $theme ) { | |
| 346 | + if ( $default_theme === $theme ) { | |
| 328 | 347 | WP_CLI::error( $theme . ' theme is in active' ); |
| 329 | 348 | } |
| 330 | 349 | |
| 331 | 350 | if ( isset( $slug ) || isset( $assoc_args['theme'] ) ) { |
| @@ -332,9 +351,9 @@ | ||
| 332 | 351 | if ( isset( $slug_table[ $theme ] ) ) { |
| 333 | 352 | $options[ 'custom_switcher_theme_' . $name ] = $theme; |
| 334 | 353 | } |
| 335 | 354 | else { |
| 336 | - WP_CLI::error( $theme . ' theme are not installed' ); | |
| 355 | + WP_CLI::error( $slug . ' theme is not installed' ); | |
| 337 | 356 | } |
| 338 | 357 | } |
| 339 | 358 | else { |
| 340 | 359 | $options[ 'custom_switcher_theme_' . $name ] = 'None'; |
| @@ -341,15 +360,15 @@ | ||
| 341 | 360 | } |
| 342 | 361 | |
| 343 | 362 | $options[ 'custom_switcher_userAgent_' . $name ] = isset( $useragent ) ? $useragent : ''; |
| 344 | 363 | |
| 345 | - update_option( $this->options, $options ); | |
| 364 | + update_option( $this->option_name, $options ); | |
| 346 | 365 | WP_CLI::success( 'add ' . $name . ' Custom Switcher' ); |
| 347 | 366 | } |
| 348 | 367 | } |
| 349 | 368 | |
| 350 | 369 | /** |
| 351 | - * delete Custom Switcher | |
| 370 | + * Delete Custom Switcher | |
| 352 | 371 | * |
| 353 | 372 | * ## OPTIONS |
| 354 | 373 | * |
| 355 | 374 | * <device> |
| @@ -360,22 +379,22 @@ | ||
| 360 | 379 | * # delete example Custom Switcher |
| 361 | 380 | * wp multi-device delete example |
| 362 | 381 | * |
| 363 | 382 | * @synopsis <device> |
| 364 | - */ | |
| 383 | + */ | |
| 365 | 384 | public function delete( $args, $assoc_args ) { |
| 366 | 385 | $name = isset( $args[0] ) ? $args[0] : null; |
| 367 | 386 | |
| 368 | - $options = get_option( $this->options ); | |
| 387 | + $options = get_option( $this->option_name ); | |
| 369 | 388 | |
| 370 | - if ( in_array( $name, array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ) ) ) { | |
| 389 | + if ( in_array( $name, array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ), true ) ) { | |
| 371 | 390 | WP_CLI::error( 'Default Switcher can\'t delete' ); |
| 372 | 391 | } |
| 373 | - else if ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) { | |
| 392 | + elseif ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) { | |
| 374 | 393 | unset( $options[ 'custom_switcher_theme_' . $name ] ); |
| 375 | 394 | unset( $options[ 'custom_switcher_userAgent_' . $name ] ); |
| 376 | 395 | |
| 377 | - update_option( $this->options, $options ); | |
| 396 | + update_option( $this->option_name, $options ); | |
| 378 | 397 | WP_CLI::success( 'delete ' . $name . ' Custom Switcher' ); |
| 379 | 398 | } |
| 380 | 399 | else { |
| 381 | 400 | WP_CLI::error( 'Custom Switcher don\'t exist' ); |
| @@ -382,9 +401,9 @@ | ||
| 382 | 401 | } |
| 383 | 402 | } |
| 384 | 403 | |
| 385 | 404 | /** |
| 386 | - * turn on/off PC Switcher | |
| 405 | + * Turn on/off PC Switcher | |
| 387 | 406 | * |
| 388 | 407 | * ## OPTIONS |
| 389 | 408 | * |
| 390 | 409 | * <flag> |
| @@ -400,22 +419,22 @@ | ||
| 400 | 419 | * wp multi-device pc-switcher off |
| 401 | 420 | * |
| 402 | 421 | * @synopsis <flag> |
| 403 | 422 | * @subcommand pc-switcher |
| 404 | - */ | |
| 423 | + */ | |
| 405 | 424 | public function pc_switcher( $args, $assoc_args ) { |
| 406 | 425 | $flag = isset( $args[0] ) ? $args[0] : null; |
| 407 | 426 | |
| 408 | - $options = get_option( $this->options ); | |
| 427 | + $options = get_option( $this->option_name ); | |
| 409 | 428 | |
| 410 | - if ( 'on' == $flag ) { | |
| 429 | + if ( 'on' === $flag ) { | |
| 411 | 430 | $options['pc_switcher'] = 1; |
| 412 | - update_option( $this->options, $options ); | |
| 431 | + update_option( $this->option_name, $options ); | |
| 413 | 432 | WP_CLI::success( 'turn on PC Switcher' ); |
| 414 | 433 | } |
| 415 | - else if ( 'off' == $flag ) { | |
| 434 | + elseif ( 'off' === $flag ) { | |
| 416 | 435 | $options['pc_switcher'] = 0; |
| 417 | - update_option( $this->options, $options ); | |
| 436 | + update_option( $this->option_name, $options ); | |
| 418 | 437 | WP_CLI::success( 'turn off PC Switcher' ); |
| 419 | 438 | } |
| 420 | 439 | else { |
| 421 | 440 | WP_CLI::error( 'Invalid flag' ); |
| @@ -422,9 +441,9 @@ | ||
| 422 | 441 | } |
| 423 | 442 | } |
| 424 | 443 | |
| 425 | 444 | /** |
| 426 | - * turn on/off default CSS | |
| 445 | + * Turn on/off default CSS | |
| 427 | 446 | * |
| 428 | 447 | * ## OPTIONS |
| 429 | 448 | * |
| 430 | 449 | * <flag> |
| @@ -439,22 +458,22 @@ | ||
| 439 | 458 | * # turn off default CSS |
| 440 | 459 | * wp multi-device css off |
| 441 | 460 | * |
| 442 | 461 | * @synopsis <flag> |
| 443 | - */ | |
| 462 | + */ | |
| 444 | 463 | public function css( $args, $assoc_args ) { |
| 445 | 464 | $flag = isset( $args[0] ) ? $args[0] : null; |
| 446 | 465 | |
| 447 | - $options = get_option( $this->options ); | |
| 466 | + $options = get_option( $this->option_name ); | |
| 448 | 467 | |
| 449 | - if ( 'on' == $flag ) { | |
| 468 | + if ( 'on' === $flag ) { | |
| 450 | 469 | $options['default_css'] = 1; |
| 451 | - update_option( $this->options, $options ); | |
| 470 | + update_option( $this->option_name, $options ); | |
| 452 | 471 | WP_CLI::success( 'turn on default CSS' ); |
| 453 | 472 | } |
| 454 | - else if ( 'off' == $flag ) { | |
| 473 | + elseif ( 'off' === $flag ) { | |
| 455 | 474 | $options['default_css'] = 0; |
| 456 | - update_option( $this->options, $options ); | |
| 475 | + update_option( $this->option_name, $options ); | |
| 457 | 476 | WP_CLI::success( 'turn off default CSS' ); |
| 458 | 477 | } |
| 459 | 478 | else { |
| 460 | 479 | WP_CLI::error( 'Invalid flag' ); |