ld_group_postdata_updated
Fires after group post data, including leaders, users, and courses, has been updated.
add_action( 'ld_group_postdata_updated', $callback, 10, 4 );
Description
Fires after a group's post data is updated. Developers can use this hook to perform actions like sending notifications, updating related data, or triggering custom logic based on changes to group leaders, users, or courses. This hook is triggered by core LearnDash functionality.
Usage
add_action( 'ld_group_postdata_updated', 'your_function_name', 10, 4 );
Parameters
-
$group_id(mixed) - The ID of the group whose post data has been updated.
-
$group_leaders(mixed) - The ID of the group whose post data has been updated.
-
$group_users(mixed) - This parameter contains an array of user IDs who are assigned as leaders for the group.
-
$group_courses(mixed) - This parameter contains a list of user IDs who are members of the group.
Examples
add_action( 'ld_group_postdata_updated', 'my_custom_group_update_logic', 10, 4 );
/**
* Example function to handle updates to LearnDash group post data.
* This function demonstrates how to access and utilize the parameters
* passed to the 'ld_group_postdata_updated' action hook.
*
* @param int $group_id The ID of the updated LearnDash group.
* @param array $group_leaders An array of user IDs who are leaders of the group.
* @param array $group_users An array of user IDs who are members of the group.
* @param array $group_courses An array of course IDs associated with the group.
*/
function my_custom_group_update_logic( $group_id, $group_leaders, $group_users, $group_courses ) {
// Check if the group ID is valid.
if ( ! is_numeric( $group_id ) || $group_id <= 0 ) {
error_log( 'Invalid group ID received in ld_group_postdata_updated.' );
return;
}
// Example: Log the group update event.
$log_message = sprintf(
'LearnDash Group Updated: Group ID %d. Leaders: %s, Users: %s, Courses: %s',
$group_id,
implode( ',', $group_leaders ),
implode( ',', $group_users ),
implode( ',', $group_courses )
);
error_log( $log_message );
// Example: Trigger a notification to group leaders when a group is updated.
if ( ! empty( $group_leaders ) ) {
foreach ( $group_leaders as $leader_id ) {
$user = get_user_by( 'id', $leader_id );
if ( $user ) {
// This is a hypothetical notification function, replace with actual implementation if available.
// For example, you might use wp_mail() or a custom notification plugin.
$notification_subject = "LearnDash Group Updated: " . get_the_title( $group_id );
$notification_message = sprintf(
"The group '%s' you lead has been updated. Please review the changes.",
get_the_title( $group_id )
);
// Hypothetical function call:
// send_custom_user_notification( $user->user_email, $notification_subject, $notification_message );
}
}
}
// Example: Update a custom meta field for the group if specific courses are assigned.
if ( in_array( 123, $group_courses ) ) { // Replace 123 with an actual course ID
update_post_meta( $group_id, '_has_special_course_assigned', true );
} else {
delete_post_meta( $group_id, '_has_special_course_assigned' );
}
// If this were a filter hook, you would need to return the modified data.
// Since it's an action hook, no return value is expected.
}
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/group-management/class-group-management-helpers.php:408
src/classes/group-management/class-group-management-helpers.php:858
src/classes/helpers/rest-api-end-points.php:524
function wp_new_user_notification() {
}