/** * ## OPTIONS * * [--name=<name>] * : Consumer name * * [--description=<description>] * : Consumer description */ public function add($_, $args) { $consumer = WP_REST_OAuth1_Client::create($args); WP_CLI::line(sprintf('ID: %d', $consumer->ID)); WP_CLI::line(sprintf('Key: %s', $consumer->key)); WP_CLI::line(sprintf('Secret: %s', $consumer->secret)); }
/** * Handle submission of the add page * * @return array|null List of errors. Issues a redirect and exits on success. */ protected static function handle_edit_submit($consumer) { $messages = array(); if (empty($consumer)) { $did_action = 'add'; check_admin_referer('rest-oauth1-add'); } else { $did_action = 'edit'; check_admin_referer('rest-oauth1-edit-' . $consumer->ID); } // Check that the parameters are correct first $params = self::validate_parameters(wp_unslash($_POST)); if (is_wp_error($params)) { $messages[] = $params->get_error_message(); return $messages; } if (empty($consumer)) { $authenticator = new WP_REST_OAuth1(); // Create the consumer $data = array('name' => $params['name'], 'description' => $params['description'], 'meta' => array('callback' => $params['callback'])); $consumer = $result = WP_REST_OAuth1_Client::create($data); } else { // Update the existing consumer post $data = array('name' => $params['name'], 'description' => $params['description'], 'meta' => array('callback' => $params['callback'])); $result = $consumer->update($data); } if (is_wp_error($result)) { $messages[] = $result->get_error_message(); return $messages; } // Success, redirect to alias page $location = self::get_url(array('action' => 'edit', 'id' => $consumer->ID, 'did_action' => $did_action)); wp_safe_redirect($location); exit; }