ulgm_before_license_group_is_inserted
Fires before a license group is inserted into the database, allowing modification of arguments.
add_action( 'ulgm_before_license_group_is_inserted', $callback, 10, 2 );
Description
Fires before a new license group is inserted into the database. Developers can modify the `$ld_group_args` array to alter the group's properties before it's saved. The `$this` parameter provides access to the license object.
Usage
add_action( 'ulgm_before_license_group_is_inserted', 'your_function_name', 10, 2 );
Parameters
-
$ld_group_args(mixed) - This parameter contains an array of arguments that will be used to create a new license group post in WordPress.
-
$this(mixed) - This parameter contains an array of arguments that will be used to create a new license group post in WordPress.
Examples
add_action( 'ulgm_before_license_group_is_inserted', 'my_custom_license_group_logic', 10, 2 );
/**
* Example function to modify license group arguments before insertion.
*
* This function demonstrates how to hook into `ulgm_before_license_group_is_inserted`
* to alter the arguments passed to `wp_insert_post` for a license group.
*
* @param array $ld_group_args The arguments array for creating the license group post.
* @param mixed $plugin_instance The instance of the plugin performing the action.
*/
function my_custom_license_group_logic( $ld_group_args, $plugin_instance ) {
// Example: Add custom meta data to the license group.
// This could be useful for tracking specific license types or linking to other data.
if ( isset( $ld_group_args['post_title'] ) && strpos( $ld_group_args['post_title'], 'Premium License' ) !== false ) {
$ld_group_args['meta_input']['custom_license_type'] = 'premium';
$ld_group_args['meta_input']['internal_tracking_id'] = uniqid( 'lic_' );
}
// Example: Modify the post content if it's empty.
if ( empty( $ld_group_args['post_content'] ) ) {
$ld_group_args['post_content'] = 'This is a default license group description. It will be replaced if specific content is provided later.';
}
// Example: Change the post author if a specific condition is met.
// Ensure you have proper permission checks if modifying sensitive data.
if ( current_user_can( 'manage_options' ) ) {
// Assign to a specific admin user if the current user can manage options.
$admin_user_id = get_user_by( 'login', 'site_administrator' )->ID;
if ( $admin_user_id ) {
$ld_group_args['post_author'] = $admin_user_id;
}
}
// Crucially, the modified $ld_group_args need to be available for wp_insert_post.
// Since this is an action hook, we're modifying the array passed by reference
// or expecting the function that fired the hook to use the modified global/passed variable.
// In this specific case, the function that calls do_action likely uses the `$ld_group_args`
// variable directly after this hook, so our modifications will be reflected.
// No explicit return is needed for an action hook that modifies arguments passed by reference or expects them to be mutated.
}
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.php:1005
'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' ),
)
);
do_action( 'ulgm_before_license_group_is_inserted', $ld_group_args, $this );
$group_id = wp_insert_post( $ld_group_args );
if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
$type = 'groups';
// Get the translation id (trid)