/**
* Register new wsl admin tab
*/
function wsl_register_admin_tab($tab, $config)
{
    global $WORDPRESS_SOCIAL_LOGIN_ADMIN_TABS;
    // sure it can be overwritten.. just not recommended
    if (isset($WORDPRESS_SOCIAL_LOGIN_ADMIN_TABS[$tab])) {
        return wsl_render_notices_pages(_wsl__("An installed plugin is trying to o-ver-write WordPress Social Login config in a bad way.", 'wordpress-social-login'));
    }
    $WORDPRESS_SOCIAL_LOGIN_ADMIN_TABS[$tab] = $config;
}
Esempio n. 2
0
*    (c) 2011-2013 Mohamed Mrassi and contributors | http://wordpress.org/extend/plugins/wordpress-social-login/
*/
/**
* Site Info 
* borrowed from http://wordpress.org/extend/plugins/easy-digital-downloads/
*/
// --------------------------------------------------------------------
// load wp-load.php
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/../wp-load.php';
// only logged in users
if (!is_user_logged_in()) {
    wsl_render_notices_pages('You do not have sufficient permissions to access this page.');
}
// only display for admin
if (!current_user_can('manage_options')) {
    wsl_render_notices_pages('You do not have sufficient permissions to access this page.');
}
session_start();
?>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Website Information</title>
<head>  
<style>
html {
	background: #f9f9f9;
}
#wsl {
	background: #fff;
	color: #333;
function wsl_process_login_create_wp_user($provider, $hybridauth_user_profile, $request_user_login, $request_user_email)
{
    // HOOKABLE: any action to fire right before a user created on database
    do_action('wsl_hook_process_login_before_create_wp_user');
    $user_login = null;
    $user_email = null;
    // if coming from "complete registration form"
    if ($request_user_email && $request_user_login) {
        $user_login = $request_user_login;
        $user_email = $request_user_email;
    } else {
        // generate a valid user login
        $user_login = trim(str_replace(' ', '_', strtolower($hybridauth_user_profile->displayName)));
        $user_email = $hybridauth_user_profile->email;
        if (empty($user_login)) {
            $user_login = trim($hybridauth_user_profile->lastName . " " . $hybridauth_user_profile->firstName);
        }
        if (empty($user_login)) {
            $user_login = strtolower($provider) . "_user_" . md5($hybridauth_user_profile->identifier);
        }
        // user name should be unique
        if (username_exists($user_login)) {
            $i = 1;
            $user_login_tmp = $user_login;
            do {
                $user_login_tmp = $user_login . "_" . $i++;
            } while (username_exists($user_login_tmp));
            $user_login = $user_login_tmp;
        }
        // generate an email if none
        if (!isset($user_email) or !is_email($user_email)) {
            $user_email = strtolower($provider . "_user_" . $user_login) . "@example.com";
        }
        // email should be unique
        if (email_exists($user_email)) {
            do {
                $user_email = md5(uniqid(wp_rand(10000, 99000))) . "@example.com";
            } while (email_exists($user_email));
        }
        $user_login = sanitize_user($user_login, true);
        if (!validate_username($user_login)) {
            $user_login = strtolower($provider) . "_user_" . md5($hybridauth_user_profile->identifier);
        }
    }
    $display_name = $hybridauth_user_profile->displayName;
    if ($request_user_login || empty($display_name)) {
        $display_name = $user_login;
    }
    $userdata = array('user_login' => $user_login, 'user_email' => $user_email, 'display_name' => $display_name, 'first_name' => $hybridauth_user_profile->firstName, 'last_name' => $hybridauth_user_profile->lastName, 'user_url' => $hybridauth_user_profile->profileURL, 'description' => $hybridauth_user_profile->description, 'user_pass' => wp_generate_password());
    // Bouncer :: Membership level
    if (get_option('wsl_settings_bouncer_new_users_membership_default_role') != "default") {
        $userdata['role'] = get_option('wsl_settings_bouncer_new_users_membership_default_role');
    }
    // Bouncer :: User Moderation : None
    if (get_option('wsl_settings_bouncer_new_users_moderation_level') == 1) {
        // well do nothing..
    }
    // Bouncer :: User Moderation : Yield to Theme My Login plugin
    if (get_option('wsl_settings_bouncer_new_users_moderation_level') > 100) {
        $userdata['role'] = "pending";
    }
    // HOOKABLE: change the user data
    if (apply_filters('wsl_hook_process_login_alter_userdata', $userdata, $provider, $hybridauth_user_profile)) {
        $userdata = apply_filters('wsl_hook_process_login_alter_userdata', $userdata, $provider, $hybridauth_user_profile);
    }
    // HOOKABLE: any action to fire right before a user created on database
    do_action('wsl_hook_process_login_before_insert_user', $userdata, $provider, $hybridauth_user_profile);
    // HOOKABLE: delegate user insert to a custom function
    $user_id = apply_filters('wsl_hook_process_login_alter_insert_user', $userdata, $provider, $hybridauth_user_profile);
    // Create a new user
    if (!$user_id || !is_integer($user_id)) {
        $user_id = wp_insert_user($userdata);
    }
    // update user metadata
    if ($user_id && is_integer($user_id)) {
        update_user_meta($user_id, $provider, $hybridauth_user_profile->identifier);
    } else {
        if (is_wp_error($user_id)) {
            echo $user_id->get_error_message();
        } else {
            return wsl_render_notices_pages(_wsl__("An error occurred while creating a new user!", 'wordpress-social-login'));
        }
    }
    // Send notifications
    if (get_option('wsl_settings_users_notification') == 1) {
        wsl_admin_notification($user_id, $provider);
    }
    // HOOKABLE: any action to fire right after a user created on database
    do_action('wsl_hook_process_login_after_create_wp_user', $user_id, $provider, $hybridauth_user_profile);
    return array($user_id, $user_login, $user_email);
}
function wsl_process_login_authenticate_wp_user($user_id, $provider, $redirect_to, $adapter, $hybridauth_user_profile)
{
    // There was a bug when this function received non-integer user_id and updated random users, let's be safe
    if (!is_integer($user_id)) {
        return wsl_render_notices_pages(_wsl__("Invalid user_id", 'wordpress-social-login'));
    }
    // calculate user age
    $user_age = $hybridauth_user_profile->age;
    // not that precise you say... well welcome to my world
    if (!$user_age && (int) $hybridauth_user_profile->birthYear) {
        $user_age = (int) date("Y") - (int) $hybridauth_user_profile->birthYear;
    }
    // update some stuff
    $newdata['user_id'] = $user_id;
    //not to be changed
    $newdata['user'] = $provider;
    $newdata['user_gender'] = $hybridauth_user_profile->gender;
    $newdata['user_age'] = $user_age;
    $newdata['user_image'] = $hybridauth_user_profile->photoURL;
    // HOOKABLE:
    $newdata = apply_filters('wsl_hook_process_login_alter_update_userdata', $newdata, $hybridauth_user_profile, $provider);
    update_user_meta($user_id, 'wsl_user', $newdata['user']);
    update_user_meta($user_id, 'wsl_user_gender', $newdata['user_gender']);
    update_user_meta($user_id, 'wsl_user_age', $newdata['user_age']);
    update_user_meta($user_id, 'wsl_user_image', $newdata['user_image']);
    // launch contact import if enabled
    wsl_import_user_contacts($provider, $adapter, $user_id);
    // store user hybridauth user profile if needed
    wsl_store_hybridauth_user_data($user_id, $provider, $hybridauth_user_profile);
    // Bouncer :: User Moderation : E-mail Confirmation — Yield to Theme My Login plugin
    if (get_option('wsl_settings_bouncer_new_users_moderation_level') == 101) {
        $redirect_to = site_url('wp-login.php', 'login_post') . (strpos(site_url('wp-login.php', 'login_post'), '?') ? '&' : '?') . "pending=activation";
        @Theme_My_Login_User_Moderation::new_user_activation_notification($user_id);
    } elseif (get_option('wsl_settings_bouncer_new_users_moderation_level') == 102) {
        $redirect_to = site_url('wp-login.php', 'login_post') . (strpos(site_url('wp-login.php', 'login_post'), '?') ? '&' : '?') . "pending=approval";
    } else {
        // HOOKABLE:
        do_action("wsl_hook_process_login_before_set_auth_cookie", $user_id, $provider, $hybridauth_user_profile);
        // That's it. create a session for user_id and redirect him to redirect_to
        wp_set_auth_cookie($user_id);
    }
    // HOOKABLE:
    do_action("wsl_hook_process_login_before_redirect", $user_id, $provider, $hybridauth_user_profile);
    wp_safe_redirect($redirect_to);
    exit;
}