Support » Plugin: Paid Memberships Pro » Course Cats & Paid Membership Pro

  • Course Cats uses this to redirect to Dashboard or specific page based on settings

    function my_pmpro_login_redirect_url($redirect_to, $request, $user) {
    		global $wpdb;
    		//if logged in and a member, send to members page
    		if(pmpro_hasMembershipLevel(NULL, $user->ID)) {
    			
    			$pmp_login_redirect_permalink = "dashboard";
    			
    			if (get_field('pmp_login_redirect_permalink','options')) {
    				$pmp_login_redirect_permalink = get_field('pmp_login_redirect_permalink','options');
    			}
    			
    			return $pmp_login_redirect_permalink;
    		
    		} else {
    			return $redirect_to;
    		}
    	}
    	add_filter("pmpro_login_redirect_url", "my_pmpro_login_redirect_url", 10, 3);

    Now this gives a notice

    ( ! ) Notice: Undefined property: WP_Error::$ID in /srv/www/domain.com/current/web/app/themes/coursenip/functions.php on line 490

    So I thought about adding is_user_logged_in() but when I do have

    if(is_user_logged_in() && pmpro_hasMembershipLevel(NULL, $user->ID)) {

    it just redirect to the Dashboard only. Ideas?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Andrew Lima

    (@andrewza)

    Hi @rhand,

    Thank you for choosing Paid Memberships Pro, I sincerely apologize for the delayed response.

    Here is a simplified example to use the pmpro_login_redirect_url -> https://gist.github.com/strangerstudios/c7b7b9ff6ff6e815bab1, did you work from this example?

    What I would recommend in looking into is Paid Memberships Pro MemberHome Pages as this redirects users with a specific level to a certain page and should help resolve your issue – https://www.paidmembershipspro.com/add-ons/plus-add-ons/member-homepages/

    Would this be sufficient?

    There was worked from the example you mentioned first Andrew. But somehow we get undefined property $ID. Not sure if you would not get the same issue with your snippet, but I need miy adjust version as it uses an ACF field to check whether the redirect url is set or not under options.

    Oddly enough we do use the same global $wpdb. Perhaps another variable needs to be set global to avoid the undefined property error? The user ID can only be checked once logged in though I would think so perhaps that is why.. Having figured it out yet and debugging with xdebug would be nicer without this notice.

    Plugin Author Jason Coleman

    (@strangerstudios)

    Checking if is_user_logged_in() is the right move to catch cases where someone is not logged in yet. I believe when you view a login form, or maybe only when login fails, this WP filter sets $user to a WP error instead of a user object.

    However, it seems like it’s blank on successful logins for you as well.

    Try debuging in your code the $user var there and also the global $current_user to see if $current_user is set. You could maybe use that (or by just calling pmpro_hasMembershipLevel() with no params it will try to use the current user instead of the user object passed in). This may work, but doesn’t really tell us why the $user object is corrupt there. It might be another clever login-related plugin messing with that data before it gets to PMPro? I don’t know. We’d have to debug further.

    We should check if this $user object is empty always on a clean WP/PMPro install running just PMPro and a default theme. If so, there might be a more subtle bug in our code around here that I’m not seeing when glancing at it now. https://github.com/strangerstudios/paid-memberships-pro/blob/5c0762aefd8809f3747fdb53b75e950940c4766b/includes/login.php#L35

    Checking if is_user_logged_in() is the right move to catch cases where someone is not logged in yet. I believe when you view a login form, or maybe only when login fails, this WP filter sets $user to a WP error instead of a user object.

    Yes on the login screen I see this. I can login however and no fatal errors. So I just need to deal with this notice:

    
    Notice: Undefined property: WP_Error::$ID in /srv/www/domain.com/current/web/app/themes/coursenip/functions.php on line 490
    Call Stack
    #	Time	Memory	Function	Location
    1	0.0015	514248	{main}( )	.../wp-login.php:0
    2	0.5919	28580384	apply_filters( )	.../wp-login.php:812
    3	0.5919	28580784	WP_Hook->apply_filters( )	.../plugin.php:203
    4	0.5919	28582288	pmpro_login_redirect( )	.../class-wp-hook.php:298
    5	0.5919	28582288	apply_filters( )	.../login.php:35
    6	0.5919	28582688	WP_Hook->apply_filters( )	.../plugin.php:203
    7	0.5919	28584192	my_pmpro_login_redirect_url( )	.../class-wp-hook.php:298
    

    Will check out https://github.com/strangerstudios/paid-memberships-pro/blob/5c0762aefd8809f3747fdb53b75e950940c4766b/includes/login.php#L35 some more soon. Perhaps the code is missing a final needed else statement..

    • This reply was modified 2 years, 3 months ago by  Rhand.
    • This reply was modified 2 years, 3 months ago by  Rhand.

    Hey, @rhand.

    This is Brad (co-founder of Course Cats). Just wanted to a) follow up and see if you resolved the issue and b) ask you to please reach out to our support team asap – it looks like you are using our theme without our consent and outside of our terms of use as you have canceled your subscription. Thank you.

    We are using your old theme on a live site of which I emailed you the domain as well as a subdomain of https://imagewize.com. We do not really need the subscription of the old theme but your developer helped changing the domain to https://old.coursecats.com so we would not get any errors. And under that old. domain our account is still active.

    For the current old theme the subscription is not really necessary as there will be no updates from your part.We will get a new theme license as soon as we have time to switch. As we made modifications and understood the switch cannot be made just like that we decided to wait. We will need to set up a new staging environment post purchasing of the new theme and see what your new theme breaks.

    As for the error, no not solved. But it is something we can live with for now while we solve other PMP MailChimp issues. Been slow so we may have to move to another solution provider.

    • This reply was modified 2 years, 3 months ago by  Rhand.
    • This reply was modified 2 years, 3 months ago by  Rhand.
    • This reply was modified 2 years, 3 months ago by  Rhand.

    Hi, @rhand. I sent a reply via email, so I’ll just keep it short here. Unfortunately you must have an active subscription in order to use any of our themes, regardless if you need access to the guide or not – i.e. the subscription is required regardless if you’re using the old or new theme. Please reach out to me via email and I can send over a link that you can use to renew your subscription. We can also take a look at this error a bit and see if it’s something our team can assist with if you decide to stick with (PMP, that is).

    Yeah, replied as well. And as you saw licensing is fine.

    • This reply was modified 2 years, 3 months ago by  Rhand.

    All good, yes. Thank you!

    Rhand

    (@rhand)

    For anyone who had the notice issue. I changed the line 490 from:
    if(pmpro_hasMembershipLevel(NULL, $user->ID)) {
    to
    if(pmpro_hasMembershipLevel($levels = NULL, $user_id = NULL)) {
    This seems to have solved the notice issue. This I based on Paid Memberships Pro file plugins/paid-memberships-pro/includes/functions.php.

    Here is the diff

    diff --git a/site/web/app/themes/coursenip/functions.php b/site/web/app/themes/coursenip/functions.php
    index dee0310..b94234c 100644
    --- a/site/web/app/themes/coursenip/functions.php
    +++ b/site/web/app/themes/coursenip/functions.php
    @@ -487,7 +487,7 @@ if (defined('PMPRO_VERSION')) {
            function my_pmpro_login_redirect_url($redirect_to, $request, $user) {
                    global $wpdb;
                    //if logged in and a member, send to members page
    -               if(pmpro_hasMembershipLevel(NULL, $user->ID)) {
    +               if(pmpro_hasMembershipLevel($levels = NULL, $user_id = NULL)) {
                            
                            $pmp_login_redirect_permalink = "dashboard";
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Course Cats & Paid Membership Pro’ is closed to new replies.