/** * ## OPTIONS * * [--name=<name>] * : Consumer name * * [--description=<description>] * : Consumer description */ public function add($_, $args) { $authenticator = new WP_JSON_Authentication_OAuth1(); $consumer = $authenticator->add_consumer($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. */ function json_oauth_admin_handle_edit_submit($consumer) { $messages = array(); if (empty($consumer)) { $did_action = 'add'; check_admin_referer('json-oauth-add'); } else { $did_action = 'edit'; check_admin_referer('json-oauth-edit-' . $consumer->ID); } // Check that the parameters are correct first $params = json_oauth_admin_validate_parameters(wp_unslash($_POST)); if (is_wp_error($params)) { $messages[] = $params->get_error_message(); return $messages; } if (empty($consumer)) { $authenticator = new WP_JSON_Authentication_OAuth1(); // Create the consumer $data = array('name' => $params['name'], 'description' => $params['description']); $consumer = $result = $authenticator->add_consumer($data); } else { // Update the existing consumer post $data = array('ID' => $consumer->ID, 'post_title' => $params['name'], 'post_content' => $params['description']); $result = wp_update_post($data, true); } if (is_wp_error($result)) { $messages[] = $result->get_error_message(); return $messages; } // Success, redirect to alias page $location = add_query_arg(array('action' => 'json-oauth-edit', 'id' => $consumer->ID, 'did_action' => $did_action, 'processed' => 1, '_wpnonce' => wp_create_nonce('json-oauth-edit-' . $id)), network_admin_url('admin.php')); wp_safe_redirect($location); exit; }