gocodebox / lifterlms

LifterLMS, a WordPress LMS Solution: Easily create, sell, and protect engaging online courses.
https://lifterlms.com
GNU General Public License v3.0
174 stars 134 forks source link

Add a null check to prevent "Attempt to read property ... on null" PHP warnings. #2577

Open dominiquemariano opened 7 months ago

dominiquemariano commented 7 months ago

Is your feature request related to a problem? Please describe. Some users are reporting the following warnings from their logs:

PHP Warning: Attempt to read property "ID" on null in /wp-content/plugins/lifterlms/templates/course/tags.php on line 15
PHP Warning: Attempt to read property "post_type" on null in /wp-content/plugins/lifterlms/includes/abstracts/abstract.llms.post.model.php on line 473

Describe the solution you'd like Add a null check to prevent this non-fatal warnings.

Describe alternatives you've considered Just disabling PHP warnings on the server.

kimcoleman commented 7 months ago

Curious where these are both triggering / can we recreate?

Here are the related lines in question:

Tags "ID": https://github.com/gocodebox/lifterlms/blob/trunk/templates/course/tags.php#L15

Check probably best to check if there is a post->ID set there in the tags.php file or check here for a post, as the function itself is hooked in several places.

Post Model "post_type": https://github.com/gocodebox/lifterlms/blob/dev/includes/abstracts/abstract.llms.post.model.php#L473