ulgm_key_suffix
Filters the suffix appended to unique keys within the plugin for customization.
add_filter( 'ulgm_key_suffix', $callback, 10, 1 );
Description
Filters the suffix appended to generated random codes. Use this hook to add a custom suffix for uniqueness or identification purposes, for example, to include a timestamp or a site identifier. The default is an empty string.
Usage
add_filter( 'ulgm_key_suffix', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Example of how to filter the ulgm_key_suffix hook.
* This example appends a fixed string to the generated random codes.
*
* @param string $suffix The original suffix passed to the filter.
* @return string The modified suffix.
*/
add_filter( 'ulgm_key_suffix', function( $suffix ) {
// Append a specific suffix to the generated codes.
// For example, this could be used to add a version number or a site identifier.
return $suffix . '_mysite';
}, 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/handlers/class-group-management-db-handler.php:95
public function generate_random_codes( $qty ) {
$codes = array();
$i = 0;
$prefix = apply_filters( 'ulgm_key_prefix', '' );
$suffix = apply_filters( 'ulgm_key_suffix', '' );
while ( $i < $qty ) {
$random_code = $this->random_string();
if ( ! isset( $codes[ $random_code ] ) ) {
$codes[] = sprintf( '%s%s%s', $prefix, $random_code, $suffix );
}
++$i;
}
return $codes;
}