Filter
uncanny-automator-pro
uap_option_get_bp_group_types
Filters the available BuddyPress group types when retrieving plugin options.
add_filter( 'uap_option_get_bp_group_types', $callback, 10, 1 );
Description
Filters the available BuddyPress group types for selection in Uncanny Automator. Developers can modify the array of group types by adding, removing, or altering existing ones. This hook fires when the group type options are being prepared for use in Automator's integration settings.
Usage
add_filter( 'uap_option_get_bp_group_types', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter is the WordPress option value being filtered, which will contain an array of BuddyPress group types.
Return Value
The filtered value.
Examples
add_filter( 'uap_option_get_bp_group_types', 'my_custom_bp_group_types_filter', 10, 1 );
/**
* Filters the BuddyPress group types for Uncanny Automator.
*
* This function demonstrates how to modify the list of BuddyPress group types
* available in Uncanny Automator. In this example, we're removing a specific
* group type from the options.
*
* @param array $option The original array of BuddyPress group types.
* @return array The modified array of BuddyPress group types.
*/
function my_custom_bp_group_types_filter( $option ) {
// Check if the 'options' key exists and is an array
if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {
$bp_group_types = $option['options'];
// Example: Remove a group type with a specific ID (replace 'private-group-id' with an actual ID if known)
// You would typically get the group types and then filter them based on some logic.
// For demonstration, let's assume we want to exclude a group type with the slug 'private'.
$bp_group_types = array_filter( $bp_group_types, function( $group_type ) {
// Assuming each group type in the array has a 'slug' key.
// Adjust this condition based on the actual structure of the $bp_group_types array.
// If the structure is different, you'll need to inspect $bp_group_types to find the correct key.
return isset( $group_type['slug'] ) && $group_type['slug'] !== 'private';
} );
// Update the options in the original array
$option['options'] = $bp_group_types;
}
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/buddypress/helpers/buddypress-pro-helpers.php:332
public function get_bp_group_types( $label = null, $option_code = 'BP_GROUP_TYPES', $args = array() ) {
$args = wp_parse_args(
$args,
array(
'uo_include_any' => false,
'uo_any_label' => esc_attr_x( 'Any group type', 'Buddypress', 'uncanny-automator-pro' ),
)
);
if ( ! $label ) {
$label = esc_attr_x( 'Group type', 'Buddypress', 'uncanny-automator-pro' );
}
$options = array();
if ( Automator()->helpers->recipe->load_helpers ) {
if ( $args['uo_include_any'] ) {
$options[- 1] = $args['uo_any_label'];
}
if ( function_exists( 'bp_groups_get_group_types' ) ) {
$types = bp_groups_get_group_types( array(), 'objects' );
if ( $types ) {
foreach ( $types as $type ) {
$options[ esc_attr( $type->name ) ] = esc_html( $type->labels['singular_name'] );
}
}
}
}
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'options' => $options,
'is_ajax' => false,
'relevant_tokens' => array(),
'custom_value_description' => esc_html_x( 'Group type ID', 'BuddyPress', 'uncanny-automator-pro' ),
);
return apply_filters( 'uap_option_get_bp_group_types', $option );
}