コード例 #1
0
 /**
  * Render authorization page
  *
  * @return null|WP_Error Null on success, error otherwise
  */
 public function render_page()
 {
     // Check required fields
     if (empty($_REQUEST['oauth_token'])) {
         return new WP_Error('json_oauth1_missing_param', sprintf(__('Missing parameter %s', 'rest_oauth1'), 'oauth_token'), array('status' => 400));
     }
     // Set up fields
     $token_key = wp_unslash($_REQUEST['oauth_token']);
     $scope = '*';
     if (!empty($_REQUEST['wp_scope'])) {
         $scope = wp_unslash($_REQUEST['wp_scope']);
     }
     $authenticator = new WP_REST_OAuth1();
     $errors = array();
     $this->token = $authenticator->get_request_token($token_key);
     if (is_wp_error($this->token)) {
         return $this->token;
     }
     if (!empty($_REQUEST['oauth_callback'])) {
         $resp = $authenticator->set_request_token_callback($this->token['key'], $_REQUEST['oauth_callback']);
         if (is_wp_error($resp)) {
             return $resp;
         }
     }
     if ($this->token['authorized'] === true) {
         return $this->handle_callback_redirect($this->token['verifier']);
     }
     // Fetch consumer
     $this->consumer = $consumer = get_post($this->token['consumer']);
     if (!empty($_POST['wp-submit'])) {
         check_admin_referer('json_oauth1_authorize');
         switch ($_POST['wp-submit']) {
             case 'authorize':
                 $verifier = $authenticator->authorize_request_token($this->token['key']);
                 if (is_wp_error($verifier)) {
                     return $verifier;
                 }
                 return $this->handle_callback_redirect($verifier);
             case 'cancel':
                 exit;
             default:
                 return new WP_Error('json_oauth1_invalid_action', __('Invalid authorization action', 'rest_oauth1'), array('status' => 400));
         }
     }
     $file = locate_template('oauth1-authorize.php');
     if (empty($file)) {
         $file = dirname(dirname(__FILE__)) . '/theme/oauth1-authorize.php';
     }
     include $file;
 }