Filter uncanny-automator

uap_option_list_gp_rank_types

Filters the available rank types displayed in the GamiPress options for user achievements.

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

Description

Filters the list of available rank types for GamiPress integration in Uncanny Automator. Developers can modify the `$option` array to add, remove, or alter rank types, influencing which ranks are selectable within Automator recipes. Use this to customize rank selection or introduce custom rank types for integration.


Usage

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

Parameters

$option (mixed)
This parameter contains the current option value, which can be of mixed types, and is used to filter the list of GamiPress rank types.

Return Value

The filtered value.


Examples

// Example function to filter the GamiPress rank types options.
// This function might be used to selectively hide certain rank types from a dropdown or to add custom data to them.
function my_uncanny_automator_filter_gp_rank_types( $option ) {

	// Assuming $option is an array containing the rank type data,
	// and we want to add an extra property to each rank type.

	if ( ! empty( $option['options'] ) && is_array( $option['options'] ) ) {
		foreach ( $option['options'] as $key => &$rank_type_data ) {
			// Add a custom property, for example, to indicate if it's a premium rank type.
			// In a real scenario, you'd fetch this information based on actual GamiPress data.
			$rank_type_data['is_premium'] = ( $rank_type_data['slug'] === 'premium_rank' ); // Example logic

			// You could also remove certain rank types based on a condition
			// if ( $rank_type_data['slug'] === 'deprecated_rank' ) {
			//     unset( $option['options'][ $key ] );
			// }
		}
		// Re-index the array if elements were unset
		$option['options'] = array_values( $option['options'] );
	}

	// Always return the modified option array.
	return $option;
}
add_filter( 'uap_option_list_gp_rank_types', 'my_uncanny_automator_filter_gp_rank_types', 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/gamipress/helpers/gamipress-helpers.php:226

public function list_gp_rank_types( $label = null, $option_code = 'GPRANKTYPES', $args = array() ) {

		if ( ! $label ) {
			$label = esc_attr__( 'Rank 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'] : '';
		$options      = array();

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

			// $posts = Automator()->helpers->recipe->options->wp_query( [ 'post_type' => 'rank-type' ] );
			$posts = $wpdb->get_results(
				"SELECT ID, post_name, post_title, post_type
											FROM $wpdb->posts
											WHERE post_type LIKE 'rank-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( 'Rank type slug', 'GamiPress', 'uncanny-automator' ),
		);

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

Scroll to Top