Skip to content

Commit

Permalink
fix paginated dashboard endpoint 404s
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasplevy committed Feb 6, 2019
1 parent ae264e2 commit c9006a6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
LifterLMS Changelog
===================

v3.28.2 - 2019-02-01
--------------------

##### Bug fixes

+ Fixed an issue causing 404s on paginated dashboard endpoints when the permalink structure is set to anything other than `%postname%`.

##### Deprecations

+ `LLMS_Query->set_dashboard_pagination()`


v3.28.1 - 2019-02-01
--------------------

Expand Down
41 changes: 30 additions & 11 deletions includes/class.llms.query.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
<?php
defined( 'ABSPATH' ) || exit;

/**
* Query base class
* Handles queries and endpoints.
*
* @since 1.0.0
* @version 3.24.0
* @version [version]
*/

defined( 'ABSPATH' ) || exit;

/**
* LLMS_Query class
*/
class LLMS_Query {

/**
* Query var
* @access public
* @var array
*/
public $query_vars = array();

/**
* Constructor
*
* @since 1.0.0
* @version 3.6.0
* @version [version]
*/
public function __construct() {

Expand All @@ -30,7 +34,6 @@ public function __construct() {

add_filter( 'query_vars', array( $this, 'set_query_vars' ), 0 );
add_action( 'parse_request', array( $this, 'parse_request' ), 0 );
add_action( 'wp', array( $this, 'set_dashboard_pagination' ), 10 );

}

Expand All @@ -42,10 +45,22 @@ public function __construct() {

/**
* Add Query Endpoints
*
* @since 1.0.0
* @version [version]
*/
public function add_endpoints() {
foreach ( $this->get_query_vars() as $key => $var ) {
add_rewrite_endpoint( $var, EP_PAGES ); }
add_rewrite_endpoint( $var, EP_PAGES );
}
global $wp_rewrite;
foreach ( LLMS_Student_Dashboard::get_tabs() as $id => $tab ) {
if ( ! empty( $tab['paginate'] ) ) {
$regex = sprintf( '(.?.+?)/%1$s/%2$s/?([0-9]{1,})/?$', $tab['endpoint'], $wp_rewrite->pagination_base );
$redirect = sprintf( 'index.php?pagename=$matches[1]&%s=$matches[3]&paged=$matches[2]', $tab['endpoint'] );
add_rewrite_rule( $regex, $redirect, 'top' );
}
}
}

/**
Expand All @@ -54,7 +69,8 @@ public function add_endpoints() {
*/
public function add_query_vars( $vars ) {
foreach ( $this->get_query_vars() as $key => $var ) {
$vars[] = $key; }
$vars[] = $key;
}

return $vars;
}
Expand Down Expand Up @@ -214,12 +230,15 @@ public function pre_get_posts( $query ) {
/**
* Handles setting the "paged" variable on Student Dashboard endpoints
* which utilize page/{n} style pagination
* @return void
* @since 3.14.0
* @version 3.14.0
*
* @return void
* @since 3.14.0
* @version 3.14.0
* @deprecated [version] $paged automatically set via add_rewrite_rule() in $this->add_endpoints() method.
*/
public function set_dashboard_pagination() {

llms_deprecated_function( 'LLMS_Query::set_dashboard_pagination()', '3.28.2' );
$tab = LLMS_Student_Dashboard::get_current_tab( 'slug' );
$var = get_query_var( $tab );
if ( $var ) {
Expand Down
16 changes: 14 additions & 2 deletions includes/class.llms.student.dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Retrieve data sets used by various other classes and functions
*
* @since 3.0.0
* @version 3.27.0
* @version [version]
*/

defined( 'ABSPATH' ) || exit;
Expand All @@ -22,6 +22,7 @@ public function __construct() {

add_filter( 'llms_get_endpoints', array( $this, 'add_endpoints' ) );
add_filter( 'lifterlms_student_dashboard_title', array( $this, 'modify_dashboard_title' ), 5 );
add_filter( 'rewrite_rules_array', array( $this, 'modify_rewrite_rules_order' ) );

}

Expand Down Expand Up @@ -124,7 +125,7 @@ public static function get_current_tab( $return = 'data' ) {
* Retrieve all dashboard tabs and related data
* @return array
* @since 3.0.0
* @version 3.27.0
* @version [version]
*/
public static function get_tabs() {

Expand All @@ -139,12 +140,14 @@ public static function get_tabs() {
'view-courses' => array(
'content' => 'lifterlms_template_student_dashboard_my_courses',
'endpoint' => get_option( 'lifterlms_myaccount_courses_endpoint', 'view-courses' ),
'paginate' => true,
'nav_item' => true,
'title' => __( 'My Courses', 'lifterlms' ),
),
'my-grades' => array(
'content' => 'lifterlms_template_student_dashboard_my_grades',
'endpoint' => get_option( 'lifterlms_myaccount_grades_endpoint', 'my-grades' ),
'paginate' => true,
'nav_item' => true,
'title' => __( 'My Grades', 'lifterlms' ),
),
Expand All @@ -169,6 +172,7 @@ public static function get_tabs() {
'notifications' => array(
'content' => 'lifterlms_template_student_dashboard_my_notifications',
'endpoint' => get_option( 'lifterlms_myaccount_notifications_endpoint', 'notifications' ),
'paginate' => true,
'nav_item' => true,
'title' => __( 'Notifications', 'lifterlms' ),
),
Expand Down Expand Up @@ -287,6 +291,14 @@ public function modify_dashboard_title( $title ) {

}

public function modify_rewrite_rules_order( $rules ) {

// var_dump( $rules );

return $rules;

}

/**
* Callback to output the edit account content
* @return void
Expand Down

0 comments on commit c9006a6

Please sign in to comment.