Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielmerovingi/c6262dcf54224cc16bc6932bfb05640f to your computer and use it in GitHub Desktop.
Save gabrielmerovingi/c6262dcf54224cc16bc6932bfb05640f to your computer and use it in GitHub Desktop.
Generates a dropdown menu of transfer recipients that has been set in the mycred_transfer shortcode by providing a comma separated list of ids for the pay_to shortcode attribute. Requires 1.7.9.1 or higher!
/**
* Preselect Transfer Recipient
* Generates a dropdown menu of transfer recipients that has been
* set in the mycred_transfer shortcode by providing a comma separated list of
* ids for the pay_to shortcode attribute.
* @since 1.0
* @version 1.0
*/
function mycred_pro_pre_selected_transfer_recipients( $field, $settings, $atts ) {
if ( array_key_exists( 'pay_to', $atts ) ) {
$recipients = explode( ',', $atts['pay_to'] );
if ( count( $recipients ) > 1 ) {
// Make sure the IDs are valid and that it is not our own ID
$user_id = get_current_user_id();
$ids = array();
foreach ( $recipients as $recipient_id ) {
$recipient_id = absint( $recipient_id );
if ( $recipient_id === 0 || $recipient_id == $user_id ) continue;
$ids[] = $recipient_id;
}
if ( ! empty( $ids ) ) {
$field = '<select name="mycred_new_transfer[recipient_id]" class="form-control">';
foreach ( $recipients as $recipient_id ) {
$user = get_userdata( $recipient_id );
$field .= '<option value="' . $user->ID . '">' . $user->display_name . '</option>';
}
$field .= '</select>';
}
}
}
return $field;
}
add_filter( 'mycred_transfer_to_field', 'mycred_pro_pre_selected_transfer_recipients', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment