Filter uncanny-learndash-groups

do_ld_group_postdata_filter

Filters the post data for LearnDash groups, allowing modification before display.

add_filter( 'do_ld_group_postdata_filter', $callback, 10, 1 );

Description

Fires after the LearnDash group post data is processed. Developers can use this filter to modify or extend the group post data before it's returned. The hook receives the group ID and the processed post data. This is useful for custom integrations or adding additional meta information to group data.


Usage

add_filter( 'do_ld_group_postdata_filter', 'your_function_name', 10, 1 );

Parameters

$group_id (mixed)
This parameter is a placeholder and is not used by the hook.

Return Value

The filtered value.


Examples

add_filter(
	'do_ld_group_postdata_filter',
	'my_custom_ld_group_postdata_filter',
	10,
	2
);

/**
 * Example filter to modify group post data before it's saved.
 *
 * This function demonstrates how to hook into the 'do_ld_group_postdata_filter'
 * action to modify or add data to a LearnDash group's post meta before it's saved.
 *
 * @param mixed $postdata The original post data array.
 * @param int   $group_id The ID of the group being processed.
 * @return array The modified post data array.
 */
function my_custom_ld_group_postdata_filter( $postdata, $group_id ) {
	// Example: Add a custom meta key if it doesn't exist or update its value.
	if ( ! isset( $postdata['meta']['_my_custom_group_setting'] ) ) {
		$postdata['meta']['_my_custom_group_setting'] = 'default_value';
	} else {
		// Example: Sanitize and update an existing custom setting.
		$postdata['meta']['_my_custom_group_setting'] = sanitize_text_field( $postdata['meta']['_my_custom_group_setting'] );
	}

	// Example: Add another custom field based on a condition.
	if ( get_post_meta( $group_id, '_should_have_featured_image', true ) === 'yes' ) {
		$postdata['meta']['_group_featured_image_source'] = 'custom';
	}

	// Always return the modified $postdata array for the filter to work.
	return $postdata;
}

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:403
src/classes/group-management/class-group-management-helpers.php:853
src/classes/helpers/rest-api-end-points.php:519

function wp_new_user_notification() {
			}


Scroll to Top