Plugin Directory

Changeset 1938717


Ignore:
Timestamp:
09/10/2018 02:37:18 PM (8 years ago)
Author:
egany
Message:

1.2.5

  • Fixed bug UserInfo - User email existing
  • Fixed "There is no posting of comments" error
  • After logging in to the application using the existing login/password, the first name and last name fields in the user profile are not displayed.
Location:
ultimate-wp-rest/trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • ultimate-wp-rest/trunk/includes/plugin-module-rest-api.php

    r1933535 r1938717  
    2828    $this->addApiMenusInSetting();
    2929    $this->addApiUsersInSetting();
     30    $this->addApiSettingsInSetting();
    3031    $this->addApiCustomInSetting();
    3132
     
    3536    if (UTM_WP_REST_API_AUTH_MODE === 'nonce') {
    3637      if (!function_exists('wp_create_nonce')) {
    37         require_once ABSPATH . "wp-includes/pluggable.php";
     38        require_once ABSPATH . 'wp-includes/pluggable.php';
    3839      }
    3940      define('UTM_WP_REST_API_NONCE', wp_create_nonce('wp_rest'));
     
    5657    $this->setupRestApiUsers();
    5758    $this->setupRestApiMenu();
     59    $this->setupRestApiSettings();
    5860  }
    5961
     
    7476
    7577    if (empty($sToken)) {
    76       if ($bShowData) {
    77         return new WP_Error(
    78           'jwt_invalid_header',
    79           __('Invalid header.', UTM_WP_REST_TEXTDOMAIN),
    80           ['status' => 403]
    81         );
    82       }
    8378      return false;
    8479    }
     
    498493  }
    499494
     495  private function addApiSettingsInSetting() {
     496    $aSetting['option']['UTM_WP_REST_API_SETTINGS'] = [
     497      'title'                         => 'Settings',
     498      'section'                       => 'utm_wp_resttest_api',
     499      'type'                          => 'array',
     500      'value'                         => ['GET'],
     501      'elements'                      => [
     502        ['htmltag' => 'template',
     503          'file'     => 'element-tooltip',
     504          'attr'     => [
     505            'data-tooltip' => '*',
     506          ],
     507        ],
     508        ['htmltag' => 'template',
     509          'file'     => 'element-select',
     510          'attr'     => [
     511            'id'            => 'settings_method',
     512            'data-onchange' => json_encode(['setInputValueFormSelect', '#settings_name']),
     513            'data-onload'   => json_encode(['setInputValueFormSelect', '#settings_name']),
     514          ],
     515          'option'   => [
     516            'settings'         => [
     517              'GET' => 'GET - Get settings',
     518            ],
     519            'settings/version' => [
     520              'GET' => 'GET - Get current version',
     521            ],
     522          ],
     523        ],
     524        ['htmltag' => 'input',
     525          'attr'     => [
     526            'id'       => 'settings_name',
     527            'value'    => '',
     528            'type'     => 'text',
     529            'disabled' => true,
     530          ],
     531        ],
     532        ['htmltag' => 'textarea',
     533          'attr'     => [
     534            'name'   => 'UTM_WP_REST_API_SETTINGS_DATA',
     535            'id'     => 'settings_data',
     536            'format' => 'jsonp',
     537            'style'  => 'height:60px',
     538          ],
     539          'text'     => 'UTM_WP_REST_API_SETTINGS_DATA',
     540        ],
     541        ['htmltag' => 'a',
     542          'text'     => 'Send',
     543          'attr'     => [
     544            'name'         => 'button-ajax',
     545            'style'        => 'width:10rem',
     546            'class'        => 'btn-small red_wp waves-effect waves-light',
     547            'data-onclick' => json_encode(['sendRequestAPI', [
     548              'method' => '#settings_method',
     549              'api'    => '#settings_name',
     550              'data'   => '#settings_data',
     551            ]]),
     552          ],
     553        ],
     554      ],
     555      // Hidden option
     556      'UTM_WP_REST_API_SETTINGS_DATA' => [
     557        'title'   => '',
     558        'section' => 'utm_wp_resttest_api',
     559        'type'    => 'array',
     560        'value'   => [],
     561      ],
     562    ];
     563
     564    $this->PWP->setting->addSettings($aSetting);
     565  }
     566
    500567  private function addApiCustomInSetting() {
    501568    $aSetting['option']['UTM_WP_REST_API_CUSTOM'] = [
     
    601668    add_action('rest_api_init', [$oApiUsers, 'registerRestRoute'], 10);
    602669  }
     670
     671  //////////// API Settings /////////////
     672
     673  // Format:
     674  // - Settings: /wp-json/wp/v2/settings
     675  private function setupRestApiSettings() {
     676    require_once UTM_WP_REST_API_PATH . 'rest-api-settings.php';
     677    $oApiSettings = new RestApiSettings($this->PWP);
     678    add_action('rest_api_init', [$oApiSettings, 'registerRestRoute'], 10);
     679  }
    603680}
  • ultimate-wp-rest/trunk/includes/rest-api/rest-api-users.php

    r1933535 r1938717  
    55class RestApiUsers extends WP_REST_Controller {
    66  protected $meta;
     7  private $oUsersController;
    78
    89  ///////////// Call PWPCore /////////////
     
    1213    define('UTM_WP_REST_API_USERS', '/users');
    1314
    14     $this->meta = new WP_REST_User_Meta_Fields();
     15    $this->meta             = new WP_REST_User_Meta_Fields();
     16    $this->oUsersController = new WP_REST_Users_Controller();
    1517  }
    1618
     
    2426
    2527  public function registerRestRoute() {
    26     $oUsersController = new WP_REST_Users_Controller();
    27 
    2828    // User Register
    2929    register_rest_route(UTM_WP_REST_API_NAMESPACE, UTM_WP_REST_API_USERS . '/register', [
    3030      [
    3131        'methods'             => WP_REST_Server::CREATABLE,
    32         'callback'            => [$oUsersController, 'create_item'],
     32        'callback'            => [$this->oUsersController, 'create_item'],
    3333        'permission_callback' => [$this, 'registerUserPermissionsCheck'],
    3434        'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
     
    7474    ]);
    7575
     76    // Get current user
     77    register_rest_route(UTM_WP_REST_API_NAMESPACE, UTM_WP_REST_API_USERS . '/me', [
     78      [
     79        'methods'  => WP_REST_Server::READABLE,
     80        'callback' => [$this, 'getCurrentUser'],
     81        'args'     => [
     82          'context' => $this->oUsersController->get_context_param(['default' => 'view']),
     83        ],
     84      ],
     85    ]);
     86
    7687    // Token auth
    7788    register_rest_route(UTM_WP_REST_API_NAMESPACE, UTM_WP_REST_API_USERS . '/me/token', [
     
    99110  public function addFieldInfo($oData, $sFieldName, $oRequest) {
    100111    $aUserInfo = [
    101       'username'        => $oData['username'],
    102       'first_name'      => $oData['first_name'],
    103       'last_name'       => $oData['last_name'],
    104       'email'           => $oData['email'],
    105       'nickname'        => $oData['nickname'],
    106       'roles'           => $oData['roles'],
    107       'registered_date' => $oData['registered_date'],
     112      'username'   => $oData['username'],
     113      'first_name' => $oData['first_name'],
     114      'last_name'  => $oData['last_name'],
     115      'email'      => $oData['user_email'],
     116      'nickname'   => $oData['nickname'],
     117      //'roles'           => $oData['roles'],
     118      //'registered_date' => $oData['registered_date'],
     119      //'debug'      => [$oData, $sFieldName, $oRequest],
    108120    ];
    109121    return $aUserInfo;
     
    111123
    112124  public function mergeUserInfo($oResponse, $oUser, $oRequest) {
     125    return new WP_Error('rest_user_not_logged_in', __('You are not currently logged in.', UTM_WP_REST_TEXTDOMAIN), ['status' => 403]);
    113126    $aData     = $this->PWP->tool->objectToArray($oResponse);
    114127    $aUserInfo = $aData['data']['info'];
     
    221234  }
    222235
     236  public function getCurrentUser($oRequest) {
     237    $iUserID = get_current_user_id();
     238
     239    if (empty($iUserID)) {
     240      return new WP_Error('rest_not_logged_in', __('You are not currently logged in.'), ['status' => 401]);
     241    }
     242
     243    $oUser     = wp_get_current_user();
     244    //return new WP_REST_Response($oUser, 200);
     245
     246    $oResponse = $this->oUsersController->prepare_item_for_response($oUser, $oRequest);
     247
     248    $aUserInfo = [
     249      'nickname'   => $oUser->nickname,
     250      'first_name' => $oUser->first_name,
     251      'last_name'  => $oUser->last_name,
     252      'email'      => $oUser->user_email,
     253    ];
     254
     255    $aData = $this->PWP->tool->objectToArray($oResponse);
     256    $aJson = array_merge($aUserInfo, $aData['data']);
     257
     258    return new WP_REST_Response($aJson, 200);
     259  }
     260
    223261  public function checkToken($oRequest) {
    224262    $isValid = $this->PWP->api->validateJwtToken($oRequest['token']);
  • ultimate-wp-rest/trunk/readme.txt

    r1938447 r1938717  
    5151 
    5252== Changelog ==
     53= 1.2.5 =
     54* Fixed bug UserInfo - User email existing
     55* Fixed "There is no posting of comments" error
     56* After logging in to the application using the existing login/password, the first name and last name fields in the user profile are not displayed.
    5357= 1.2.4 =
    5458* Fixed bug login by nonce, update code
  • ultimate-wp-rest/trunk/ultimate_wp_rest.php

    r1933535 r1938717  
    33 * Plugin Name: Ultimate WP REST
    44 * Description: This is a plug-in for the Menus, Thumb APIs, JWT authentication, caching, and many advanced features that help you develop web and mobile applications.
    5  * Version: 1.2.4
     5 * Version: 1.2.5
    66 * Text Domain: wpr
    77 * Author: EGANY
     
    1919// Initialization path plugin
    2020defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
     21define('UTM_WP_REST_PATH', __FILE__);
    2122define('UTM_WP_REST_BASE', realpath(plugin_dir_path(__FILE__)) . DS);
    2223define('UTM_WP_REST_URL', plugin_dir_url(__FILE__));
Note: See TracChangeset for help on using the changeset viewer.