Filter uncanny-automator

uap_option_list_bo_award_types

Filters the list of available award types for BuddyPress integration when awarding badges.

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

Description

Filters the list of award types returned by BadgeOS when generating options for automations. Developers can use this hook to add, remove, or modify award types available for selection within Uncanny Automator's BadgeOS integration. This hook fires during the retrieval of award type data.


Usage

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

Parameters

$option (mixed)
This parameter represents the value of an award type option, which can be of mixed data types.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of using the uap_option_list_bo_award_types filter to modify the available BadgeOS award types.
 * This example adds a custom award type to the list and also filters out a specific existing award type.
 *
 * @param array $option The array of award types data.
 * @return array The modified array of award types data.
 */
add_filter( 'uap_option_list_bo_award_types', function( $option ) {
	// Ensure we are dealing with the expected array structure
	if ( ! is_array( $option ) || ! isset( $option['options'] ) || ! is_array( $option['options'] ) ) {
		return $option;
	}

	// Add a custom award type
	$option['options']['my_custom_award'] = array(
		'value' => 'my_custom_award',
		'label' => __( 'My Custom Achievement', 'uncanny-automator' ),
	);

	// Filter out a specific award type (e.g., if we don't want to allow awarding 'points')
	if ( isset( $option['options']['points'] ) ) {
		unset( $option['options']['points'] );
	}

	// You could also modify existing options if needed
	// For example, change the label of an existing award type:
	// if ( isset( $option['options']['badges'] ) ) {
	// 	$option['options']['badges']['label'] = __( 'Awesome Badges', 'uncanny-automator' );
	// }

	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/badgeos/helpers/badgeos-helpers.php:111

public function list_bo_award_types( $label = null, $option_code = 'BOAWARDTYPES', $args = array() ) {

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

		$token        = key_exists( 'token', $args ) ? $args['token'] : false;
		$is_ajax      = key_exists( 'is_ajax', $args ) ? $args['is_ajax'] : false;
		$is_any       = key_exists( 'is_any', $args ) ? $args['is_any'] : false;
		$target_field = key_exists( 'target_field', $args ) ? $args['target_field'] : '';
		$end_point    = key_exists( 'endpoint', $args ) ? $args['endpoint'] : '';
		$options      = array();

		if ( $is_any == true ) {
			$options['-1'] = esc_html__( 'Any achievement', 'uncanny-automator' );
		}

		global $wpdb;
		if ( Automator()->helpers->recipe->load_helpers ) {

			//$posts = Automator()->helpers->recipe->options->wp_query( [ 'post_type' => 'achievement-type' ] );
			$posts = $wpdb->get_results(
				"SELECT ID, post_name, post_title, post_type
											FROM $wpdb->posts
											WHERE post_type LIKE 'achievement-type' AND post_status = 'publish' ORDER BY post_title ASC"
			);

			if ( ! empty( $posts ) ) {
				foreach ( $posts as $post ) {
					$options[ $post->post_name ] = $post->post_title;
				}
			}
		}
		$type = 'select';

		$option = array(
			'option_code'              => $option_code,
			'label'                    => $label,
			'input_type'               => $type,
			'required'                 => true,
			'supports_tokens'          => $token,
			'is_ajax'                  => $is_ajax,
			'fill_values_in'           => $target_field,
			'endpoint'                 => $end_point,
			'options'                  => $options,
			'custom_value_description' => _x( 'Achievement type slug', 'BadgeOS', 'uncanny-automator' ),
		);

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

Scroll to Top