Automattic / sensei

Sensei LMS - Online Courses, Quizzes, & Learning
https://senseilms.com
GNU General Public License v2.0
545 stars 199 forks source link

Fatal Error when Memberships and Sensei used together #1811

Closed jessepearson closed 7 years ago

jessepearson commented 7 years ago

Reported in 574957-zd-woothemes.

This method call can return null if no content is found. If it does return null, then there's a fatal error encountered in the next foreach loop.

danjjohnson commented 7 years ago

Thanks @jessepearson - I had another report of this in 576964-zd-woothemes with the following error:

PHP Fatal error: Call to a member function get_posts() on null in .../wp-content/plugins/woothemes-sensei/includes/class-sensei-wc-memberships.php on line 136

I couldn't reproduce, but a temporary solution is to disable the "Auto-start courses belonging to a membership" setting in Sensei > Settings > WooCommerce Memberships.

@pgk can you take a look when you get chance?

lisaleague commented 7 years ago

Actually the courses are auto-starting without this option checked - I did not have this checked (was likely added after I first set up Sensei and Memberships) and just went to look at this setting today, as I was unaware of this option. Customer this AM was confused by instructions on how to start the course from the My Account page - When switching to customer with User Switching Course is already started. I checked out for a course to verify this. Instead of the start course button, the button shown is Reset Course.

jessepearson commented 7 years ago

@danjjohnson Sorry for not including the error message, but that's the same one I was getting.

The work around you mentioned works. I believe it's simply due to there are no content restrictions in the membership plan purchased.

pgk commented 7 years ago

@danjjohnson @jessepearson

Fix on the PR above. I see why this might happen although I don't understand the domain logic behind returning a null restricted content.

It is ambiguous, does it mean we have no restrictions setup on that membership (which I think is edge-casey) or that we can access all content?

For the PR above I assume it's the first.

A wp_query with no results might have been a better indicator for the first case.