Filter
uncanny-automator-pro
uap_option_list_bbpress_topics
Filters bbPress topic options for use within the Uncanny Automator plugin's settings.
add_filter( 'uap_option_list_bbpress_topics', $callback, 10, 1 );
Description
Filters the list of available bbPress topic options for Uncanny Automator. Developers can add custom bbPress topic data points to be used in Automator recipes. Use this hook to extend the integration with your own specific bbPress fields or custom post meta related to topics.
Usage
add_filter( 'uap_option_list_bbpress_topics', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter is used to define the label for the option list of BBPress topics.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to hook into 'uap_option_list_bbpress_topics'
* to add custom options for bbPress topics in Uncanny Automator Pro.
*
* This example adds a new option to display the author's display name
* if the topic is created by a logged-in user.
*/
add_filter(
'uap_option_list_bbpress_topics',
function ( $option ) {
// Ensure we are working with the correct section if needed,
// or directly append to the main array if the structure allows.
// Assuming $option is an array of arrays, and we want to modify
// a specific section, e.g., 'BBPRESS_TOPICS'.
// You might need to inspect the $option structure to be certain.
// For demonstration, let's assume $option is structured like this:
// $option = [
// 'SECTION_KEY' => [
// 'KEY_1' => 'Value 1',
// // ... existing options
// ],
// // ... other sections
// ];
// If the structure isn't guaranteed or is dynamic, you might need to
// find the correct place to insert or simply merge.
// A safer approach is to understand the expected structure from the source code.
// Based on the provided source context, it seems the filter might be applied
// within a function that builds a specific array for 'BBPRESS_TOPICS'.
// Let's assume we need to add to the list of options within the 'BBPRESS_TOPICS' key.
$custom_options = array();
// Check if the 'BBPRESS_TOPICS' key exists and is an array
if ( isset( $option['BBPRESS_TOPICS'] ) && is_array( $option['BBPRESS_TOPICS'] ) ) {
// Add a new custom option.
// We'll use a hypothetical $option_code prefix, as seen in the source.
// In a real scenario, you'd determine this prefix based on how Uncanny Automator
// generates its option codes. For this example, let's invent one.
$option_code_prefix = 'BBPRESS_TOPIC'; // This might need to be adjusted based on actual usage.
// Example: Add an option to get the topic author's display name.
// This would likely require an additional function within Uncanny Automator
// to retrieve this data dynamically when the automation runs.
$custom_options[ $option_code_prefix . '_AUTHOR_DISPLAY_NAME' ] = esc_attr__( 'Topic Author Display Name', 'uncanny-automator-pro' );
// Merge the custom options into the existing 'BBPRESS_TOPICS' array.
// We are prepending them to ensure they appear at the top, or you could append.
$option['BBPRESS_TOPICS'] = array_merge( $custom_options, $option['BBPRESS_TOPICS'] );
} else {
// If 'BBPRESS_TOPICS' doesn't exist, or is not an array,
// you might need to create it or handle it differently.
// For this example, we'll assume it exists. If it were a completely
// new section, you'd do:
// $option['NEW_BBPRESS_SECTION'] = $custom_options;
}
// Return the modified array.
return $option;
},
10, // Priority: 10 is the default, adjust if needed.
1 // Accepted args: The callback function accepts 1 argument ($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/bbpress/helpers/bbpress-pro-helpers.php:222
public function list_bbpress_topics( $label = null, $option_code = 'BBTOPICS', $any_option = false, $multi_select = false ) {
if ( ! function_exists( 'bbp_get_topic_post_type' ) ) {
return Automator()->helpers->recipe->build_default_options_array( $label, $option_code );
}
if ( ! $label ) {
$label = esc_attr__( 'Topic', 'uncanny-automator-pro' );
}
$any_label = null;
if ( $any_option ) {
$any_label = esc_attr__( 'Any topic', 'uncanny-automator-pro' );
}
$args = array(
'post_type' => bbp_get_topic_post_type(),
'posts_per_page' => 999,
'orderby' => 'title',
'order' => 'DESC',
'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',
'supports_multiple_values' => $multi_select,
'required' => true,
'options' => $options,
'relevant_tokens' => array(
$option_code => esc_attr__( 'Topic title', 'uncanny-automator-pro' ),
$option_code . '_ID' => esc_attr__( 'Topic ID', 'uncanny-automator-pro' ),
$option_code . '_URL' => esc_attr__( 'Topic URL', 'uncanny-automator-pro' ),
$option_code . '_GUEST_EMAIL' => esc_attr__( 'Guest email', 'uncanny-automator-pro' ),
$option_code . '_GUEST_NAME' => esc_attr__( 'Guest name', 'uncanny-automator-pro' ),
$option_code . '_GUEST_WEBSITE' => esc_attr__( 'Guest website', 'uncanny-automator-pro' ),
$option_code . '_FORUM_ID' => esc_attr__( 'Forum ID', 'uncanny-automator-pro' ),
$option_code . '_FORUM_TITLE' => esc_attr__( 'Forum title', 'uncanny-automator-pro' ),
$option_code . '_FORUM_URL' => esc_attr__( 'Forum URL', 'uncanny-automator-pro' ),
),
);
return apply_filters( 'uap_option_list_bbpress_topics', $option );
}