Filter uncanny-automator

uap_option_list_buddyboss_forums

Filters the BuddyBoss forum options for user access permissions before they are displayed.

add_filter( 'uap_option_list_buddyboss_forums', $callback, 10, 1 );

Description

Filters the available options for BuddyBoss forums within Uncanny Automator. Developers can use this hook to add or modify the selectable forum tokens for recipes, like Forum Title, ID, or URL, to customize automation triggers and actions.


Usage

add_filter( 'uap_option_list_buddyboss_forums', 'your_function_name', 10, 1 );

Parameters

$option (mixed)
This parameter is the option array being filtered, allowing for modifications to the list of BuddyBoss forums.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to filter the uap_option_list_buddyboss_forums hook.
 *
 * This example demonstrates adding an extra relevant token for BuddyBoss forums,
 * specifically the 'Forum Description'.
 */
add_filter( 'uap_option_list_buddyboss_forums', 'my_uap_add_buddyboss_forum_description_token', 10, 1 );

/**
 * Adds a 'Forum Description' token to the list of relevant tokens for BuddyBoss forums.
 *
 * @param array $option The current option array being filtered.
 * @return array The modified option array with the new token.
 */
function my_uap_add_buddyboss_forum_description_token( $option ) {
	// Ensure we are dealing with the expected structure and that $option_code is set.
	// In a real scenario, you might need to fetch $option_code dynamically or
	// infer it based on the structure of $option. For this example, we'll assume
	// it's available or can be constructed. If $option is not an array, or doesn't
	// contain the expected 'relevant_tokens' key, we should handle that gracefully.

	if ( ! is_array( $option ) || ! isset( $option['relevant_tokens'] ) || ! is_array( $option['relevant_tokens'] ) ) {
		// If the structure is unexpected, return the original option to avoid errors.
		return $option;
	}

	// Attempt to infer the $option_code. This is a crucial assumption.
	// In the context of Uncanny Automator, $option_code is likely determined
	// by the trigger or action slug. If you are implementing this outside
	// of Uncanny Automator's core, you might need to pass this information
	// or adapt the logic.
	// For this example, let's assume the $option_code can be derived from
	// the keys already present, like 'forum_title', 'forum_ID', etc.
	// A safer approach might be to check if 'forum_title' exists and use its prefix.
	$option_code = null;
	foreach ( $option['relevant_tokens'] as $key => $value ) {
		if ( str_ends_with( $key, '_title' ) ) {
			$option_code = substr( $key, 0, -strlen( '_title' ) );
			break;
		}
	}

	// If we couldn't determine the option code, return the original option.
	if ( $option_code === null ) {
		return $option;
	}

	// Add the new relevant token for the forum description.
	$option['relevant_tokens'][ $option_code . '_description' ] = esc_attr__( 'Forum Description', '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

src/integrations/buddyboss/helpers/buddyboss-helpers.php:215
uncanny-automator-pro/src/integrations/buddyboss/helpers/buddyboss-pro-helpers.php:442

public function list_buddyboss_forums( $label = null, $option_code = 'BDBFORUMS', $args = array() ) {

		if ( ! function_exists( 'bbp_get_forum_post_type' ) ) {

			return Automator()->helpers->recipe->build_default_options_array( $label, $option_code );
		}

		$args = wp_parse_args(
			$args,
			array(
				'uo_include_any' => false,
				'uo_any_label'   => esc_attr__( 'Any forum', 'uncanny-automator' ),
			)
		);
		if ( ! $label ) {
			$label = esc_attr__( 'Forum', 'uncanny-automator' );
		}

		$options    = array();
		$forum_args = array(
			'post_type'      => bbp_get_forum_post_type(),
			'posts_per_page' => 999,
			'orderby'        => 'title',
			'order'          => 'ASC',
			'post_status'    => array( 'publish', 'private' ),
		);

		if ( $args['uo_include_any'] ) {
			$options[- 1] = $args['uo_any_label'];
		}

		$forums = Automator()->helpers->recipe->options->wp_query( $forum_args );
		if ( ! empty( $forums ) ) {
			foreach ( $forums as $key => $forum ) {
				$options[ $key ] = $forum;
			}
		}

		$option = array(
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => 'select',
			'required'        => true,
			'options'         => $options,
			'relevant_tokens' => array(
				$option_code          => esc_attr__( 'Forum title', 'uncanny-automator' ),
				$option_code . '_ID'  => esc_attr__( 'Forum ID', 'uncanny-automator' ),
				$option_code . '_URL' => esc_attr__( 'Forum URL', 'uncanny-automator' ),
			),
		);

		return apply_filters( 'uap_option_list_buddyboss_forums', $option );
	}

Scroll to Top