*/
        public static function new_user_approval_admin_notification($user_id)
        {
            global $current_site;
            $user = new WP_User($user_id);
            $user_login = stripslashes($user->user_login);
            $user_email = stripslashes($user->user_email);
            if (is_multisite()) {
                $blogname = $current_site->site_name;
            } else {
                // The blogname option is escaped with esc_html on the way into the database in sanitize_option
                // we want to reverse this for the plain text arena of emails.
                $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
            }
            $title = sprintf(__('[%s] New User Awaiting Approval', 'theme-my-login'), $blogname);
            $message = sprintf(__('New user requires approval on your blog %s:', 'theme-my-login'), $blogname) . "\r\n\r\n";
            $message .= sprintf(__('Username: %s', 'theme-my-login'), $user_login) . "\r\n";
            $message .= sprintf(__('E-mail: %s', 'theme-my-login'), $user_email) . "\r\n\r\n";
            $message .= __('To approve or deny this user:'******'theme-my-login') . "\r\n";
            $message .= admin_url('users.php?role=pending');
            $title = apply_filters('user_approval_admin_notification_title', $title, $user_id);
            $message = apply_filters('user_approval_admin_notification_message', $message, $user_id);
            $to = apply_filters('user_approval_admin_notification_mail_to', get_option('admin_email'));
            @wp_mail($to, $title, $message);
        }
    }
    Theme_My_Login_User_Moderation::get_object();
}
if (is_admin()) {
    include_once dirname(__FILE__) . '/admin/user-moderation-admin.php';
}
 /**
  * Applies user moderation mail filters according to moderation type
  *
  * Callback for "register_post" hook in Theme_My_Login::register_new_user()
  *
  * @see Theme_My_Login::register_new_user()
  * @since 6.1
  * @access public
  */
 public function apply_user_moderation_notification_filters()
 {
     if (!class_exists('Theme_My_Login_User_Moderation')) {
         return;
     }
     $moderation_type = Theme_My_Login_User_Moderation::get_object()->get_option('type');
     switch ($moderation_type) {
         case 'email':
             $this->set_mail_headers($this->get_option(array('user_activation', 'mail_from')), $this->get_option(array('user_activation', 'mail_from_name')), $this->get_option(array('user_activation', 'mail_content_type')));
             add_filter('user_activation_notification_title', array(&$this, 'user_activation_notification_title_filter'), 10, 2);
             add_filter('user_activation_notification_message', array(&$this, 'user_activation_notification_message_filter'), 10, 3);
             break;
         case 'admin':
             $this->set_mail_headers($this->get_option(array('user_approval', 'admin_mail_from')), $this->get_option(array('user_approval', 'admin_mail_from_name')), $this->get_option(array('user_approval', 'admin_mail_content_type')));
             add_filter('user_approval_admin_notification_mail_to', array(&$this, 'user_approval_admin_notification_mail_to_filter'));
             add_filter('user_approval_admin_notification_title', array(&$this, 'user_approval_admin_notification_title_filter'), 10, 2);
             add_filter('user_approval_admin_notification_message', array(&$this, 'user_approval_admin_notification_message_filter'), 10, 2);
             break;
     }
 }
/**
* 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;
}
 /**
  * Attaches actions/filters explicitly to users.php
  *
  * Callback for "load-users.php" hook
  *
  * @since 6.0
  * @access public
  */
 public function load_users_page()
 {
     add_action('admin_notices', array(&$this, 'admin_notices'));
     // 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';
             switch ($_GET['action']) {
                 case 'approve':
                     check_admin_referer('approve-user');
                     if (!self::approve_user($user)) {
                         wp_die(__('You can’t edit that user.', 'theme-my-login'));
                     }
                     $redirect_to = add_query_arg('update', 'approve', $redirect_to);
                     break;
                 case 'resendactivation':
                     check_admin_referer('resend-activation');
                     do_action('tml_user_activation_resend', $user);
                     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);
                     break;
             }
             wp_redirect($redirect_to);
             exit;
         }
     }
 }
 /**
  * Activates this module
  *
  * Callback for "tml_activate_user-moderation/user-moderation.php" hook in method Theme_My_Login_Admin::activate_module()
  *
  * @see Theme_My_Login_Admin::activate_module()
  * @since 6.0
  * @access public
  *
  * @param object $theme_my_login Reference to global $theme_my_login object
  */
 function activate(&$theme_my_login)
 {
     $options = Theme_My_Login_User_Moderation::init_options();
     $theme_my_login->options->set_option('moderation', $options['moderation']);
     $email = array_merge((array) $theme_my_login->get_option('email'), $options['email']);
     $theme_my_login->options->set_option('email', $email);
 }
Пример #6
0
/**
* 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;
}
Пример #7
0
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;
}
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;
}