Support » Plugin: Permalink Manager Lite » Incompatibility with Sensei LMS’s Learning Mode

  • Resolved Carlos

    (@lbakyl)


    Hi,

    Sensei LMS released version 4.x which provides a new learning mode (focus mode). However, this seems to be loaded dynamically and results in 404 whenever Permalink Manager is active and applied to that page.

    If you would have time to look into it or have some advise, I will be grateful. Thank you.

    Regards,
    Carlos.

Viewing 1 replies (of 1 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi Carlos,

    I have just created a workaround to allow Permalink Manager to detect the endpoint used for URLs that have been switched to “Learning Mode”:

    /**
     * Detect "Learning mode" endpoint
     */
    function pm_detect_sensei_learning_mode($uri_parts, $request_url, $endpoints) {
    	if(!empty($uri_parts['uri']) && class_exists('Sensei_Course_Theme')) {
    		$sensei_class = Sensei_Course_Theme::instance();
    		$sensei_query_var = $sensei_class::QUERY_VAR;
    
    		// Check if the URI begins with Sensei query variable
    		if(strpos($uri_parts['uri'], $sensei_query_var) === 0) {
    			$uri_parts['uri'] = preg_replace("/(^{$sensei_query_var}\/)(.*)/", '$2', $uri_parts['uri']);
    			$uri_parts['sensei_learning_mode'] = $sensei_query_var;
    		}
    	}
    
    	return $uri_parts;
    }
    add_filter('permalink_manager_detect_uri', 'pm_detect_sensei_learning_mode', 10, 3);
    
    /**
     * Turn on "Learning mode" if custom permalink was detected
     */
    function pm_enable_sensei_learning_mode($query, $old_query, $uri_parts, $pm_query) {
    	if(!empty($uri_parts['sensei_learning_mode']) && !empty($pm_query['id'])) {
    		$sensei_query_var = $uri_parts['sensei_learning_mode'];
    
    		// Activate "Learning mode"
    		$_GET[$sensei_query_var] = 1;
    		$query[$sensei_query_var] = 1;
    
    		// Disable the redirect
    		add_filter('sensei_course_learning_mode_theme_override_enabled', '__return_false');
    	}
    
    	return $query;
    }
    add_filter('permalink_manager_filter_query', 'pm_enable_sensei_learning_mode', 1, 4);

    Could you try to paste the above code to functions.php file in your theme directory?

    Best regards,
    Maciej

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