Skip to content

Swift Developer Blog

Learn Swift and App Development for iOS

  • Swift Blog
    • UITableView
    • UIImageView
    • UIScrollView
    • UIWebView
    • SubView
    • UIImagePickerController
    • UIPageViewController
    • UITabBarController
    • UIAlertController
    • UISegmentedControl
    • Xcode
    • Firebase
  • Video Tutorials
  • Code Examples
    • Code examples
    • Cheat Sheets
  • Resources
    • Swift Developer
  • Full stack
    • Developer Resources
    • Android & Kotlin
    • Java
    • RESTful Web Services
    • Amazon Web Services
    • Firebase with Kotlin
    • Firebase with Swift
    • Hibernate
    • Git
    • Design Patterns
  • About
  • Contact me
  • Home
  • User login and Registration with Swift
  • Integrate your mobile app with Wordpress users table
April 4, 2015 by Sergey Kargopolov 7 comments on "Integrate your mobile app with WordPress users table"

Integrate your mobile app with Wordpress users table

In this video I am showing you how to create PHP scripts that will help you create a new WordPress user and then check if WordPress user with provided user name and password exists. You can use these scripts to make your app store user details in WordPress users table and let WordPress Users login with same credentials into your mobile app.


Register New User Example PHP script


/*
* Template Name: Register New User Example
*/
$user_name = htmlentities($_REQUEST[“user_name”]);
$user_password = htmlentities($_REQUEST[“user_password”]);
$user_email = htmlentities($_REQUEST[“user_email”]);
$user_url = htmlentities($_REQUEST[“user_url”]);
$display_name = htmlentities($_REQUEST[“display_name”]);
$role = ‘author’;if(empty($user_name) || empty($user_password) || empty($user_email) || empty($display_name))
{
$returnValue = array(“Status”=>”error”,”Message”=>”Missing required field”);
echo json_encode($returnValue);
return;
}

if ( username_exists( $user_name ) )
{
$returnValue = array(“Status”=>”error”,”Message”=>”User exists”);
echo json_encode($returnValue);
return;
}

//$user_password = wp_hash_password($user_password);

$userdata = array(
‘user_login’ => $user_name,
‘user_url’ => $user_url,
‘user_pass’ => $user_password,
‘user_email’ => $user_email,
‘display_name’ => $display_name,
‘role’ => $role
);

$user_id = wp_insert_user( $userdata ) ;
$user = new WP_User($user_id);
$user->set_role($role);

if(!empty($user_id))
{
$returnValue = array(“Status”=>”ok”,”Message”=>”Subscriber created”);
echo json_encode($returnValue);
}

/*
$user_password = wp_hash_password($user_password);

global $wpdb;

$insertUser = “INSERT INTO $wpdb->users (user_login, user_pass, user_email, user_url, display_name) VALUES (‘$user_name’, ‘$user_password’, ‘$user_email’, ‘$user_url’)”;
$wpdb->query( $insertUser );

$user_id = $wpdb->get_var($wpdb->prepare(“SELECT id FROM $wpdb->users WHERE user_email = %s”, $user_email));

$my_user = new WP_User( $user_id );
$my_user->set_role( “author” );
*/

?>

 

Check user name and password PHP Script

/*
* Template Name: Check user name and password
*/

$user_name = htmlentities($_REQUEST[“user_name”]);
$user_password = htmlentities($_REQUEST[“user_password”]);

if(empty($user_name) || empty($user_password) )
{
$returnValue = array(“Status”=>”error”,”Message”=>”Missing required field”);
echo json_encode($returnValue);
return;
}

$user = get_user_by( ‘login’, $user_name );
if ( $user && wp_check_password( $user_password, $user->data->user_pass, $user->ID) )
{
$returnValue = array(“Status”=>”ok”,”UserStatus”=>”1″,”Message”=>”User exists”);
echo json_encode($returnValue);
}
else
{
$returnValue = array(“Status”=>”ok”,”UserStatus”=>”0″,”Message”=>”User is not found”);
echo json_encode($returnValue);
}

?>

 

To learn how to create user interface for Register/Sign up and Login functionality with Swift please watch videos below:

Posted in: User login and Registration with Swift
Tagged: PHP, Wordpress

Post navigation

Previous Previous post: User Registration/Sign up and login example with Swift and Parse
Next Next post: Creating custom user interface files with XIB in Xcode 6 and Swift

Primary Sidebar

Find videos

Unit Testing Swift?

Unit Testing Swift Mobile App

Recent Posts

  • Inject JavaScript into WKWebView
  • WKWebView. Load HTML File from App Bundle.
  • UIImagePickerController in Swift with Firebase. Cheat Sheet.
  • Firebase Realtime Database Cheat Sheet
  • Push Notifications with Firebase Cloud Messaging – Cheat Sheet

Search by Tag

AWS Facebook Facebook SDK Facebook Sign in Firebase HTTP HTTP Get HTTP Post Icon Java Keychain Load Images Login MMDrawerController MySQL Navigation Drawer NSURLSession Parse Password PHP Push Notifications Search Sign in SubView Swift UIActivityIndicator UIAlertController UIImage UIImagePickerController UIImageView UIPageViewController UIScrollView UISearchBar UISegmentedControl UITabBarController UITableView UITableViewCell UITableViewController UITableViewDatasource UIWebView Upload Xcode Xcode Tips Xcode Tips and Tricks XIB

Featured posts

  • Left side menu (Navigation Drawer) example with Swift
  • Creating custom user interface files with XIB in Xcode 6 and Swift
  • Add Subview and Remove subview example in Swift
  • Customize UINavigationBar appearance in Swift
  • MBProgressHUD example in Swift
  • iOS Keychain example in Swift
  • Image Upload with Progress Bar example in Swift
  • Circular Image or Image with Rounded Corners. Example in Swift

Copyright © 2023 Swift Developer Blog. Powered by WordPress and Themelia.

Would you like more video tutorials weekly?
  • Swift programming with Parse. Practical Examples.
  • Swift programming with PHP and MySQL. Practical examples.
  • iOS Mobile Apps Development with Swift

Enter your email and stay on top of things,

Subscribe!