Filter uncanny-automator

uap_option_list_gp_points_types

Filters the available point types displayed in the Gamipress GP Points select option.

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

Description

Filters the array of GamiPress point types used in Uncanny Automator. Developers can modify this array to include, exclude, or alter the display of specific point types when configuring Automator actions or triggers that involve GamiPress points. This hook fires when the GamiPress points options list is being generated.


Usage

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

Parameters

$option (mixed)
This parameter is used to specify the label for the point type option.

Return Value

The filtered value.


Examples

<?php

/**
 * Example of modifying the point types returned by the uap_option_list_gp_points_types filter.
 *
 * This function demonstrates how to add a new custom point type or modify
 * existing ones before they are presented in a GamiPress points selection.
 *
 * @param array $option The array of point types, including 'options' and other settings.
 * @return array The modified array of point types.
 */
function my_custom_gamipress_point_types( $option ) {

	// Simulate fetching available GamiPress point types.
	// In a real scenario, you'd likely use GamiPress's own functions to get this.
	// For this example, we'll mock some data.
	$available_point_types = array(
		'points' => array(
			'name' => __( 'Points', 'gamipress' ),
			'slug' => 'points',
		),
		'extra_points' => array(
			'name' => __( 'Extra Points', 'gamipress' ),
			'slug' => 'extra_points',
		),
	);

	// Ensure the 'options' key exists and is an array before proceeding.
	if ( ! isset( $option['options'] ) || ! is_array( $option['options'] ) ) {
		$option['options'] = array();
	}

	// Loop through our custom point types and add them to the options.
	// We'll prefix them with 'my_custom_' to avoid potential conflicts.
	foreach ( $available_point_types as $slug => $point_data ) {
		$option['options'][ 'my_custom_' . $slug ] = array(
			'label' => $point_data['name'] . ' (Custom)',
			'value' => 'my_custom_' . $slug,
			'data'  => array(
				'gamipress_slug' => $slug, // Store original slug for backend processing
			),
		);
	}

	// You could also filter out specific point types if needed:
	// $option['options'] = array_filter( $option['options'], function( $item ) {
	// 	return $item['value'] !== 'my_custom_extra_points';
	// } );

	return $option;
}

// Add the filter to WordPress.
// The second parameter '1' indicates that this filter accepts one argument.
add_filter( 'uap_option_list_gp_points_types', 'my_custom_gamipress_point_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:174

public function list_gp_points_types( $label = null, $option_code = 'GPPOINTSTYPES', $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-gp-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' => 'points-type' ] );
			$posts = $wpdb->get_results(
				"SELECT ID, post_name, post_title, post_type
											FROM $wpdb->posts
											WHERE post_type LIKE 'points-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( 'Point type slug', 'GamiPress', 'uncanny-automator' ),
		);

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

Scroll to Top