PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Login redirection broken for users with Author capabilities

s2Member Plugin. A Membership plugin for WordPress®.

Login redirection broken for users with Author capabilities

Postby arwyl » October 26th, 2010, 6:24 pm

Because I want all registered users to be able to blog, I have edited the capabilities of the 'Subscriber' and 's2member level 1' roles with Capability Manager and given them Author permissions. Now, when users log in, they are no longer being redirected to my specified Welcome page, but end up on the home page instead. How do I fix this?

Thanks very much in advance!
In theory, theory and practice are the same; in practice they aren't.
User avatar
arwyl
Experienced User
Experienced User
 
Posts: 6
Joined: October 26, 2010

Re: Login redirection broken for users with Author capabilit

Postby Jason Caldwell » October 27th, 2010, 3:41 am

Thanks for the excellent question.

Well, I wish we had a Hook/Filter that would accomplish this for you. I'll see about adding a Filter in the next release so the method I'm about to describe won't be necessary. Until then, here goes.

Unzip the file that I've attached, and place it into your /mu-plugins/ directory. If you don't have an /mu-plugins/ directory, please create one. MUST USE (mu)-plugins are loaded automatically.

s2-login-redirection.zip
(969 Bytes) Downloaded 4 times

I've added this additional check: $user->has_cap("author")
Code: Select all
<?php
/*
Create this function before s2Member loads it's default version.
    goes here: /wp-content/mu-plugins/s2-login-redirection.php
*/
function ws_plugin__s2member_login_redirect ($username = FALSE)
    {
        eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
        do_action ("ws_plugin__s2member_before_login_redirect", get_defined_vars ());
        unset ($__refs, $__v); /* Unset defined __refs, __v. */
        /**/
        $username = (!$username && is_object ($current_user = wp_get_current_user ())) ? $current_user->user_login : $username;
        /* This additional check was added in case wp_signon() fires this event with empty $_POST credentials.
            In this rare case, we can check to see if WordPress® is remembering a previously logged in User. */
        /**/
        if (!is_object ($user = new WP_User ($username)) || ! ($user_id = $user->ID) || !$user->has_cap ("edit_posts") || $user->has_cap ("author"))
            {
                eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
                do_action ("ws_plugin__s2member_during_login_redirect", get_defined_vars ());
                unset ($__refs, $__v); /* Unset defined __refs, __v. */
                /**/
                if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["custom_reg_password"] && function_exists ("ws_plugin__s2member_generate_password"))
                    {
                        delete_user_setting ("default_password_nag"); /* setcookie() */
                        update_user_option ($user_id, "default_password_nag", false, true);
                    }
                /**/
                if (strtolower ($username) === "demo" || ws_plugin__s2member_ip_restrictions_ok ($_SERVER["REMOTE_ADDR"], strtolower ($username)))
                    {
                        if ($special_redirection_url = ws_plugin__s2member_login_redirection_url ($user))
                            wp_redirect ($special_redirection_url);
                        /**/
                        else
                            wp_redirect 
(get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"]));
                    }
                /**/
                exit ();
            }
        /**/
        eval ('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
        do_action ("ws_plugin__s2member_after_login_redirect", get_defined_vars ());
        unset ($__refs, $__v); /* Unset defined __refs, __v. */
        /**/
        return;
    }
?>
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Login redirection broken for users with Author capabilit

Postby arwyl » October 27th, 2010, 8:30 am

Thank you, Jason, for your prompt reply!

I had already been taking a look at that line in the \wp-content\plugins\s2member\includes\functions\login-redirection.inc.php file, but I hadn't been able to figure out what the right edit to the check was.

Curiously, the check that did the trick was the opposite one:
Code: Select all
if !$user->has_cap ("author")


Maybe because my users are not "proper" Authors, but Subscribers and s2-level-1 members with added capabilities that give them author rights. I'm not sure I understand :? , but it sure is working! Both Subscribers and s2-level-1 members now get redirected to my custom Welcome page, so I can gratefully mark this issue as:

RESOLVED.

Thanks again! :D
In theory, theory and practice are the same; in practice they aren't.
User avatar
arwyl
Experienced User
Experienced User
 
Posts: 6
Joined: October 26, 2010


Return to s2Member Plugin

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron