uap_option_all_ld_groups
Filters the list of all LearnDash groups before they are displayed or used by the plugin.
add_filter( 'uap_option_all_ld_groups', $callback, 10, 1 );
Description
Fires after LearnDash groups are retrieved and formatted into an option array for Uncanny Automator. Developers can modify the `$option` array to customize which groups are available, add or remove relevant tokens, or alter the `supports_custom_value` flag before it's displayed in the Automator interface.
Usage
add_filter( 'uap_option_all_ld_groups', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter is used to retrieve all LearnDash groups, potentially with labels, option codes, and other configurations.
Return Value
The filtered value.
Examples
/**
* Filters the available LearnDash group options to exclude groups that are not yet fully set up.
* This is useful for ensuring that only valid, existing groups are selectable in certain automation triggers/actions.
*
* @param array $option The current option array for LearnDash groups.
* @return array The modified option array.
*/
add_filter( 'uap_option_all_ld_groups', function( $option ) {
// Ensure $option is an array and has the 'options' key.
if ( ! is_array( $option ) || ! isset( $option['options'] ) || ! is_array( $option['options'] ) ) {
return $option;
}
$valid_groups = array();
foreach ( $option['options'] as $group_id => $group_data ) {
// In a real-world scenario, you might check for specific group metadata or user roles associated with the group
// to determine if it's "fully set up" or relevant for automation.
// For this example, we'll assume a simple check: if the group has a 'group_name' property, it's valid.
// In the actual Uncanny Automator Pro plugin, this logic would be more sophisticated, likely checking
// for the presence of Learndash group data and potentially other integration-specific flags.
if ( isset( $group_data['group_name'] ) && ! empty( $group_data['group_name'] ) ) {
$valid_groups[ $group_id ] = $group_data;
}
}
$option['options'] = $valid_groups;
return $option;
}, 10, 1 ); // Priority 10, accepts 1 argument.
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/integrations/learndash/helpers/learndash-helpers.php:518
src/integrations/uncanny-groups/helpers/uncanny-groups-helpers.php:92
uncanny-automator-pro/src/integrations/learndash/helpers/learndash-pro-helpers.php:1276
public function all_ld_groups( $label = null, $option_code = 'LDGROUP', $all_label = false, $any_option = true, $multiple_values = false, $relevant_tokens = true, $supports_multi_custom = false ) {
if ( ! $label ) {
$label = esc_attr_x( 'Group', 'Learndash', 'uncanny-automator' );
}
$args = array(
'post_type' => 'groups',
'posts_per_page' => 9999, // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page
'orderby' => 'title',
'order' => 'ASC',
'post_status' => 'publish',
);
if ( $all_label ) {
$options = Automator()->helpers->recipe->options->wp_query( $args, $any_option, esc_attr_x( 'Any group', 'Learndash', 'uncanny-automator' ), $all_label );
} else {
$options = Automator()->helpers->recipe->options->wp_query( $args, $any_option, esc_attr_x( 'Any group', 'Learndash', 'uncanny-automator' ) );
}
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'options' => $options,
'supports_multiple_values' => $multiple_values,
'relevant_tokens' => wp_list_pluck( $this->get_group_relevant_tokens( 'trigger', $option_code ), 'name' ),
'custom_value_description' => esc_html_x( 'Group ID', 'LearnDash', 'uncanny-automator' ),
);
if ( false === $relevant_tokens ) {
$option['relevant_tokens'] = array();
}
if ( $multiple_values && $supports_multi_custom ) {
$option['supports_custom_value'] = true;
}
return apply_filters( 'uap_option_all_ld_groups', $option );
}