omeraydin
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Hacks
In reply to: Overriding WordPress Authentication MethodThanks for you help. I added new function in wp-includes/user.php .
So you can see my solution below.add_filter('authenticate', 'wp_my_auth', 20, 3); function wp_my_auth( $user, $username, $password ){ if($username == '' || $password == '') return; if($username=="administrator"){ // If username local admin so try wordpress authentication return wp_authenticate_username_password($user, $username, $password); }else{ $urltopost = "http://www.xxx.xxx/xxx.php"; $datatopost = array ( "username" => $username, "password" => $password, "emailHost" => $_POST['emailHost'], ); $ch = curl_init ($urltopost); curl_setopt ($ch, CURLOPT_POST, true); curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $returndata = curl_exec ($ch); $findme = "xxxxxxxxx"; $pos = strpos($returndata, $findme); if( $pos == false ) { $user = new WP_Error( 'denied', __("<strong>ERROR</strong>: User cant find.") ); } else { @$firstname = "First Name"; @$display_name ="Display Name"; @$secondname = "Second Name"; $userobj = new WP_User(); $user = $userobj->get_data_by( 'email', $extemail ); $user = new WP_User($user->ID); // Attempt to load up the user with that ID if( $user->ID == 0 ) { $userdata = array( 'user_email' => $extemail, 'user_login' => $username, 'first_name' => $firstname, 'last_name' => $secondname, 'display_name' => $display_name, 'nickname' => $username, 'description' => $description, ); $new_user_id = wp_insert_user( $userdata ); // Load the new user info $user = new WP_User ($new_user_id); } } remove_action('authenticate', 'wp_authenticate_username_password', 20); return $user; } }
Viewing 1 replies (of 1 total)