Filter uncanny-automator

uap_option_list_bbpress_forums

Filters the list of bbPress forums available for selection in plugin options.

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

Description

Filters the list of available BBPress forum tokens within Uncanny Automator. Developers can use this hook to add, remove, or modify the tokens provided for BBPress forums, allowing for more dynamic and customized recipe triggers and actions related to forum content.


Usage

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

Parameters

$option (mixed)
This parameter contains the current value of the option being filtered, which is typically an array of bbPress forums.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of filtering the uap_option_list_bbpress_forums hook.
 *
 * This example demonstrates how to add a custom token for the selected
 * bbPress forum, specifically to include the number of topics within that forum.
 *
 * @param array $option The original option array containing forum details and tokens.
 * @return array The modified option array with the added custom token.
 */
add_filter( 'uap_option_list_bbpress_forums', function( $option ) {

	// Ensure this is a valid forum option and we have a forum ID to work with.
	if ( ! isset( $option['value'] ) || empty( $option['value'] ) ) {
		return $option;
	}

	$forum_id = $option['value'];
	$option_code = key( $option['options'] ); // Assuming the first key is the main option code.

	// Fetch the number of topics for the current forum.
	$forum_topic_count = bbpress()->topics->get_count( $forum_id );

	// Add a new relevant token for the number of topics.
	$option['relevant_tokens'][ $option_code . '_topic_count' ] = esc_attr__( 'Number of topics', 'uncanny-automator' );

	// Note: When you add a new token like this, you would typically
	// also need to ensure Uncanny Automator's token processing logic
	// knows how to retrieve and display this new token's value.
	// This example only shows adding the token to the list of available tokens.
	// The actual retrieval of the value for this token would happen
	// elsewhere in Uncanny Automator based on the added key.

	return $option;

}, 10, 1 ); // Priority 10, 1 accepted 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/bbpress/helpers/bbpress-helpers.php:96
uncanny-automator-pro/src/integrations/bbpress/helpers/bbpress-pro-helpers.php:166

public function list_bbpress_forums( $label = null, $option_code = 'BBFORUMS', $any_option = false ) {

		if ( ! function_exists( 'bbp_get_forum_post_type' ) ) {

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

		if ( ! $label ) {
			$label = esc_attr__( 'Forum', 'uncanny-automator' );
		}

		$any_label = null;

		if ( $any_option ) {
			$any_label = esc_attr__( 'Any forum', 'uncanny-automator' );
		}

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

		$options = Automator()->helpers->recipe->options->wp_query( $args, $any_option, $any_label );

		$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_bbpress_forums', $option );
	}

Scroll to Top