Filter
uncanny-automator
uap_option_list_bo_points_types
Filters the list of available point types for BadgeOS when setting up user points options.
add_filter( 'uap_option_list_bo_points_types', $callback, 10, 1 );
Description
Filters the list of BadgeOS point types used in Uncanny Automator's action and trigger select fields. Developers can modify the array of point types, adding or removing options, to customize how BadgeOS points are integrated with Automator.
Usage
add_filter( 'uap_option_list_bo_points_types', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter represents the label or title for the point type option.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to filter the available BadgeOS point types for Uncanny Automator.
*
* This function modifies the list of point types that Uncanny Automator can use
* to trigger automations or assign points. In this example, we'll remove a specific
* point type if its slug matches a certain string, for demonstration purposes.
*
* @param array $options An associative array of available BadgeOS point types.
* Keys are the point type slugs, and values are their display names.
* @return array The modified array of BadgeOS point types.
*/
function my_uncanny_automator_filter_badgeos_points( $options ) {
// Check if the input is indeed an array and not empty
if ( ! is_array( $options ) || empty( $options ) ) {
return $options;
}
// Let's say we want to hide a point type with the slug 'super_points'
$slug_to_remove = 'super_points';
// Iterate through the options and remove the unwanted point type
foreach ( $options as $slug => $name ) {
if ( $slug === $slug_to_remove ) {
unset( $options[ $slug ] );
}
}
// Alternatively, you could add a new option if you had custom BadgeOS point types
// and wanted to make them available to Uncanny Automator.
// $options['my_custom_point_slug'] = 'My Custom Point Type';
return $options;
}
add_filter( 'uap_option_list_bo_points_types', 'my_uncanny_automator_filter_badgeos_points', 10, 1 );
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:171
public function list_bo_points_types( $label = null, $option_code = 'BOPOINTSTYPES', $args = array() ) {
if ( ! $label ) {
$label = esc_attr__( 'Point type', 'uncanny-automator' );
}
$token = key_exists( 'token', $args ) ? $args['token'] : false;
$is_ajax = key_exists( 'is_ajax', $args ) ? $args['is_ajax'] : false;
$target_field = key_exists( 'target_field', $args ) ? $args['target_field'] : '';
$end_point = key_exists( 'endpoint', $args ) ? $args['endpoint'] : '';
$include_all = key_exists( 'include_all', $args ) ? $args['include_all'] : false;
$options = array();
if ( $include_all ) {
$options['ua-all-bo-types'] = esc_attr__( 'All point types', 'uncanny-automator' );
}
global $wpdb;
if ( Automator()->helpers->recipe->load_helpers ) {
//$posts = Automator()->helpers->recipe->options->wp_query( [ 'post_type' => 'point_type' ] );
$posts = $wpdb->get_results(
"SELECT ID, post_name, post_title
FROM $wpdb->posts
WHERE post_type LIKE 'point_type' AND post_status = 'publish' ORDER BY post_title ASC"
);
if ( ! empty( $posts ) ) {
foreach ( $posts as $post ) {
$options[ $post->post_name ] = $post->post_title;
}
}
}
//$options = Automator()->helpers->recipe->options->wp_query( [ 'post_type' => 'point_type' ] );
$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( 'Point type slug', 'BadgeOS', 'uncanny-automator' ),
);
return apply_filters( 'uap_option_list_bo_points_types', $option );
}