Support » Plugin: Join My Multisite » Should this be used in conjunction with Multisite Emails and Redirects?

  • Resolved marikamitsos

    (@marikamitsos)


    Hello and thank you for time and work.

    We are testing the plugin on a multisite together with your other scripts “Multisite Emails and Redirects” found at: https://halfelf.org/2016/multisite-redirect-registrtation-per-site/

    For some reason we get an PHP notice on the login screen:
    PHP Notice: Undefined property: WP_Error::$ID in /wp-content/mu-plugins/multisite-registration.php on line 99
    Line 99 corresponds to the second line of the code “Redirect Logins to Their Site”:

    add_filter('login_redirect', function ( $redirect_to, $request_redirect_to, $user ) {
        if ($user->ID != 0) {
            $user_info = get_userdata($user->ID);
            if ($user_info->primary_blog) {
                $primary_url = get_blogaddress_by_id($user_info->primary_blog) . 'wp-admin/';
                if ($primary_url) {
                    wp_redirect($primary_url);
                    die();
                }
            }
        }
        return $redirect_to;
    }, 100, 3);

    I understand it is only a notice, but it shows right up on the login screen and looks really bad.

    Could you please help?

    thank you in advance
    marikamitsos

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Ipstenu (Mika Epstein)

    (@ipstenu)

    ๐Ÿณ๏ธโ€๐ŸŒˆ Halfelf Rogue & Plugin Review Team Rep

    The second line, so you mean if ($user->ID != 0) { ?

    If so, then it’s not getting valid data for $user (which probably means the ID value cannot be found as it’s not defined).

    You could try to check isset( $user->ID ) for that, but something’s preventing the user data from being passed through, so that’s really the ultimate issue.

    marikamitsos

    (@marikamitsos)

    Thank you for the reply.

    I don’t see how the data can be “lost”. It would mean that WordPress does not understand that the user (before logging in) is a mere visitor (or not).
    We also use the domain mapping plugin. Could this be causing the issue?
    Also. Could you please explain where/how we should use isset( $user->ID ) within the code itself?

    Plugin Author Ipstenu (Mika Epstein)

    (@ipstenu)

    ๐Ÿณ๏ธโ€๐ŸŒˆ Halfelf Rogue & Plugin Review Team Rep

    It’s not ‘lost’ it’s just not sending VALID data.

    It would mean that WordPress does not understand that the user (before logging in) is a mere visitor (or not).

    No, it means that something is preventing the data stored in $user from being properly passed on:

    add_filter('login_redirect', function ( $redirect_to, $request_redirect_to, $user ) {
    

    That’s where $user is collected. So most likely you have something ELSE on your install that’s messing around with user variables when created and that’s somehow breaking the ID.

    I believe you’d want to change if ($user->ID != 0) { to if (isset( $user->ID ) && $user->ID != 0) {

    However all of this is outside the scope of plugin support. This is random one-off code I don’t actually support (which is why it wasn’t included in the plugin). You’re going to have to do some experimentation on your own.

    marikamitsos

    (@marikamitsos)

    Hi and sorry for the late reply,
    We tried your suggestion and it DOES work.
    Thank you so much.

    We now have to figure out what is causing the issue.

    However all of this is outside the scope of plugin support. This is random one-off code I donโ€™t actually support (which is why it wasnโ€™t included in the plugin).

    Nevertheless you were very helpful.

    Thanks again

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Should this be used in conjunction with Multisite Emails and Redirects?’ is closed to new replies.