Beispiel #1
0
 /**
  * Get comment url
  *
  * ## OPTIONS
  *
  * <id>...
  * : One or more IDs of comments to get the URL.
  *
  * ## EXAMPLES
  *
  *     $ wp comment url 123
  *     http://example.com/about/page-with-comments/#comment-123
  */
 public function url($args)
 {
     parent::_url($args, 'get_comment_link');
 }
Beispiel #2
0
 /**
  * Delete a comment.
  *
  * ## OPTIONS
  *
  * <id>...
  * : One or more IDs of comments to delete.
  *
  * [--force]
  * : Skip the trash bin.
  *
  * ## EXAMPLES
  *
  *     # Delete comment.
  *     $ wp comment delete 1337 --force
  *     Success: Deleted comment 1337.
  *
  *     # Delete multiple comments.
  *     $ wp comment delete 1337 2341 --force
  *     Success: Deleted comment 1337.
  *     Success: Deleted comment 2341.
  */
 public function delete($args, $assoc_args)
 {
     parent::_delete($args, $assoc_args, function ($comment_id, $assoc_args) {
         $force = \WP_CLI\Utils\get_flag_value($assoc_args, 'force');
         $status = wp_get_comment_status($comment_id);
         $r = wp_delete_comment($comment_id, $force);
         if ($r) {
             if ($force || 'trash' === $status) {
                 return array('success', "Deleted comment {$comment_id}.");
             } else {
                 return array('success', "Trashed comment {$comment_id}.");
             }
         } else {
             return array('error', "Failed deleting comment {$comment_id}.");
         }
     });
 }
Beispiel #3
0
 /**
  * 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');
 }
 /**
  * Create a product with licensing enabled.
  *
  * ## Options
  *
  * <title>
  * : Product Title
  *
  * <price>
  * : Product price. Formatted as a float.
  *
  * --file=<file>
  * : Attachment ID used for download
  *
  * --limit=<limit>
  * : Activation limit. Variants are not supported. Pass 0 for unlimited.
  *
  * [--key-type=<key-type>]
  * : Key type. Default: random.
  *
  * [--online-software=<online-software>]
  * : Enable online software tools like remote deactivation. Default: true
  *
  * [--version=<version>]
  * : Initial version. Default: 1.0
  *
  * [--description=<description>]
  * : Short product description. 3-5 sentences max.
  *
  * @param $args
  * @param $assoc_args
  */
 public function create($args, $assoc_args)
 {
     list($title, $price) = $args;
     $fn = array($this, 'create_product');
     parent::_create($args, $assoc_args, function ($params) use($title, $price, $fn) {
         return call_user_func($fn, $title, $price, $params);
     });
 }
Beispiel #5
0
 /**
  * Get site url
  *
  * ## OPTIONS
  *
  * <id>...
  * : One or more IDs of sites to get the URL.
  *
  * ## EXAMPLES
  *
  *     wp site url 123
  */
 public function url($args)
 {
     if (!is_multisite()) {
         WP_CLI::error('This is not a multisite install.');
     }
     parent::_url($args, 'get_site_url');
 }
Beispiel #6
0
 /**
  * Delete a post by ID.
  *
  * ## OPTIONS
  *
  * <id>...
  * : One or more IDs of posts to delete.
  *
  * [--force]
  * : Skip the trash bin.
  *
  * [--defer-term-counting]
  * : Recalculate term count in batch, for a performance boost.
  *
  * ## EXAMPLES
  *
  *     wp post delete 123 --force
  *
  *     wp post delete $(wp post list --post_type='page' --format=ids)
  *
  *     # delete all posts in the trash
  *     wp post delete $(wp post list --post_status=trash --format=ids)
  */
 public function delete($args, $assoc_args)
 {
     $defaults = array('force' => false);
     $assoc_args = array_merge($defaults, $assoc_args);
     parent::_delete($args, $assoc_args, function ($post_id, $assoc_args) {
         $status = get_post_status($post_id);
         $r = wp_delete_post($post_id, $assoc_args['force']);
         if ($r) {
             $action = $assoc_args['force'] || 'trash' === $status ? 'Deleted' : 'Trashed';
             return array('success', "{$action} post {$post_id}.");
         } else {
             return array('error', "Failed deleting post {$post_id}.");
         }
     });
 }
 /**
  * Create a license key.
  *
  * Requires manual purchases add-on.
  *
  * ## Options
  *
  * <product>
  * : Product ID.
  *
  * <customer>
  * : Customer ID
  *
  * [<key>]
  * : Optionally, specify the license key to be used.
  *
  * [--limit=<limit>]
  * : Activation limit. Defaults to lowest value available.
  * Set to '-' for unlimited.
  *
  * [--amount-paid=<amount-paid>]
  * : The amount the customer paid for this key. Defaults to the product
  * base price.
  *
  * [--expires=<expires>]
  * : License key expiry date.
  * Default: forever. Accepts strtotime compatible value. GMT.
  *
  * [--status=<status>]
  * : Key status. Accepts: active, expired, disabled. Default: active
  *
  * @param $args
  * @param $assoc_args
  */
 public function create($args, $assoc_args)
 {
     list($ID, $customer, $key) = array_pad($args, 3, '');
     $product = itelic_get_product($ID);
     if (!$product || !$product->has_feature('licensing')) {
         WP_CLI::error("Invalid product.");
     }
     $customer = it_exchange_get_customer($customer);
     if (!$customer) {
         WP_CLI::error("Invalid customer.");
     }
     $create_args = array('product' => $product->ID, 'customer' => $customer->id, 'key' => $key, 'status' => \WP_CLI\Utils\get_flag_value($assoc_args, 'status', \ITELIC\Key::ACTIVE));
     if (isset($assoc_args['limit'])) {
         $create_args['limit'] = $assoc_args['limit'];
     }
     if (isset($assoc_args['expires'])) {
         $create_args['expires'] = $assoc_args['expires'];
     }
     if (isset($assoc_args['amount-paid'])) {
         $create_args['paid'] = $assoc_args['amount-paid'];
     } else {
         $create_args['paid'] = $product->get_feature('base-price');
     }
     parent::_create($args, $assoc_args, function () use($create_args) {
         try {
             $key = itelic_create_key($create_args);
             if (!$key) {
                 WP_CLI::error("Unknown error occurred.");
             }
             return $key->get_pk();
         } catch (Exception $e) {
             WP_CLI::error($e->getMessage());
         }
         WP_CLI::error("Unknown error occurred.");
     });
 }
Beispiel #8
0
 /**
  * Get post url
  *
  * ## OPTIONS
  *
  * <id>...
  * : One or more IDs of posts get the URL.
  *
  * ## EXAMPLES
  *
  *     wp post url 123
  *
  *     wp post url 123 324
  */
 public function url($args)
 {
     parent::_url($args, 'get_permalink');
 }
 /**
  * Create a release.
  *
  * [<file>]
  * : Read changelog from <file> Passing `-` as the filename will cause
  * changelog to be read from STDIN
  *
  * --product=<product>
  * : ID of the product being released.
  *
  * --version=<version>
  * : Version number of the release being created.
  *
  * --file=<file>
  * : ID of the attachment being used for the software download.
  *
  * --type=<type>
  * : Type of release. Accepted values: major, minor, security, pre-release
  *
  * [--status=<status>]
  * : Status of the release. Accepted values: draft, active. Default: draft
  *
  * [--changelog=<changelog>]
  * : What changed in this release. Version number and date omitted. HTML
  * allowed.
  *
  * [--edit]
  * : Immediately open system's editor to write or edit changelog.
  *
  * [--porcelain]
  * : Output just the new release ID.
  *
  * @param $args
  * @param $assoc_args
  */
 public function create($args, $assoc_args)
 {
     if (!empty($args[0])) {
         $assoc_args['changelog'] = $this->read_from_file_or_stdin($args[0]);
     }
     if (\WP_CLI\Utils\get_flag_value($assoc_args, 'edit')) {
         $input = \WP_CLI\Utils\get_flag_value($assoc_args, 'post_content', '');
         $output = \WP_CLI\Utils\launch_editor_for_input($input, 'WP-CLI: New Release Changelog');
         if ($output) {
             $assoc_args['changelog'] = $output;
         } else {
             $assoc_args['changelog'] = $input;
         }
     }
     $assoc_args = wp_parse_args($assoc_args, array('status' => \ITELIC\Release::STATUS_DRAFT, 'changelog' => ''));
     parent::_create($args, $assoc_args, function ($params) {
         $product = itelic_get_product($params['product']);
         if (!$product) {
             WP_CLI::error('Invalid product ID.');
         }
         $version = $params['version'];
         $file = get_post($params['file']);
         if (!$file) {
             WP_CLI::error('Invalid post ID for download file.');
         }
         $type = $params['type'];
         $status = $params['status'];
         if (!in_array($status, array(\ITELIC\Release::STATUS_ACTIVE, \ITELIC\Release::STATUS_DRAFT))) {
             WP_CLI::error("Invalid status.");
         }
         $changelog = $params['changelog'];
         try {
             $args = array('product' => $product, 'file' => $file, 'version' => $version, 'type' => $type, 'status' => $status, 'changelog' => $changelog);
             $release = itelic_create_release($args);
             if (is_wp_error($release)) {
                 return $release;
             }
             return $release->get_pk();
         } catch (Exception $e) {
             WP_CLI::error($e->getMessage());
         }
     });
 }
 /**
  * Activate a release.
  *
  * ## OPTIONS
  *
  * <location>
  * : Where the software is being activated. Typically a website.
  *
  * <key>
  * : The key being activated.
  *
  * [--when=<when>]
  * : Wen the activation occurred. Accepts strtotime compatible
  * value. GMT.
  *
  * [--version=<version>]
  * : The version of the software installed. Default: latest.
  *
  * [--track=<track>]
  * : Accepted values: stable, pre-release. Default: stable
  *
  * [--porcelain]
  * : Output just the new activation ID.
  *
  * @param $args
  * @param $assoc_args
  */
 public function activate($args, $assoc_args)
 {
     list($location, $key) = $args;
     $key = itelic_get_key($key);
     if (!$key) {
         WP_CLI::error("Invalid key.");
     }
     if ($key->get_status() != ITELIC\Key::ACTIVE) {
         WP_CLI::error(sprintf("Key has a status of '%s' not 'active'.", $key->get_status()));
     }
     if (isset($assoc_args['when'])) {
         $when = \ITELIC\make_date_time($assoc_args['when']);
     } else {
         $when = null;
     }
     if (isset($assoc_args['version'])) {
         $release = itelic_get_release_by_version($key->get_product()->ID, $assoc_args['version']);
         if (!$release) {
             WP_CLI::error(sprintf("Invalid release ID %d.", $assoc_args['release']));
         }
     } else {
         $release = null;
     }
     if (isset($assoc_args['track'])) {
         if (in_array($assoc_args['track'], array('stable', 'pre-release'))) {
             $track = $assoc_args['track'];
         } else {
             WP_CLI::error("Invalid value '%s' for track.");
         }
     } else {
         $track = 'stable';
     }
     parent::_create($args, $assoc_args, function () use($location, $key, $when, $release, $track) {
         $a = itelic_activate_license_key($key, $location, $when, $release, $track);
         if ($a) {
             return $a->get_pk();
         }
         return new WP_Error();
     });
 }