Filter uncanny-automator

uap_option_list_mycred_points_types

Filters myCRED points types available in the user menu to allow customization of display.

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

Description

Filters the list of myCRED point types used in Uncanny Automator's myCRED integration. Developers can modify the `$option` array to customize the point type selection, add or remove options, or change their display. This hook fires when the myCRED point type selection is being populated.


Usage

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

Parameters

$option (mixed)
This parameter represents the current value of the options list for MyCred point types, which can be filtered.

Return Value

The filtered value.


Examples

/**
 * Filters the options list for myCred point types to exclude specific point types.
 *
 * This function is a callback for the 'uap_option_list_mycred_points_types' filter.
 * It checks if the current filter context involves a specific setting (e.g., 'mycred_points_settings')
 * and, if so, removes the 'mycred_total' point type from the available options.
 *
 * @param array $options The current array of options for myCred point types.
 * @return array The modified array of options, potentially with 'mycred_total' removed.
 */
add_filter( 'uap_option_list_mycred_points_types', function ( $options ) {

	// Check if we are in a context where we need to filter out specific point types.
	// For example, if a user is configuring an integration that shouldn't use the total points.
	if ( isset( $_POST['meta']['mycred_points_settings'] ) ) { // Example condition: adjust based on actual context

		// Example: Remove the 'mycred_total' point type if it exists in the options.
		// This might be useful if you don't want to allow users to select 'total' points
		// in a specific configuration to avoid potential issues or confusion.
		if ( isset( $options['mycred_total'] ) ) {
			unset( $options['mycred_total'] );
		}
	}

	// Always return the modified (or unmodified) options array.
	return $options;
}, 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/mycred/helpers/mycred-helpers.php:97

public function list_mycred_points_types( $label = null, $option_code = 'MYCREDPOINTSTYPES', $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-mycred-points'] = esc_attr__( 'All point types', 'uncanny-automator' );
		}

		if ( Automator()->helpers->recipe->load_helpers ) {
			$posts = mycred_get_types();

			if ( ! empty( $posts ) ) {
				foreach ( $posts as $key => $post ) {
					$options[ $key ] = $post;
				}
			}
		}
		$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' => esc_attr__( 'Point type meta key', 'uncanny-automator' ),
		);

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

Scroll to Top