Filter uncanny-learndash-groups

ulgm_insert_group

Filters the group title before it is inserted into the database, allowing for modification.

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

Description

Fires when a new group is being inserted into the database. Allows developers to modify the group's title, post type, status, and other arguments before it's saved. This hook is crucial for customizing group creation processes, such as adding custom meta or altering default settings.


Usage

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

Parameters

$group_title (mixed)
This parameter represents the title of the group being inserted.

Return Value

The filtered value.


Examples

/**
 * Modify the group title when a new group is created.
 *
 * This example appends the current date to the group title to make it more specific,
 * for instance, useful for tracking groups created within a specific time frame.
 *
 * @param array $group_args The array of arguments for creating the group.
 * @return array The modified group arguments with an updated group title.
 */
add_filter( 'ulgm_insert_group', function( $group_args ) {
    // Ensure we are working with an array and it contains a 'post_title'.
    if ( is_array( $group_args ) && isset( $group_args['post_title'] ) ) {
        // Append the current date in YYYY-MM-DD format to the group title.
        $group_args['post_title'] = $group_args['post_title'] . ' - ' . date( 'Y-m-d' );
    }
    return $group_args;
}, 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/classes/woocommerce/woocommerce-license-subscription.php:583
src/classes/woocommerce/woocommerce-license.php:994
src/classes/helpers/process-manual-group.php:100

)
			);
		}
		if ( ! user_can( $user, 'group_leader' ) && ! user_can( $user, 'administrator' ) ) {
			$user->add_role( 'group_leader' );
		}

		$ld_group_args = apply_filters(
			'ulgm_insert_group',
			array(
				'post_type'    => 'groups',
				'post_status'  => 'publish',
				'post_title'   => $group_title,
				'post_content' => '',
				'post_author'  => apply_filters( 'ulgm_custom_group_post_author', $user->ID, get_current_user_id(), 'license-purchase' ),


Scroll to Top