ulgm_groups_key_redemption_form_before_enrollment_key
Fires just before a user enrolls with a group key, allowing modifications to the enrollment process.
add_action( 'ulgm_groups_key_redemption_form_before_enrollment_key', $callback, 10, 1 );
Description
Fires before the enrollment key input field on the groups key redemption form. Developers can use this hook to add custom content or modify the form's layout before the enrollment key input, providing opportunities for advanced integrations or user experience enhancements.
Usage
add_action( 'ulgm_groups_key_redemption_form_before_enrollment_key', 'your_function_name', 10, 1 );
Examples
add_action( 'ulgm_groups_key_redemption_form_before_enrollment_key', 'my_custom_enrollment_key_field', 10, 0 );
/**
* Adds a custom field before the enrollment key input in the Uncanny Groups key redemption form.
* This example adds a placeholder for a group name input, which might be used in a more complex scenario.
*/
function my_custom_enrollment_key_field() {
// This example assumes you might want to pre-fill or dynamically set a group name.
// In a real-world scenario, you might fetch data from user meta, a query parameter, etc.
$predefined_group_name = isset( $_GET['group_name'] ) ? sanitize_text_field( $_GET['group_name'] ) : '';
?>
<tr>
<td class="label"><label for="ulgm_group_name"><?php esc_html_e( 'Group Name (Optional)', 'my-text-domain' ); ?></label></td>
<td class="input">
<input type="text"
name="ulgm_group_name"
id="ulgm_group_name"
value="<?php echo esc_attr( $predefined_group_name ); ?>"
placeholder="<?php esc_attr_e( 'Enter the group name if known', 'my-text-domain' ); ?>"
class="regular-text">
<p class="description"><?php esc_html_e( 'If you know the name of the group you are joining, enter it here.', 'my-text-domain' ); ?></p>
</td>
</tr>
<?php
}
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/includes/forms/user-code-redemption.php:22
return ob_get_clean();
}
?>
<form id="ulgm_registration_form" class="uncanny-learndash-groups" action="" method="POST">
<fieldset>
<?php do_action( 'ulgm_groups_key_redemption_form_start' ); ?>
<table class="table table-form form-table clr">
<?php do_action( 'ulgm_groups_key_redemption_form_before_enrollment_key' ); ?>
<tr>
<td class="label"><label
for="code_registration"><?php esc_html_e( 'Enrollment key', 'uncanny-learndash-groups' ); ?></label>
</td>
<td class="input">
<input name="ulgm_code_redeem"
id="ulgm_code_redeem"