/** * Attaches actions/filters explicitly to users.php * * Callback for "load-users.php" hook * * @since 6.0 * @access public */ function load_users_page() { add_filter('user_row_actions', array(&$this, 'user_row_actions'), 10, 2); add_action('admin_notices', array(&$this, 'admin_notices')); add_action('delete_user', array(&$this, 'deny_user')); // Is there an action? if (isset($_GET['action'])) { // Is it a sanctioned action? if (in_array($_GET['action'], array('approve', 'resendactivation'))) { // Is there a user ID? $user = isset($_GET['user']) ? $_GET['user'] : ''; // No user ID? if (!$user || !current_user_can('edit_user', $user)) { wp_die(__('You can’t edit that user.', 'theme-my-login')); } // Where did we come from? $redirect_to = isset($_REQUEST['wp_http_referer']) ? remove_query_arg(array('wp_http_referer', 'updated', 'delete_count'), stripslashes($_REQUEST['wp_http_referer'])) : 'users.php'; // Are we approving? if ('approve' == $_GET['action']) { check_admin_referer('approve-user'); if (!Theme_My_Login_User_Moderation_Admin::approve_user($user)) { wp_die(__('You can’t edit that user.', 'theme-my-login')); } $redirect_to = add_query_arg('update', 'approve', $redirect_to); } elseif ('resendactivation' == $_GET['action']) { check_admin_referer('resend-activation'); if (!Theme_My_Login_User_Moderation::new_user_activation_notification($user)) { wp_die(__('The e-mail could not be sent.', 'theme-my-login') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...', 'theme-my-login')); } $redirect_to = add_query_arg('update', 'sendactivation', $redirect_to); } wp_redirect($redirect_to); exit; } } }
/** * Authenticate a user within wordpress * * Ref: http://codex.wordpress.org/Function_Reference/wp_set_auth_cookie * Ref: http://codex.wordpress.org/Function_Reference/wp_safe_redirect */ function wsl_process_login_authenticate_wp_user($user_id, $provider, $redirect_to, $adapter, $hybridauth_user_profile, $wp_user) { // HOOKABLE: do_action("wsl_process_login_authenticate_wp_user_start", $user_id, $provider, $redirect_to, $adapter, $hybridauth_user_profile, $wp_user); // update some fields in usermeta for the current user update_user_meta($user_id, 'wsl_current_provider', $provider); if ($hybridauth_user_profile->photoURL) { update_user_meta($user_id, 'wsl_current_user_image', $hybridauth_user_profile->photoURL); } // Bouncer::User Moderation // > When Bouncer::User Moderation is enabled, WSL will check for the current user role. If equal to 'pending', then Bouncer will do the following : // 1. Halt the authentication process, // 2. Skip setting the authentication cookies for the user, // 3. Reset the Redirect URL to the appropriate Theme My Login page. $wsl_settings_bouncer_new_users_moderation_level = get_option('wsl_settings_bouncer_new_users_moderation_level'); // current user role $role = current($wp_user->roles); // if role eq 'pending', we halt the authentication and we redirect the user to the appropriate url (pending=activation or pending=approval) if ($role == 'pending') { // E-mail Confirmation if ($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"; // send a new e-mail/activation notification - if TML not enabled, we ensure WSL to keep it quiet $errors = new WP_Error(); do_action('register_post', $wp_user->user_nicename, $wp_user->{$user_email}, $errors); @Theme_My_Login_User_Moderation::new_user_activation_notification($user_id); } elseif ($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: This action runs just before logging the user in (before creating a WP cookie) do_action("wsl_hook_process_login_before_wp_set_auth_cookie", $user_id, $provider, $hybridauth_user_profile); // DEPRECIATED: as of 2.2.3 // do_action( 'wsl_hook_process_login_before_set_auth_cookie', $user_id, $provider, $hybridauth_user_profile ); // Set WP auth cookie wp_set_auth_cookie($user_id, true); // let keep it std do_action('wp_login', $wp_user->user_login, $wp_user); } // HOOKABLE: This action runs just before redirecting the user back to $redirect_to // > Note: If you have enabled User Moderation, then the user is NOT NECESSARILY CONNECTED // > within wordpress at this point (in case the user $role == 'pending'). // > To be sure the user is connected, use wsl_hook_process_login_before_wp_set_auth_cookie instead. do_action("wsl_hook_process_login_before_wp_safe_redirect", $user_id, $provider, $hybridauth_user_profile, $redirect_to); // DEPRECIATED: as of 2.2.3 // do_action( 'wsl_hook_process_login_before_set_auth_cookie', $user_id, $provider, $hybridauth_user_profile ); do_action('wsl_clear_user_php_session'); // Display WSL debugging instead of redirecting the user // > this will give a complete report on what wsl did : database queries and fired hooks // wsl_display_dev_mode_debugging_area(); die(); // ! keep this line commented unless you know what you are doing :) // That's it. We done. wp_safe_redirect($redirect_to); // for good measures die; }
function wsl_process_login_authenticate_wp_user($user_id, $provider, $redirect_to, $adapter, $hybridauth_user_profile) { // 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 update_user_meta($user_id, 'wsl_user', $provider); update_user_meta($user_id, 'wsl_user_gender', $hybridauth_user_profile->gender); update_user_meta($user_id, 'wsl_user_age', $user_age); update_user_meta($user_id, 'wsl_user_image', $hybridauth_user_profile->photoURL); // 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; }
/** * Authenticate a user within wordpress * * Ref: http://codex.wordpress.org/Function_Reference/wp_set_auth_cookie * Ref: http://codex.wordpress.org/Function_Reference/wp_safe_redirect */ function wsl_process_login_authenticate_wp_user($user_id, $provider, $redirect_to, $adapter, $hybridauth_user_profile, $wp_user) { // HOOKABLE: do_action("wsl_process_login_authenticate_wp_user_start", $user_id, $provider, $redirect_to, $adapter, $hybridauth_user_profile, $wp_user); // update some fields in usermeta for the current user update_user_meta($user_id, 'wsl_current_provider', $provider); //update_user_meta( $user_id, 'wsl_'.$provider , $provider ); //var_dump($hybridauth_user_profile); //die(); //$existing_user = wsl_get_stored_hybridauth_user_profiles_by_user_id($user_id); //var_dump($existing_user); die(); $disciplines = array("dota" => 1, "cs" => 2); $regions = array("CES" => 1, "CN" => 2, "EU" => 3); $method = ""; if ($provider == "Steam") { $user_current_steam = get_user_meta($user_id, 'user_steam'); $region = "CES"; $discipline_name = "dota"; $discipline_data = array(); if ($user_current_steam[$discipline_name]) { $user_current_steam = json_decode($user_current_steam); $discipline_data = $user_current_steam[$discipline_name]; $method = "PUT"; } else { $method = "POST"; } if ($discipline_name and $region) { if ($hybridauth_user_profile->identifier) { $discipline_data[$discipline_name]["steam_id"] = $hybridauth_user_profile->identifier; } if ($hybridauth_user_profile->displayName) { $discipline_data[$discipline_name]["steam_displayName"] = $hybridauth_user_profile->displayName; } if ($hybridauth_user_profile->photoURL) { $discipline_data[$discipline_name]["steam_avatar"] = $hybridauth_user_profile->photoURL; } $discipline_data[$discipline_name]["region"] = $region; } CallSLTVAPI($method, "http://api.sltv.pro/api/v1/user_disciplines", array('user_id' => $user_id, 'discipline_id' => $disciplines[$discipline_name], 'region_id' => $regions[$region], 'game_unique_id' => $discipline_data["steam_id"])); $discipline_data = json_encode($discipline_data); update_user_meta($user_id, 'user_steam', $discipline_data); } if ($hybridauth_user_profile->photoURL) { update_user_meta($user_id, 'wsl_current_user_image', $hybridauth_user_profile->photoURL); } // Bouncer::User Moderation // > When Bouncer::User Moderation is enabled, WSL will check for the current user role. If equal to 'pending', then Bouncer will do the following : // 1. Halt the authentication process, // 2. Skip setting the authentication cookies for the user, // 3. Reset the Redirect URL to the appropriate Theme My Login page. $wsl_settings_bouncer_new_users_moderation_level = get_option('wsl_settings_bouncer_new_users_moderation_level'); // current user role $role = current($wp_user->roles); // if role eq 'pending', we halt the authentication and we redirect the user to the appropriate url (pending=activation or pending=approval) if ($role == 'pending') { // E-mail Confirmation if ($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"; // send a new e-mail/activation notification - if TML not enabled, we ensure WSL to keep it quiet @Theme_My_Login_User_Moderation::new_user_activation_notification($user_id); } elseif ($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: This action runs just before logging the user in (before creating a WP cookie) do_action("wsl_hook_process_login_before_wp_set_auth_cookie", $user_id, $provider, $hybridauth_user_profile); // DEPRECIATED: as of 2.2.3 // do_action( 'wsl_hook_process_login_before_set_auth_cookie', $user_id, $provider, $hybridauth_user_profile ); // Set WP auth cookie wp_set_auth_cookie($user_id, true); // let keep it std do_action('wp_login', $wp_user->user_login, $wp_user); } // HOOKABLE: This action runs just before redirecting the user back to $redirect_to // > Note: If you have enabled User Moderation, then the user is NOT NECESSARILY CONNECTED // > within wordpress at this point (in case the user $role == 'pending'). // > To be sure the user is connected, use wsl_hook_process_login_before_wp_set_auth_cookie instead. do_action("wsl_hook_process_login_before_wp_safe_redirect", $user_id, $provider, $hybridauth_user_profile, $redirect_to); // DEPRECIATED: as of 2.2.3 // do_action( 'wsl_hook_process_login_before_set_auth_cookie', $user_id, $provider, $hybridauth_user_profile ); do_action('wsl_clear_user_php_session'); // Display WSL debugging instead of redirecting the user // > this will give a complete report on what wsl did : database queries and fired hooks // wsl_display_dev_mode_debugging_area(); die(); // ! keep this line commented unless you know what you are doing :) // That's it. We done. wp_safe_redirect($redirect_to); // for good measures die; }
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; }