Filter
uncanny-automator
uap_option_list_gp_award_types
Filters the award types available for Gamipress GP awards.
add_filter( 'uap_option_list_gp_award_types', $callback, 10, 1 );
Description
Filters the list of GamiPress award types. Developers can use this hook to add, remove, or modify award types displayed in Uncanny Automator's GamiPress integration options, allowing for custom award type filtering or selection.
Usage
add_filter( 'uap_option_list_gp_award_types', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter holds the current value or setting being filtered for the gamification award types.
Return Value
The filtered value.
Examples
/**
* Example of how to use the uap_option_list_gp_award_types filter.
*
* This example demonstrates how to dynamically modify the options for GamiPress award types
* in the Uncanny Automator plugin. In this specific scenario, we're going to remove
* the 'points' award type from the list of available options.
*
* @param array $option An array containing the options for GamiPress award types.
* This array typically includes keys like 'options', 'is_ajax', etc.
* @return array The modified array of options.
*/
add_filter( 'uap_option_list_gp_award_types', 'my_automator_remove_gp_points_award', 10, 1 );
function my_automator_remove_gp_points_award( $option ) {
// Check if the 'options' key exists and is an array.
if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {
// Iterate through the options to find and remove the 'points' award type.
foreach ( $option['options'] as $key => $value ) {
// Assuming the award type slug is the key in the $option['options'] array.
if ( $key === 'points' ) {
unset( $option['options'][ $key ] );
// Break the loop once found to avoid unnecessary iteration.
break;
}
}
}
// Return the modified options array.
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/gamipress/helpers/gamipress-helpers.php:116
public function list_gp_award_types( $label = null, $option_code = 'GPAWARDTYPES', $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();
global $wpdb;
if ( Automator()->helpers->recipe->load_helpers ) {
if ( $is_any == true ) {
$options['-1'] = esc_attr__( 'Any achievement', 'uncanny-automator' );
}
// $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;
}
}
/* translators: GamiPress achievement type */
$options['points-award'] = esc_attr__( 'Points awards', 'uncanny-automator' );
/* translators: GamiPress achievement type */
$options['step'] = esc_attr__( 'Step', 'uncanny-automator' );
/* translators: GamiPress achievement type */
$options['rank-requirement'] = esc_attr__( 'Rank requirement', 'uncanny-automator' );
}//end if
$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', 'GamiPress', 'uncanny-automator' ),
);
return apply_filters( 'uap_option_list_gp_award_types', $option );
}