/** * Update one or more comments. * * ## OPTIONS * * <id>... * : One or more IDs of comments to update. * * --<field>=<value> * : One or more fields to update. See wp_update_comment(). * * ## EXAMPLES * * wp comment update 123 --comment_author='That Guy' */ public function update($args, $assoc_args) { parent::_update($args, $assoc_args, function ($params) { if (!wp_update_comment($params)) { return new WP_Error('Could not update comment.'); } return true; }); }
/** * Update a user. * * ## OPTIONS * * <user>... * : The user login, user email or user ID of the user(s) to update. * * --<field>=<value> * : One or more fields to update. For accepted fields, see wp_update_user(). * * ## EXAMPLES * * # Update user * $ wp user update 123 --display_name=Mary --user_pass=marypass * Success: Updated user 123. */ public function update($args, $assoc_args) { if (isset($assoc_args['user_login'])) { WP_CLI::warning("User logins can't be changed."); unset($assoc_args['user_login']); } $user_ids = array(); foreach ($this->fetcher->get_many($args) as $user) { $user_ids[] = $user->ID; } parent::_update($user_ids, $assoc_args, 'wp_update_user'); }
/** * Update one or more posts. * * ## OPTIONS * * <id>... * : One or more IDs of posts to update. * * [<file>] * : Read post content from <file>. If this value is present, the * `--post_content` argument will be ignored. * * Passing `-` as the filename will cause post content to * be read from STDIN. * * --<field>=<value> * : One or more fields to update. See wp_update_post(). * * [--defer-term-counting] * : Recalculate term count in batch, for a performance boost. * * ## EXAMPLES * * wp post update 123 --post_name=something --post_status=draft */ public function update($args, $assoc_args) { foreach ($args as $key => $arg) { if (is_numeric($arg)) { continue; } $assoc_args['post_content'] = $this->read_from_file_or_stdin($arg); unset($args[$key]); break; } if (isset($assoc_args['post_category'])) { $assoc_args['post_category'] = explode(',', $assoc_args['post_category']); } parent::_update($args, $assoc_args, function ($params) { return wp_update_post($params, true); }); }
/** * Update a product. * * ## Options * * <ID> * : Product ID * * --<field>=<value> * : One or more fields to update. * Accepted: online-software, update-file, variants-enabled, base-price, * limit, key-type * * @param $args * @param $assoc_args */ public function update($args, $assoc_args) { list($ID) = $args; $product = $this->fetcher->get_check($ID); $white_list = array('online-software', 'update-file', 'variants-enabled', 'base-price', 'limit', 'key-type'); foreach ($assoc_args as $arg => $val) { if (!in_array($arg, $white_list)) { WP_CLI::error(sprintf("Invalid update param '%s'", $arg)); } } $key_types = itelic_get_key_types(); if (isset($assoc_args['key-type']) && !isset($key_types[$assoc_args['key-type']])) { WP_CLI::error(sprintf("Invalid key type '%s'", $assoc_args['key-type'])); } parent::_update($args, $assoc_args, function ($params) use($product) { if (isset($params['variants-enabled'])) { $params['enabled_variant_activations'] = $params['variants-enabled']; } if (isset($params['base-price'])) { $product->update_feature('base-price', $params['base-price']); } return $product->update_feature('licensing', $params); }); }
/** * Update one or more posts. * * ## OPTIONS * * <id>... * : One or more IDs of posts to update. * * --<field>=<value> * : One or more fields to update. See wp_update_post(). * * ## EXAMPLES * * wp post update 123 --post_name=something --post_status=draft */ public function update($args, $assoc_args) { parent::_update($args, $assoc_args, function ($params) { return wp_update_post($params, true); }); }