Filter
uncanny-automator
uap_option_list_mycred_rank_types
Filters the list of available myCRED rank types for integration with the User Auto Post plugin.
add_filter( 'uap_option_list_mycred_rank_types', $callback, 10, 1 );
Description
This filter hook allows developers to modify the list of myCred rank types available for selection within Uncanny Automator. It fires when the rank types are being prepared for display, enabling customization of which ranks appear or how they are presented. Developers can add, remove, or alter the rank type options before they are shown to the user.
Usage
add_filter( 'uap_option_list_mycred_rank_types', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter holds the current value of the option being filtered, which is intended to be a list of MyCred rank types.
Return Value
The filtered value.
Examples
add_filter( 'uap_option_list_mycred_rank_types', 'my_custom_mycred_rank_types_filter', 10, 1 );
/**
* Example of filtering the myCred rank types option list.
* This example adds a custom option to the list, for demonstration purposes.
* In a real-world scenario, you might use this to exclude certain ranks or
* add meta information to existing ones.
*
* @param array $option The original array of options for the myCred rank types.
* @return array The modified array of options.
*/
function my_custom_mycred_rank_types_filter( $option ) {
// Assume $option is an array like:
// [
// 'label' => 'Ranks',
// 'options' => [
// 'rank_id_1' => 'Rank Name 1',
// 'rank_id_2' => 'Rank Name 2',
// ],
// // other potential keys like 'is_ajax', 'fill_values_in', etc.
// ]
// Let's pretend we want to add a placeholder for a rank that might be dynamically created.
// Or perhaps we want to ensure a specific rank is always present, even if myCred doesn't list it for some reason.
// For a realistic example, we'll add a new entry.
// In a real scenario, you'd likely interact with myCred's API or stored options
// to get actual rank IDs and names. For simplicity, we'll hardcode one.
if ( ! isset( $option['options'] ) || ! is_array( $option['options'] ) ) {
// If 'options' key is missing or not an array, initialize it.
$option['options'] = array();
}
// Add a custom rank option.
// Replace 'my_custom_rank_id' and 'My Custom Rank' with actual values if needed.
$option['options']['my_custom_rank_id'] = 'My Custom Rank (Added via Filter)';
// You could also modify existing options:
// if ( isset( $option['options']['some_existing_rank_id'] ) ) {
// $option['options']['some_existing_rank_id'] .= ' (Modified)';
// }
// Or remove options:
// unset( $option['options']['rank_to_remove'] );
// Ensure the 'custom_value_description' is still set if it was present.
// This hook specifically deals with the 'mycred_rank_types' option,
// so we expect this key to be relevant.
if ( ! isset( $option['custom_value_description'] ) ) {
$option['custom_value_description'] = esc_attr__( 'Rank ID', 'uncanny-automator' );
}
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/mycred/helpers/mycred-helpers.php:160
public function list_mycred_rank_types( $label = null, $option_code = 'MYCREDRANKTYPES', $args = array() ) {
if ( ! $label ) {
$label = esc_attr__( 'Ranks', '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-ranks'] = esc_attr__( 'All ranks', 'uncanny-automator' );
}
/*if ( Automator()->helpers->recipe->load_helpers ) {
$posts = get_posts( [
'post_type' => 'mycred_rank',
'posts_per_page' => 9999,
'post_status' => 'publish'
] );
if ( ! empty( $posts ) ) {
foreach ( $posts as $post ) {
if ( $post->post_type === 'mycred_rank' ) {
$options[ $post->ID ] = $post->post_title;
}
}
}
}*/
$query_args = array(
'post_type' => 'mycred_rank',
'posts_per_page' => 9999,
'post_status' => 'publish',
);
$options = Automator()->helpers->recipe->wp_query( $query_args );
$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__( 'Rank ID', 'uncanny-automator' ),
);
return apply_filters( 'uap_option_list_mycred_rank_types', $option );
}