Action uncanny-learndash-groups

uo_before_manual_group_created

Fires before a manual group is created, allowing modifications to group arguments.

add_action( 'uo_before_manual_group_created', $callback, 10, 2 );

Description

Fired before a manual group is created by the admin. Developers can use this hook to modify the arguments passed to `wp_insert_post` or perform other actions before the group is saved. `$args` contains general creation arguments, and `$ld_group_args` holds the specific arguments for the LearnDash group.


Usage

add_action( 'uo_before_manual_group_created', 'your_function_name', 10, 2 );

Parameters

$args (mixed)
This parameter contains an array of arguments used for creating the post object in WordPress.
$ld_group_args (mixed)
This parameter contains an array of arguments that were used to create the manual group.

Examples

<?php
/**
 * Example of how to hook into the 'uo_before_manual_group_created' action.
 * This example demonstrates modifying the group's post title and adding
 * custom metadata before the group is finalized and saved to the database.
 */
add_action( 'uo_before_manual_group_created', function( $args, $ld_group_args ) {

	// Check if the $ld_group_args is an array and has a 'post_title' key.
	if ( is_array( $ld_group_args ) && isset( $ld_group_args['post_title'] ) ) {

		// Modify the group's post title to include a prefix indicating it's manually created.
		$ld_group_args['post_title'] = 'MANUAL_GROUP: ' . $ld_group_args['post_title'];

		// Add custom metadata to the group, for instance, a status indicating it's pending review.
		// Note: This metadata will be available *before* wp_insert_post is called.
		// If you need to update metadata *after* the post is created, use 'uo_after_manual_group_created'.
		if ( is_array( $args ) && isset( $args['user_id'] ) ) {
			$ld_group_args['meta_input']['_custom_group_creator_user_id'] = $args['user_id'];
		}
		$ld_group_args['meta_input']['_manual_group_creation_status'] = 'pending_review';

		// In a real scenario, you might want to adjust $ld_group_args directly
		// or perform more complex logic based on $args.
		// For demonstration, we'll echo a message.
		error_log( 'UO: Modifying manual group arguments before creation.' );
	}

	// The hook is an action, so no return value is expected or needed.

}, 10, 2 ); // Priority 10, accepts 2 arguments.

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/helpers/process-manual-group.php:112

'post_title'   => $group_title,
					'post_content' => '',
					'post_parent'  => $group_parent,
					'post_author'  => apply_filters( 'ulgm_custom_group_post_author', $customer_id, $group_leader_id, 'admin-created' ),
				)
			);

			do_action( 'uo_before_manual_group_created', $args, $ld_group_args );

			$group_id = wp_insert_post( $ld_group_args );

			$price_type = apply_filters( 'uo_create_new_group_price_type', 'closed', $group_id );
			update_post_meta( $group_id, '_ulgm_is_custom_group_created', 'yes' );
			update_post_meta( $group_id, '_thumbnail_id', $group_image );
			update_post_meta( $group_id, '_ld_price_type', $price_type );


Scroll to Top