ulgm_groups_key_redemption_form_before_buttons
Fires before the submit and cancel buttons are displayed on the group key redemption form.
add_action( 'ulgm_groups_key_redemption_form_before_buttons', $callback, 10, 1 );
Description
Fires before the submit and cancel buttons on the user key redemption form. This hook allows developers to insert custom content, fields, or modify the form's layout immediately preceding the form submission controls.
Usage
add_action( 'ulgm_groups_key_redemption_form_before_buttons', 'your_function_name', 10, 1 );
Examples
<?php
/**
* Example function to add custom content before the redemption form buttons.
*
* This function demonstrates how to hook into 'ulgm_groups_key_redemption_form_before_buttons'
* to inject additional elements or information before the submit button.
*
* @param int $user_id The ID of the currently logged-in user.
*/
function my_custom_redemption_form_enhancement( $user_id ) {
// Check if the user is logged in. If not, we might not want to show this.
if ( ! is_user_logged_in() ) {
return;
}
// For demonstration, let's add a simple message.
// In a real scenario, you might dynamically generate content based on user roles,
// group memberships, or other WordPress data.
?>
<p class="ulgm-custom-message">
<?php esc_html_e( 'Please ensure you have the correct enrollment key. Once redeemed, it cannot be changed.', 'your-text-domain' ); ?>
</p>
<?php
// You could also conditionally display fields or links here.
// For example, if the user is an administrator, you might show a link to manage codes.
if ( current_user_can( 'manage_options' ) ) {
$manage_codes_url = admin_url( 'admin.php?page=ulgm_codes' ); // Assuming this is a valid admin URL
?>
<p>
<a href="<?php echo esc_url( $manage_codes_url ); ?>" class="button button-secondary">
<?php esc_html_e( 'Manage Enrollment Keys', 'your-text-domain' ); ?>
</a>
</p>
<?php
}
}
// Add the action to the hook.
// The hook 'ulgm_groups_key_redemption_form_before_buttons' passes the user_id as an argument.
// We use a priority of 10 and specify that the function accepts 1 argument.
add_action( 'ulgm_groups_key_redemption_form_before_buttons', 'my_custom_redemption_form_enhancement', 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/includes/forms/user-code-redemption.php:39
value="<?php if ( ulgm_filter_has_var( 'ulgm_code_redeem', INPUT_POST ) ) {
echo ulgm_filter_input( 'ulgm_code_redeem', INPUT_POST );
} ?>"
placeholder="<?php esc_html_e( 'Enrollment key', 'uncanny-learndash-groups' ); ?>"
type="text"/></td>
</tr>
<?php do_action( 'ulgm_groups_key_redemption_form_after_enrollment_key' ); ?>
<?php do_action( 'ulgm_groups_key_redemption_form_before_buttons' ); ?>
<tr>
<td class="label"></td>
<td class="input">
<input type="submit" class="btn btn-default"
value="<?php esc_html_e( 'Redeem code', 'uncanny-learndash-groups' ); ?>"/>
<input type="hidden" name="_ulgm_code_nonce"
value="<?php echo wp_create_nonce( Utilities::get_prefix() ); ?>"/>