Created
August 28, 2017 14:27
-
-
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!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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