Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Add custom transfer fields for giving credits to creators
- function mycred_pro_custom_transfer_compl( $options ) {
- $options['display_name'] = 'Display Name';
- return $options;
- }
- add_filter( 'mycred_transfer_autofill_by', 'mycred_pro_custom_transfer_compl' );
- // Take over the autocomplete process
- function mycred_pro_custom_autocomplete( $transfer_settings, $mycred ) {
- $results = array();
- $user_id = get_current_user_id();
- $string = sanitize_text_field( $_REQUEST['string']['term'] );
- global $wpdb;
- // Query
- $blog_users = $wpdb->get_results( $wpdb->prepare( "SELECT display_name, ID FROM {$wpdb->users} WHERE ID != %d AND display_name LIKE %s;", $user_id, '%' . $string . '%' ), 'ARRAY_N' );
- if ( $wpdb->num_rows > 0 ) {
- foreach ( $blog_users as $hit ) {
- if ( $mycred->exclude_user( $hit[1] ) ) continue;
- $results[] = $hit[0];
- }
- }
- wp_send_json( $results );
- }
- add_action( 'mycred_transfer_autofill_find', 'mycred_pro_custom_autocomplete', 10, 2 );
- // Get the recipient
- function mycred_pro_find_transfer_recipient( $recipient_id, $to ) {
- if ( $recipient_id !== false ) return $recipient_id;
- global $wpdb;
- // Get user by display name
- $recipient = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->users} WHERE display_name = %s", $to ) );
- if ( $recipient !== NULL )
- $recipient_id = $recipient;
- return $recipient_id;
- }
- add_filter( 'mycred_transfer_get_recipient', 'mycred_pro_find_transfer_recipient', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement