Private Messaging Login/Register

When a user visits the inbox page before logging in it shows a login and registration form that is generated by private messaging.

I am using custom login and registration forms and need this to either show those or redirect to the login page.

How can I achieve this without editing the core of your plugin?

  • Vaughan

    Hi @sbaker,

    Hope you're well?

    Can you take a screenshot of the page with the last name, or post the URL so I know exactly what i'm looking for so I can try & replicate it?

    with regards to the login, i'm looking at the code, but I don't think this is possible without modifying the plugin core.

    I can see in the file /private-messaging/app/controllers/inbox-shortcode-controller.php

    Lines 91 - 96

    if (!is_user_logged_in()) {
                mmg()->load_script('login');
                return $this->render('shortcode/login', array(
                    'show_nav' => $this->can_show_nav($a['nav_view'])
                ), false);
            }

    But I don't see any hooks to be able to change this without editing that.

    But should you wish to change this so it redirects to your login page, you can edit those lines & add in a redirect instead.

    if (!is_user_logged_in()) {
                $login_page = '/your-login-page/';
                wp_redirect(site_url($login_page));
                exit;
            }

    change your-login-page to the page where your login form is.

    I'll also ask one of our developers to see if there's another solution I haven't found which doesn't require editing the plugin code.

    Hope this helps

  • Hoang Ngo

    Hi @sbaker,

    I hope you are well today.

    Please use the beta version, it fixed the name issue. Also, it contain many other bugs fixes.
    For login redirect, you can use something like this:

    add_filter('the_posts', 'custom_login_redirect', 10, 2);
    
    function custom_login_redirect($posts, WP_Query $query)
    {
        if ($query->is_main_query() && $query->is_page == true && $query->get_queried_object_id() == mmg()->setting()->inbox_page) {
            $login_page = '/your-login-page/';
            wp_redirect(site_url($login_page));
            exit;
        }
        return $posts;
    }

    Please add that code to your theme functions.php or use mu-plugins

    Also, you will need to update the $login_page variable to your login page.

    Best regards,
    Hoang

  • sbaker

    I got the update/beta version installed and things are a little better.

    The login / register part is better as the register button now goes to the login page. Also the code you gave me works great for the redirect.

    The names are now displaying the display name. Would it not be better for this to show the username or can we have an option to display the username?

    The user avatars are now showing sporadically. When I first access the messages screen a few will show. Then when i click a message more show up. It seems there are still some bugs to be worked out in this.

  • Vaughan

    Hi Sbaker,

    Can you try the following code instead.

    add_filter('the_posts', 'custom_login_redirect', 10, 2);
    
    function custom_login_redirect($posts, WP_Query $query)
    {
        if (!is_user_logged_in() && $query->is_main_query() && $query->is_page == true && $query->get_queried_object_id() == mmg()->setting()->inbox_page) {
            $login_page = '/your-login-page/';
            wp_redirect(site_url($login_page));
            exit;
        }
        return $posts;
    }

    Hope this helps