Filter Uncanny Redemption Codes

ulc_codes_group_sortable

Filters the columns used for sorting sortable code groups.

add_filter( 'ulc_codes_group_sortable', $callback, 10, 1 );

Description

Filters the sortable columns for the "Codes" group view in the admin area. Developers can use this hook to add, remove, or modify the columns that are sortable by date or code. This filter fires when generating the sortable column array.


Usage

add_filter( 'ulc_codes_group_sortable', 'your_function_name', 10, 1 );

Parameters

$columns (mixed)
This parameter contains an array defining which columns are sortable and their corresponding database field names and sortable status.

Return Value

The filtered value.


Examples

/**
 * Example of how to add or modify sortable columns for the 'ulc_codes_group_sortable' filter.
 *
 * This function will add a new sortable column named 'creation_date'
 * and mark the existing 'code_for' column as non-sortable by setting the second parameter to false.
 *
 * @param array $columns An associative array of column IDs and their sortable status.
 *                       The value is an array where the first element is the sortable key,
 *                       and the second element is a boolean indicating if it's sortable.
 * @return array The modified array of sortable columns.
 */
add_filter( 'ulc_codes_group_sortable', function( $columns ) {
	// Add a new sortable column for creation date.
	$columns['creation_date'] = array( 'creation_date', true );

	// Make the 'code_for' column non-sortable (or un-sortable).
	if ( isset( $columns['code_for'] ) ) {
		$columns['code_for'][1] = false;
	}

	// Optionally, remove a column entirely if needed.
	// unset( $columns['timeline'] );

	return $columns;
}, 10, 1 );

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/admin/class-view-groups.php:84

protected function get_sortable_columns() {
		$columns = array(
			'timeline'   => array( 'issue_date', true ),
			'code_for'   => array( 'code_for', true ),
		);

		return apply_filters( 'ulc_codes_group_sortable', $columns );
	}


Scroll to Top