Action uncanny-learndash-groups

ulgm_after_add_group_leader_form_fields

Fires after group leader form fields are added, passing the current managed group ID.

add_action( 'ulgm_after_add_group_leader_form_fields', $callback, 10, 1 );

Description

Fires after the group leader form fields are displayed in the frontend group management interface. Developers can use this hook to add custom fields or modify existing ones within the "Add Leader" form for a specific managed group. The current group ID is passed for context.


Usage

add_action( 'ulgm_after_add_group_leader_form_fields', 'your_function_name', 10, 1 );

Parameters

$ulgm_current_managed_group_id (mixed)
This parameter contains the ID of the group for which a group leader is being added.

Examples

<?php
/**
 * Example callback for the ulgm_after_add_group_leader_form_fields action hook.
 * This example adds an additional field to the group leader form to collect a
 * unique identifier for the leader, and then validates it before the form is submitted.
 *
 * @param int $ulgm_current_managed_group_id The ID of the group being managed.
 */
function my_custom_group_leader_fields( $ulgm_current_managed_group_id ) {
	// Add a custom field for a unique leader identifier.
	?>
	<div class="uo-row">
		<label for="custom-leader-id"><?php esc_html_e( 'Unique Leader ID:', 'my-text-domain' ); ?></label>
		<input type="text" id="custom-leader-id" name="custom_leader_id" required>
	</div>
	<?php
}
add_action( 'ulgm_after_add_group_leader_form_fields', 'my_custom_group_leader_fields', 10, 1 );

/**
 * Example callback to validate the custom group leader field before submission.
 * This assumes there's a subsequent AJAX handler or form processing that
 * would utilize this validation. For a direct form submission, this logic
 * would typically be within the form processing function.
 *
 * @param int $ulgm_current_managed_group_id The ID of the group being managed.
 */
function validate_custom_group_leader_id( $ulgm_current_managed_group_id ) {
	// This is a conceptual example. In a real scenario, you'd check $_POST
	// data after the form is submitted. This hook fires *after* the form
	// fields are rendered, so direct validation here on POST isn't typical.
	// However, you could use this to potentially *add* client-side validation
	// attributes or JavaScript hooks.

	// For demonstration, let's assume we're adding a data attribute to the
	// form to indicate the need for validation.
	?>
	<script type="text/javascript">
		jQuery(document).ready(function($) {
			// Find the form associated with this action and add a data attribute.
			// This is a simplified example, you'd need to ensure you're targeting
			// the correct form element.
			var form = $('#add-group-leader-form'); // Assuming your form has this ID.
			if (form.length) {
				form.data('validate-custom-id', true);
			}
		});
	</script>
	<?php
}
// You might hook this to a different action that runs *during* form submission processing.
// For this specific hook's context (rendering fields), a direct POST validation
// isn't appropriate within the hook itself. The example above shows how you
// *could* influence client-side behavior.
// add_action( 'ulgm_after_add_group_leader_form_fields', 'validate_custom_group_leader_id', 20, 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/templates/frontend-uo_groups/groups-table-actions.php:73

</i>
								</div>

								<input type="hidden" name="group-id" id="group-id"
									   value="<?php echo self::$ulgm_current_managed_group_id; ?>">
								<input type="hidden" name="action" id="add-leader" value="add-leader">

								<?php do_action( 'ulgm_after_add_group_leader_form_fields', self::$ulgm_current_managed_group_id ); ?>

								<div class="uo-row-footer">
									<div style="margin-bottom: 15px" class="uo-modal-spinner"></div>

									<button class="uo-btn submit-group-management-form"
											data-end-point="add_group_leader"><?php echo __( 'Add group leader', 'uncanny-learndash-groups' ); ?>
									</button>


Scroll to Top