Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function sensei_get_prev_next_lessons() not found in class-sensei-frontend.php #7602

Open
jsantosi opened this issue May 9, 2024 · 2 comments
Labels
[Status] Needs Triage Issue needs to be triaged [Type] Bug

Comments

@jsantosi
Copy link

jsantosi commented May 9, 2024

Steps to Reproduce

  1. Access the learning website
  2. Navigate to the current lesson page
  3. Try to move to the next lesson.
  4. See error

Expected Behavior
I expected that clicking to move to the next lesson would transition without errors.

Actual Behavior
When attempting to move to the next lesson, the following error occurs:

Fatal error: Uncaught Error: Call to undefined function sensei_get_prev_next_lessons() in /home/customer/www/staging17.gabster.com.br/public_html/learn/wp-content/plugins/sensei-lms/includes/class-sensei-frontend.php:736
Additional Context
Sensei LMS Version: 4.24.0
WordPress Version: 6.5.3

@jsantosi jsantosi added [Status] Needs Triage Issue needs to be triaged [Type] Bug labels May 9, 2024
@jsantosi
Copy link
Author

jsantosi commented May 9, 2024

I managed to locate the function in template_functions.php. However, for some reason, it's not being called in class-sensei-frontend.php.
Perhaps it's necessary to check if the function exists using "functions_exists".
This should avoid the undefined function call error. See:

`/**

  • Redirect to the next lesson, if applicable.

  • @SInCE 1.12.0

  • @param int $lesson_id Lesson ID.
    */
    private function maybe_redirect_to_next_lesson( $lesson_id = 0 ) {
    if ( 0 >= $lesson_id ) {
    return;
    }

    // Verifica se a função existe antes de chamá-la
    if ( ! function_exists( 'sensei_get_prev_next_lessons' ) ) {
    return;
    }

    $nav_links = sensei_get_prev_next_lessons( $lesson_id );
    $redirect_url = false;

    if ( isset( $nav_links['next'] ) ) {
    $redirect_url = $nav_links['next']['url'];
    }

    /**

    • Filter the URL that students are redirected to after completing a lesson.
    • @SInCE 1.12.0
    • @hook sensei_complete_lesson_redirect_url
    • @param {string|bool} $redirect_url URL to redirect students to after completing a lesson. False to skip redirect.
    • @param {int} $lesson_id Current lesson ID.
    • @param {array} $nav_links Navigation links found for the current lesson.
    • @return {string|bool} Filtered URL to redirect students to after completing a lesson. False to skip redirect.
      */
      $redirect_url = apply_filters( 'sensei_complete_lesson_redirect_url', $redirect_url, $lesson_id, $nav_links );

    if ( $redirect_url ) {
    wp_safe_redirect( esc_url_raw( $redirect_url ) );
    exit;
    }
    }
    `

@merkushin
Copy link
Member

Hi @jsantosi !

Tested it on a fresh website with WordPress 6.5.3, Sensei LMS 4.24.0 and Course Theme 1.3.7.
No error found.

Do you have other plugins or do you use a custom theme?
Could you try to deactivate other plugins one-by-one and check if the issue persists?
If the plugin dance didn't help, try to switch the theme to a standard WordPress theme or to the Course theme and check if the issue persists.

@merkushin merkushin added [Status] Needs Triage Issue needs to be triaged and removed [Status] Needs Triage Issue needs to be triaged labels May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] Needs Triage Issue needs to be triaged [Type] Bug
Projects
None yet
Development

No branches or pull requests

2 participants