Home › Forums › Legacy Support › Support queries › Other issues › php error suddenly appearing on top of page
- This topic has 5 replies, 2 voices, and was last updated 3 years, 6 months ago by Anshuman Sahu.
Viewing 6 posts - 1 through 6 (of 6 total)
-
AuthorPosts
-
April 27, 2021 at 4:17 pm #354774fdittmarParticipantHi team, hope you're all safe out there..., This is a follow-on from: https://wplms.io/support/forums/topic/restricting-access-to-pages-based-on-course-category/ @Alex, we created a page template 2 years ago that restricts access to pages (based on the template) to certain types of logged-in users only (in this case students with a certain location taxonomy ID). Those pages are now showing a warning at the top of the page (but page still loads OK otherwise): Warning: count(): Parameter must be an array or an object that implements Countable in /home/customer/www/x.com/public_html/wp-content/themes/xchild/pagetemplatefromalexthatrestrictsaccess.php on line 40 Line 40 in that file is this from your original code: if(function_exists('bp_course_get_total_course_count_for_user') && count(bp_course_get_total_course_count_for_user(get_current_user_id())) > 0 ){ Any idea why this would now throw an error message after working for years? thanks On 3.9.9 now - old styleApril 28, 2021 at 2:56 pm #354987Anshuman SahuKeymaster
change the above to :if(function_exists(‘bp_course_get_total_course_count_for_user’) && count(bp_course_get_total_course_count_for_user(get_current_user_id())) > 0 ){
if(function_exists(‘bp_course_get_total_course_count_for_user’) && is_user_logged_in() && bp_course_get_total_course_count_for_user(get_current_user_id()) && count(bp_course_get_total_course_count_for_user(get_current_user_id())) > 0 ){
April 30, 2021 at 5:00 pm #355422fdittmarParticipantHi, Thanks but that gives the same error Warning: count(): Parameter must be an array or an object that implements Countable in xxx line 41 ps. I corrected ‘ for'
as it pasted incorrectly.May 1, 2021 at 2:27 pm #355555Anshuman SahuKeymastercorrected again we dont need count there : updated code :if(function_exists(‘bp_course_get_total_course_count_for_user’) && is_user_logged_in() && bp_course_get_total_course_count_for_user(get_current_user_id()) && bp_course_get_total_course_count_for_user(get_current_user_id()) > 0 ){
May 1, 2021 at 3:09 pm #355560fdittmarParticipantThat seems to work. Excellent support - you're a star. I'll apply this to the other 'restrictive page templates' too (they have a different, shorter line 41 but seem to work with your new one too. The old one (where just removing 'count' does not work) is: if(function_exists('bp_course_get_total_course_count_for_user') && count(bp_course_get_total_course_count_for_user(get_current_user_id())) > 0 ){ I assume replacing it with your new one does not have undesirable side effects. Many thanks.May 3, 2021 at 2:50 pm #355763Anshuman SahuKeymasterNo the new one is infact the correct code .Old one was wrong the function bp_course_get_total_course_count_for_user does not return array it returns integer and this is why the error was appearing . -
AuthorPosts
Viewing 6 posts - 1 through 6 (of 6 total)
- The topic ‘php error suddenly appearing on top of page’ is closed to new replies.