Filter uncanny-learndash-groups

ulgm-frontend-datatables-page-length

Filters the default page length for the frontend DataTables plugin to allow customization of entries displayed per page.

add_filter( 'ulgm-frontend-datatables-page-length', $callback, 10, 1 );

Description

This filter allows developers to modify the default number of entries displayed per page in the frontend DataTables. You can customize the pagination length before it's applied to the table. The hook fires when the DataTables configuration is being generated.


Usage

add_filter( 'ulgm-frontend-datatables-page-length', 'your_function_name', 10, 1 );

Parameters

$page_length (mixed)
This parameter represents the default number of entries to display per page in the DataTables instance on the frontend.

Return Value

The filtered value.


Examples

/**
 * Change the default page length for the frontend DataTables.
 *
 * This filter allows administrators to set a different default number of items
 * displayed per page in the frontend tables generated by the ULGM plugin.
 * For instance, if you want to show 100 items per page by default instead of 50.
 */
add_filter( 'ulgm-frontend-datatables-page-length', 'my_custom_ulgm_page_length', 10, 1 );

function my_custom_ulgm_page_length( $page_length ) {
    // Check if the current user is an administrator.
    // We only want to apply this override for administrators.
    if ( current_user_can( 'manage_options' ) ) {
        // Set the desired default page length to 100.
        $custom_length = 100;
        return $custom_length;
    }

    // If the user is not an administrator, return the original page length.
    return $page_length;
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/class-utilities.php:1236

public static function attr_datatables_page_length( $page_length = 50 ) {
		// Check if it's a valid value
		// If it's not, fix it
		if ( empty( $page_length ) || ! is_numeric( $page_length ) ) {
			$page_length = 50;
		}

		// Return it
		return apply_filters(
			'ulgm-frontend-datatables-page-length',
			$page_length
		);
	}


Scroll to Top