ulc_view_codes_date_format
Filters the date format used for displaying codes within the plugin, allowing customization.
add_filter( 'ulc_view_codes_date_format', $callback, 10, 1 );
Description
Filters the date format used for displaying coupon codes in the admin view. Developers can modify this filter to customize how dates are presented, for example, to use a different locale or a custom format. The default value is the WordPress site's configured date format.
Usage
add_filter( 'ulc_view_codes_date_format', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Example of using the 'ulc_view_codes_date_format' filter to customize the date display.
* This function will prepend "Today is: " to the default date format.
*
* @param string $date_format The current date format option.
* @return string The modified date format string.
*/
function my_custom_codes_date_format( $date_format ) {
// Add a prefix to the date format if it's not empty.
if ( ! empty( $date_format ) ) {
return 'Today is: ' . $date_format;
}
return $date_format; // Return the original if empty
}
// Add the filter to the 'ulc_view_codes_date_format' hook.
// The '10' is the priority (default is 10), and '1' indicates that the callback function accepts one argument.
add_filter( 'ulc_view_codes_date_format', 'my_custom_codes_date_format', 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-codes.php:111
* @return string
*/
public function single_row( $coupon ) {
$codes_batch_id = absint( $coupon->code_group );
$r = '<tr>';
list( $columns ) = $this->get_column_info();
$date_format = apply_filters( 'ulc_view_codes_date_format', get_option( 'date_format' ) );
$time_format = apply_filters( 'ulc_view_codes_time_format', get_option( 'time_format' ) );
// Optimize: Call get_users_of_code once and reuse the result
$code_users = Database::get_users_of_code( $coupon->ID, false );
foreach ( $columns as $column_name => $column_display_name ) {
$r .= '<td class="column-' . $column_name . '" data-label="' . esc_attr( $column_display_name ) . '">';