Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support new upstream autoload options #496

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion features/option-get-autoload.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Feature: Get 'autoload' value for an option
"""
Error: Could not get 'foo' option. Does it exist?
"""

@less-than-wp-6.6
Scenario: Displays 'autoload' value
Given a WP install

Expand All @@ -23,3 +23,18 @@ Feature: Get 'autoload' value for an option
"""
yes
"""
@require-wp-6.6
Scenario: Displays 'autoload' value
Given a WP install

When I run `wp option add foo bar`
Then STDOUT should contain:
"""
Success:
"""

When I run `wp option get-autoload foo`
Then STDOUT should be:
"""
on
"""
35 changes: 35 additions & 0 deletions features/option-set-autoload.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Feature: Set 'autoload' value for an option
Error: Invalid value specified for positional arg.
"""

@less-than-wp-6.6
Scenario: Successfully updates autoload value
Given a WP install

Expand Down Expand Up @@ -56,3 +57,37 @@ Feature: Set 'autoload' value for an option
"""
no
"""

@require-wp-6.6
Scenario: Successfully updates autoload value
Given a WP install

When I run `wp option add foo bar`
Then STDOUT should contain:
"""
Success:
"""

When I run `wp option get-autoload foo`
Then STDOUT should be:
"""
on
"""

When I run `wp option set-autoload foo off`
Then STDOUT should be:
"""
Success: Updated autoload value for 'foo' option.
"""

When I run the previous command again
Then STDOUT should be:
"""
Success: Autoload value passed for 'foo' option is unchanged.
"""

When I run `wp option get-autoload foo`
Then STDOUT should be:
"""
off
"""
32 changes: 28 additions & 4 deletions features/option.feature
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ Feature: Manage WordPress options
"""

@require-wp-4.2
@less-than-wp-6.6
Scenario: Update autoload value for custom option
Given a WP install
And I run `wp option add hello world --autoload=no`
Expand All @@ -160,7 +161,30 @@ Feature: Manage WordPress options
| option_name | option_value | autoload |
| hello | island | yes |

@require-wp-6.6
Scenario: Update autoload value for custom option
Given a WP install
And I run `wp option add hello world --autoload=off`

When I run `wp option update hello universe`
Then STDOUT should not be empty

When I run `wp option list --search='hello' --fields=option_name,option_value,autoload`
Then STDOUT should be a table containing rows:
| option_name | option_value | autoload |
| hello | universe | off |

When I run `wp option update hello island --autoload=on`
Then STDOUT should not be empty

When I run `wp option list --search='hello' --fields=option_name,option_value,autoload`
Then STDOUT should be a table containing rows:
| option_name | option_value | autoload |
| hello | island | on |


@require-wp-4.2
@less-than-wp-6.6
Scenario: Managed autoloaded options
Given a WP install

Expand Down Expand Up @@ -248,11 +272,11 @@ Feature: Manage WordPress options
"""
And the return code should be 0

When I try `wp option list --search='auto_opt' --autoload=no`
When I try `wp option list --search='auto_opt' --autoload=nope`
Then STDOUT should be empty
And STDERR should be:
And STDERR should contain:
ernilambar marked this conversation as resolved.
Show resolved Hide resolved
"""
Error: Value of '--autoload' should be on or off.
Error: Value of '--autoload' should be
"""
And the return code should be 1

Expand All @@ -264,7 +288,7 @@ Feature: Manage WordPress options
"""
And the return code should be 0

When I try `wp option add str_opt_foo 'bar' --autoload=off`
When I try `wp option add str_opt_foo 'bar' --autoload=bad`
Then STDOUT should be empty
And STDERR should contain:
"""
Expand Down
17 changes: 12 additions & 5 deletions src/Option_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public function get( $args, $assoc_args ) {
* : Should this option be automatically loaded.
* ---
* options:
* - 'on'
* - 'off'
* - 'yes'
* - 'no'
* ---
Expand All @@ -125,7 +127,7 @@ public function add( $args, $assoc_args ) {
$value = WP_CLI::get_value_from_arg_or_stdin( $args, 1 );
$value = WP_CLI::read_value( $value, $assoc_args );

if ( Utils\get_flag_value( $assoc_args, 'autoload' ) === 'no' ) {
if ( in_array( Utils\get_flag_value( $assoc_args, 'autoload' ), [ 'no', 'off' ], true ) ) {
$autoload = 'no';
} else {
$autoload = 'yes';
Expand Down Expand Up @@ -271,12 +273,13 @@ public function list_( $args, $assoc_args ) {
}

if ( isset( $assoc_args['autoload'] ) ) {
if ( 'on' === $assoc_args['autoload'] ) {
$autoload = $assoc_args['autoload'];
if ( 'on' === $autoload || 'yes' === $autoload ) {
$autoload_query = " AND autoload='yes'";
} elseif ( 'off' === $assoc_args['autoload'] ) {
} elseif ( 'off' === $autoload || 'no' === $autoload ) {
$autoload_query = " AND autoload='no'";
} else {
WP_CLI::error( "Value of '--autoload' should be on or off." );
WP_CLI::error( "Value of '--autoload' should be 'on', 'off', 'yes', or 'no'." );
}
}

Expand Down Expand Up @@ -360,6 +363,8 @@ function ( $a, $b ) use ( $orderby, $order ) {
* : Requires WP 4.2. Should this option be automatically loaded.
* ---
* options:
* - 'on'
* - 'off'
* - 'yes'
* - 'no'
* ---
Expand Down Expand Up @@ -413,7 +418,7 @@ public function update( $args, $assoc_args ) {
$value = WP_CLI::read_value( $value, $assoc_args );

$autoload = Utils\get_flag_value( $assoc_args, 'autoload' );
if ( ! in_array( $autoload, [ 'yes', 'no' ], true ) ) {
if ( ! in_array( $autoload, [ 'on', 'off', 'yes', 'no' ], true ) ) {
$autoload = null;
}

Expand Down Expand Up @@ -479,6 +484,8 @@ public function get_autoload( $args ) {
* : Should this option be automatically loaded.
* ---
* options:
* - 'on'
* - 'off'
* - 'yes'
* - 'no'
* ---
Expand Down