本文整理汇总了PHP中WP_CLI::get_value_from_arg_or_stdin方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_CLI::get_value_from_arg_or_stdin方法的具体用法?PHP WP_CLI::get_value_from_arg_or_stdin怎么用?PHP WP_CLI::get_value_from_arg_or_stdin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_CLI
的用法示例。
在下文中一共展示了WP_CLI::get_value_from_arg_or_stdin方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update an option.
*
* ## OPTIONS
*
* <key>
* : The name of the option to add.
*
* [<value>]
* : The new value. If ommited, the value is read from STDIN.
*
* [--format=<format>]
* : The serialization format for the value. Default is plaintext.
*
* ## EXAMPLES
*
* # Update an option by reading from a file
* wp option update my_option < value.txt
*
* # Update one option on multiple sites using xargs
* wp site list --field=url | xargs -n1 -I {} sh -c 'wp --url={} option update <key> <value>'
*
* @alias set
*/
public function update($args, $assoc_args)
{
$key = $args[0];
$value = WP_CLI::get_value_from_arg_or_stdin($args, 1);
$value = WP_CLI::read_value($value, $assoc_args);
$result = update_option($key, $value);
// update_option() returns false if the value is the same
if (!$result && $value != get_option($key)) {
WP_CLI::error("Could not update option '{$key}'.");
} else {
WP_CLI::success("Updated '{$key}' option.");
}
}
示例2: update
/**
* Update an option.
*
* ## OPTIONS
*
* <key>
* : The name of the option to add.
*
* [<value>]
* : The new value. If ommited, the value is read from STDIN.
*
* [--autoload=<autoload>]
* : Requires WP 4.2. Should this option be automatically loaded. Accepted values: yes, no. Default: yes
*
* [--format=<format>]
* : The serialization format for the value. Default is plaintext.
*
* ## EXAMPLES
*
* # Update an option by reading from a file
* wp option update my_option < value.txt
*
* # Update one option on multiple sites using xargs
* wp site list --field=url | xargs -n1 -I {} sh -c 'wp --url={} option update <key> <value>'
*
* @alias set
*/
public function update($args, $assoc_args)
{
$key = $args[0];
$value = WP_CLI::get_value_from_arg_or_stdin($args, 1);
$value = WP_CLI::read_value($value, $assoc_args);
$autoload = \WP_CLI\Utils\get_flag_value($assoc_args, 'autoload');
if (!in_array($autoload, array('yes', 'no'))) {
$autoload = null;
}
$value = sanitize_option($key, $value);
$old_value = sanitize_option($key, get_option($key));
if ($value === $old_value && is_null($autoload)) {
WP_CLI::success("Value passed for '{$key}' option is unchanged.");
} else {
if (update_option($key, $value, $autoload)) {
WP_CLI::success("Updated '{$key}' option.");
} else {
WP_CLI::error("Could not update option '{$key}'.");
}
}
}
示例3: update
/**
* Update a meta field.
*
* ## OPTIONS
*
* <id>
* : The ID of the object.
*
* <key>
* : The name of the meta field to update.
*
* [<value>]
* : The new value. If ommited, the value is read from STDIN.
*
* [--format=<format>]
* : The serialization format for the value. Default is plaintext.
*
* @alias set
*/
public function update($args, $assoc_args)
{
list($object_id, $meta_key) = $args;
$meta_value = \WP_CLI::get_value_from_arg_or_stdin($args, 2);
$meta_value = \WP_CLI::read_value($meta_value, $assoc_args);
$success = \update_metadata($this->meta_type, $object_id, $meta_key, $meta_value);
if ($success) {
\WP_CLI::success("Updated custom field.");
} else {
\WP_CLI::error("Failed to update custom field.");
}
}
示例4: update
/**
* Update an option.
*
* ## OPTIONS
*
* <key>
* : The name of the option to add.
*
* [<value>]
* : The new value. If ommited, the value is read from STDIN.
*
* [--format=<format>]
* : The serialization format for the value. Default is plaintext.
*
* ## EXAMPLES
*
* # Update an option by reading from a file
* wp option update my_option < value.txt
*
* # Update one option on multiple sites using xargs
* wp site list --field=url | xargs -n1 -I {} sh -c 'wp --url={} option update <key> <value>'
*
* @alias set
*/
public function update($args, $assoc_args)
{
$key = $args[0];
$value = WP_CLI::get_value_from_arg_or_stdin($args, 1);
$value = WP_CLI::read_value($value, $assoc_args);
$value = sanitize_option($key, $value);
$old_value = sanitize_option($key, get_option($key));
if ($value === $old_value) {
WP_CLI::success("Value passed for '{$key}' option is unchanged.");
} else {
if (update_option($key, $value)) {
WP_CLI::success("Updated '{$key}' option.");
} else {
WP_CLI::error("Could not update option '{$key}'.");
}
}
}
示例5: update
/**
* Update a meta field.
*
* ## OPTIONS
*
* <id>
* : The ID of the object.
*
* <key>
* : The name of the meta field to update.
*
* [<value>]
* : The new value. If ommited, the value is read from STDIN.
*
* [--format=<format>]
* : The serialization format for the value. Default is plaintext.
*
* @alias set
*/
public function update($args, $assoc_args)
{
list($object_id, $meta_key) = $args;
$meta_value = \WP_CLI::get_value_from_arg_or_stdin($args, 2);
$meta_value = \WP_CLI::read_value($meta_value, $assoc_args);
$object_id = $this->check_object_id($object_id);
$meta_value = sanitize_meta($meta_key, $meta_value, $this->meta_type);
$old_value = sanitize_meta($meta_key, get_metadata($this->meta_type, $object_id, $meta_key, true), $this->meta_type);
if ($meta_value === $old_value) {
\WP_CLI::success("Value passed for custom field '{$meta_key}' is unchanged.");
} else {
$success = \update_metadata($this->meta_type, $object_id, $meta_key, $meta_value);
if ($success) {
\WP_CLI::success("Updated custom field '{$meta_key}'.");
} else {
\WP_CLI::error("Failed to update custom field '{$meta_key}'.");
}
}
}