Filter
uncanny-automator-pro
uap_option_all_lf_groups
Filters the available LifterLMS groups for specific UAP settings before they are displayed.
add_filter( 'uap_option_all_lf_groups', $callback, 10, 1 );
Description
Filters the array of available LifterLMS group token options before they are displayed in Uncanny Automator. Developers can use this hook to add, remove, or modify the token options available for LifterLMS groups, such as adding custom fields or modifying existing ones.
Usage
add_filter( 'uap_option_all_lf_groups', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter holds the current value of the option being filtered, which can be modified before it's returned by the hook.
Return Value
The filtered value.
Examples
add_filter( 'uap_option_all_lf_groups', 'my_custom_lifterlms_group_options', 10, 1 );
/**
* Adds custom options for LifterLMS groups to Uncanny Automator.
*
* This function intercepts the options array for LifterLMS groups and
* adds additional custom fields related to group properties.
*
* @param array $option The original options array for LifterLMS groups.
* @return array The modified options array with custom group fields.
*/
function my_custom_lifterlms_group_options( $option ) {
// Assuming $option is an array that looks like this initially:
// [
// 'id' => 'some_unique_id',
// 'options' => [
// 'group_ID' => 'Group ID',
// 'group_URL' => 'Group URL',
// // ... other default options
// ]
// ]
// We want to add new options related to LifterLMS groups.
// For this example, let's say we want to add an option for the group's creation date.
// In a real scenario, you would likely fetch this data from LifterLMS if available
// or if you had a custom way to track it.
// For demonstration purposes, we'll simulate adding a 'GROUP_CREATED_DATE' option.
// You would replace 'your_prefix_group_created_date' with a unique key.
$option['options']['your_prefix_group_created_date'] = esc_attr__( 'Group Creation Date', 'uncanny-automator' );
// You could also add more complex data by checking existing options or lifterlms data.
// For instance, if you wanted to include information about the group's associated course:
// $option['options']['group_COURSE_ID'] = esc_attr__( 'Associated Course ID', 'uncanny-automator' );
// $option['options']['group_COURSE_TITLE'] = esc_attr__( 'Associated Course Title', 'uncanny-automator' );
return $option;
}
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
uncanny-automator-pro/src/integrations/lifterlms/helpers/lifterlms-pro-helpers.php:117
public function all_lf_groups( $label = null, $option_code = 'LFGROUPS', $any_option = true ) {
if ( ! $label ) {
$label = esc_attr__( 'Group', 'uncanny-automator-pro' );
}
$args = array(
'post_type' => 'llms_group',
'posts_per_page' => 999,
'orderby' => 'title',
'order' => 'ASC',
'post_status' => 'publish',
);
$options = Automator()->helpers->recipe->options->wp_query( $args, $any_option, esc_attr__( 'Any group', 'uncanny-automator' ) );
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
// to setup example, lets define the value the child will be based on
'current_value' => false,
'validation_type' => 'text',
'options' => $options,
'relevant_tokens' => array(
$option_code => esc_attr__( 'Group title', 'uncanny-automator' ),
$option_code . '_ID' => esc_attr__( 'Group ID', 'uncanny-automator' ),
$option_code . '_URL' => esc_attr__( 'Group URL', 'uncanny-automator' ),
$option_code . '_THUMB_ID' => esc_attr__( 'Group featured image ID', 'uncanny-automator' ),
$option_code . '_THUMB_URL' => esc_attr__( 'Group featured image URL', 'uncanny-automator' ),
),
);
return apply_filters( 'uap_option_all_lf_groups', $option );
}