• Resolved KZNCraig

    (@kzncraig)


    Hi, a customer alerted me to a “There has been a critical error on this website” WP error.

    I checked the PHP error logs and see this error that was logged after the above error.

    [14-Oct-2024 06:47:45 UTC] PHP Fatal error: Uncaught ValueError: array_rand(): Argument #1 ($array) cannot be empty in /home/africanreptilesv/public_html/wp-content/plugins/sensei-lms/includes/class-sensei-lesson.php:3834

    Kindly advise.

    Many thanks.

    • This topic was modified 5 months, 1 week ago by KZNCraig.

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support Deric (a11n)

    (@dericleeyy)

    Are you able to reproduce this issue consistently?

    Could you try these steps to temporarily disable all plugins and revert to a default theme?

    1. Install Health Check plugin on your site
    2. Download and install Twenty Twenty-Three on your site if not installed already
    3. Go to Installed Plugins. Click Troubleshoot on Sensei
    4. Try viewing the Course to reproduce the error
    5. Once you are done, go back to wp-admin and disable troubleshooting mode through the top bar.
    Thread Starter KZNCraig

    (@kzncraig)

    Thank you for your response so far.

    This is a live environment so I cannot easily disable plugins and change theme. The troubleshoot option is not available.

    All plugins are up to date and WordPress core is up to date.

    I can reproduce the error my side. So it happens for me (the developer), and for the client.

    The error is pretty clear as it says: “Array cannot be empty” which is triggered in a file called class-sensei-lesson.php on line 38

    PHP Fatal error: Uncaught ValueError: array_rand(): Argument #1 ($array) cannot be empty in */plugins/sensei-lms/includes/class-sensei-lesson.php:38

    When I open this file line 38 shows php comments within a class called “class Sensei_Lesson {” – not code. So it is very confusing.

    Is there a chance I can get direct email ticket support?

    Plugin Support Cara

    (@dcka)

    @kzncraig Email support is available with a paid license, so please feel free to reach out if you have one. Otherwise, we’re happy to continue helping here.

    This is a live environment so I cannot easily disable plugins and change theme. The troubleshoot option is not available.

    The Health Check?plugin recommended earlier enables you to deactivate plugins and the theme without affecting how it appears to users. Once that is installed and active on the site, you should be able to click Troubleshoot on Sensei.

    Alternatively, you can create a staging version of your client’s site where you should be able to troubleshoot more thoroughly. Many hosts provide a?staging?service, where you can do testing without affecting the live?site. You can ask your host about this.?

    If they don’t give you a?staging?site, you could try WP?Staging?or Duplicator:

    Plugin Author Donna Peplinskie (a11n)

    (@donnapep)

    Hi @kzncraig,

    I can reproduce the error my side.

    Are you able to share steps to reproduce? Are you viewing a lesson or quiz when the error occurs?

    By looking at the code, I’m guessing that you may have the Classic Editor plugin activated. Can you confirm? If so, can you please share screenshots of the Quiz Settings and Quiz Questions meta boxes for the problematic lesson / quiz?

    When I open this file line 38 shows php?comments?within a class called “class Sensei_Lesson {” – not code. So it is very confusing.

    In your original message the fatal error indicated the issue was on line 3834, which does call array_rand.

    Plugin Support Jay

    (@bluejay77)

    Hi there,

    It has been a while since we have heard from you, so I’m marking this topic as resolved.

    But if you have any further questions or need some more help, you’re welcome to reply here or open another thread.

    On our site when we remove a user from a course, here is the relevant stack trace:

    class-sensei-lesson.php(3832): array_rand(Array, 0)
    class-sensei-utils.php(733): Sensei_Lesson->lesson_quiz_questions(‘10055172’)
    class-sensei-utils.php(811): Sensei_Utils::sensei_get_quiz_questions(10055172)
    class-sensei-utils.php(660): Sensei_Utils::sensei_delete_quiz_answers(10055172, 3405)
    class-sensei-utils.php(706): Sensei_Utils::sensei_remove_user_from_lesson(10055171, 3405, true)
    class-sensei-utils.php(2818): Sensei_Utils::sensei_remove_user_from_course(85579, 3405)

    Seems like to remove the user from the course it wants to delete their quiz answers but to do that it gets the lesson_quiz_questions but in our case the $questions_array used in this code is empty:

    $selected_questions = array_rand(
    $questions_array,
    $show_questions > $questions_count ? $questions_count : $show_questions
    );

    And it errors out because it can’t randomize an empty array.

    Plugin Support Deric (a11n)

    (@dericleeyy)

    @joncampbell

    Could you try these steps to temporarily disable all plugins and revert to a default theme?

    1. Install Health Check plugin on your site
    2. Download and install Twenty Twenty-Five on your site if not installed already
    3. Go to Installed Plugins. Click Troubleshoot on Sensei
    4. Try removing a user from a course
    5. Once you are done, go back to wp-admin and disable troubleshooting mode through the top bar.
    joncampbell

    (@joncampbell)

    @dericleeyy
    I installed Twenty Twenty-Five and Health Check and did the troubleshooting.
    I then went to the Students area of the admin and Reset Progress on a user and it causes a fatal error still:

    [15-Jan-2025 20:03:18 UTC] PHP Fatal error: Uncaught ValueError: array_rand(): Argument #1 ($array) cannot be empty in /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-lesson.php:3832
    Stack trace: 0 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-lesson.php(3832): array_rand(Array, 0) 1 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-utils.php(733): Sensei_Lesson->lesson_quiz_questions(‘10055172’) 2 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-utils.php(811): Sensei_Utils::sensei_get_quiz_questions(10055172) 3 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-utils.php(660): Sensei_Utils::sensei_delete_quiz_answers(10055172, 3405) 4 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-utils.php(706): Sensei_Utils::sensei_remove_user_from_lesson(10055171, 3405, true) 5 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-utils.php(2818): Sensei_Utils::sensei_remove_user_from_course(85579, 3405) 6 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/rest-api/class-sensei-rest-api-course-progress-controller.php(81): Sensei_Utils::reset_course_for_user(85579, 3405) 7 /wp-includes/rest-api/class-wp-rest-server.php(1292): Sensei_REST_API_Course_Progress_Controller->batch_delete_items(Object(WP_REST_Request)) 8 /wp-includes/rest-api/class-wp-rest-server.php(1125): WP_REST_Server->respond_to_request(Object(WP_REST_Request), ‘/sensei-interna…’, Array, NULL) 9 /wp-includes/rest-api/class-wp-rest-server.php(439): WP_REST_Server->dispatch(Object(WP_REST_Request)) 10 /wp-includes/rest-api.php(449): WP_REST_Server->serve_request(‘/sensei-interna…’) 11 /wp-includes/class-wp-hook.php(324): rest_api_loaded(Object(WP)) 12 /wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(”, Array) 13 /wp-includes/plugin.php(565): WP_Hook->do_action(Array) 14 /wp-includes/class-wp.php(418): do_action_ref_array(‘parse_request’, Array) 15 /wp-includes/class-wp.php(813): WP->parse_request(”) 16 /wp-includes/functions.php(1336): WP->main(”) 17 /wp-blog-header.php(16): wp() 18 /index.php(17): require(‘/Users/jon…..’) 19 {main}

    thrown in /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-lesson.php on line 3832

    Plugin Support Cara

    (@dcka)

    @joncampbell So far, we haven’t been able to replicate the issue on a demo site generated from here. Can you let us know which version of Sensei LMS you’re using? Can you please make sure you’re using the latest version available?

    If the issue persists on the latest version, please also share the following from the site:

    • PHP version
    • WordPress version
    • Sensei LMS version

    In any case, we’ll open an issue for this so we can investigate further.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.