create user class and make use of it
This commit is contained in:
@@ -8,6 +8,10 @@ class Wiass_REST_User_API {
|
|||||||
*/
|
*/
|
||||||
private static $namespace = 'wiaas';
|
private static $namespace = 'wiaas';
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
include_once dirname( __FILE__ ) . '/user/class-wiaas-user-profile.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
register_rest_route( self::$namespace, 'user/validate-token', array(
|
register_rest_route( self::$namespace, 'user/validate-token', array(
|
||||||
@@ -39,21 +43,8 @@ class Wiass_REST_User_API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function get_countries(){
|
public static function get_countries(){
|
||||||
$result = [
|
$countries = Wiaas_User_Profile::get_list_of_countries();
|
||||||
array(
|
|
||||||
'idCountry' => '1',
|
|
||||||
'countryName' => 'Sweden'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'idCountry' => '2',
|
|
||||||
'countryName' => 'Finland'
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'idCountry' => '3',
|
|
||||||
'countryName' => 'Denmark'
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
return new WP_REST_Response($result);
|
return new WP_REST_Response($countries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// Exit if accessed directly
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
class Wiaas_User_Profile {
|
||||||
|
|
||||||
|
const LIST_OF_COUNTRIES = [
|
||||||
|
array(
|
||||||
|
'idCountry' => '1',
|
||||||
|
'countryName' => 'Sweden'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'idCountry' => '2',
|
||||||
|
'countryName' => 'Finland'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'idCountry' => '3',
|
||||||
|
'countryName' => 'Denmark'
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
public static function get_list_of_countries(){
|
||||||
|
return self::LIST_OF_COUNTRIES;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function check_country_id($id){
|
||||||
|
foreach (self::LIST_OF_COUNTRIES as $country){
|
||||||
|
if ($country['idCountry'] === $id) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_country_name_by_id($id){
|
||||||
|
foreach(self::LIST_OF_COUNTRIES as $country){
|
||||||
|
if ($country['idCountry'] === $id) return $country['countryName'];
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user