php error suddenly appearing on top of page

Home Forums Legacy Support Support queries Other issues php error suddenly appearing on top of page

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #354774
    fdittmar
    Participant
    Hi 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 style
    #354987
    Anshuman Sahu
    Keymaster
    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 ){
    
    
    change the above to :
    
    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 ){
    
    
    #355422
    fdittmar
    Participant
    Hi, 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.
    #355555
    Anshuman Sahu
    Keymaster
    corrected 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 ){
    
    #355560
    fdittmar
    Participant
    That 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.
    #355763
    Anshuman Sahu
    Keymaster
    No 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 .
Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘php error suddenly appearing on top of page’ is closed to new replies.