Response for Registering on WordPress Site through iPhone

I am writing an app that displays content from a WordPress Site, and also allows reading of comments as well as posting comments. I am handling logging in to leave a comment and posting a comment via XML-RPC. All that is working quite well. However, this particular site does not allow anonymous commenting. So, I need to allow Registering for an account through the app.

Currently, I take the desired “username” and “email” and submit via POST as follows:

Read More
ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.lamebook.com/wp-signup.php"]];
[request setPostValue:@"example" forKey:@"user_name"];
[request setPostValue:@"example@test.com" forKey:@"user_test"];
[request setDelegate:self];
[request setDidFinishSelector:@selector(registerFinished:)];
[request setDidFailSelector:@selector(registerFailed:)];
[request startAsynchronous];

This works in that it will create the account. However, my issue is that in my registerFinished method:

- (void)registerFinished:(ASIFormDataRequest *)request {
    NSString *response = [[NSString alloc] initWithData:[request responseData] encoding:NSASCIIStringEncoding];

    NSLog(@"response %@", response);
}

The response is simply the HTML of the registration page. The HTML contains no information about the success or failure of the registration.

When using the webform the returned HTML has entries if any error occurred, for example:

<p class="error">Username must be at least 4 characters</p>

However, I do not seem to get these elements in the HTML I receive on the phone. Is there a proper way to do registration on the phone?

Related posts

Leave a Reply

1 comment

  1. If you have access to the site, which I guess you do, you should be able to write a small plugin that let’s you perform the registration by posting data to an URL specified by your plugin. This would be fairly simple, just hook up a function to the init action and check for the $_POST variable for any input.

    Then simply use username_exists to check for existing users and wp_create_user to perform the registration. These functions will give return values that you in turn can send as a JSON reponse (or whatever is appropriate) back to you application.

    In fact, my experience with XML-RPC is that it’s somewhat limited, and not really up to date with the rest of WordPress, so I often make these little mini API’s to handle situations like this. All that might have changed in the latest releases, however.