Using Wordpress Accounts in an iOS App
Hey I am creating an iOS app. The first window is the login screen where people sign up with their Wordpress blog account. I have reviewed xml-rpc but it does not allow registration from phone. Then I looked at using RESTful api, but I have no idea how to connect it to wordpress db to check if username and password are correct. There are quite a few impulses for wordpress that set up RESTful APIs, but none of them help with what I'm trying to do.
Any help would be much appreciated!
+3
source to share
1 answer
Figured out how to do it. You can do this with xml-rpc. Here's the code I have in my requests plugin in case it ever needs it:
function register_user($args){
require_once( ABSPATH . WPINC . '/registration.php' );
/* Check if users can register. */
$registration = get_option( 'users_can_register' );
/* If user registered, input info. */
$userdata = array(
'user_pass' => esc_attr( $args[2] ),
'user_login' => esc_attr( $args[0] ),
'first_name' => esc_attr( "" ),
'last_name' => esc_attr( "" ),
'nickname' => esc_attr( "" ),
'user_email' => esc_attr( $args[1] ),
'user_url' => esc_attr( "" ),
'aim' => esc_attr( "" ),
'yim' => esc_attr( ""),
'jabber' => esc_attr( "" ),
'description' => esc_attr( "" ),
'role' => get_option( 'default_role' ),
);
if ( !$userdata['user_login'] ){
$error = __('A username is required for registration.', 'frontendprofile');
return "user-invalid";
}elseif ( username_exists($userdata['user_login']) ){
$error = __('Sorry, that username already exists!', 'frontendprofile');
return "user-used";
}elseif ( !is_email($userdata['user_email'], true) ){
$error = __('You must enter a valid email address.', 'frontendprofile');
return "email-invalid";
}elseif ( email_exists($userdata['user_email']) ){
$error = __('Sorry, that email address is already used!', 'frontendprofile');
return "email-used";
}
else{
$new_user = wp_insert_user( $userdata );
wp_new_user_notification($new_user, $user_pass); //send the user an email with the information
return "success";
}
update_user_meta( $args[0]->ID, 'setup', "0" );
}
+1
source to share