WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Getting user info at wp_login hook?

[Resolved] Getting user info at wp_login hook?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hmmm. If you have the user login name by the time you’re firing your plugin, could you use the $wpdb class to query wp_users and wp_usermeta to retrieve the information yourself?

    All the best,

    VoodooLogic

    Voodoo – thanks for prodding me in the direction or doing it from scratct, rather than trying to figure out which global variables weren’t available yet, and tracking those dependencies though everything.

    In the end, I was able to use get_userdatabylogin() to get a copy of the user object, and then I wrote a custom version of current_user_can() that uses get_option() to pull the roles and capabilities out of the db directly. For anyone else’s future reference, this is how I did it:

    function elbe_zp_login( $user_login ) {
    $user = get_userdatabylogin($user_login);
    if (elbe_current_user_can('publish_posts', $user)) {
    elbe_zp_login_user();
    } else {
    // echo "current user cannot publish posts...";
    }
    } // end function


    function elbe_current_user_can($capability, $current_user) {
    //
    $roles = get_option('wp_user_roles');
    $user_roles = $current_user->wp_capabilities;
    $user_roles = array_keys($user_roles, true);
    $role = $user_roles[0];
    $capabilities = $roles[$role]['capabilities'];
    if ( in_array( $capability, array_keys( $capabilities, true) ) ) {
    // check array keys of capabilities for match against requested capability
    return true;
    }
    } // end function

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Getting user info at wp_login hook?’ is closed to new replies.
Skip to toolbar