From: Steve Sutton Date: Fri, 23 Mar 2018 19:18:35 +0000 (-0400) Subject: Filter for getting employees. X-Git-Tag: v1.1.7^2~6 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=e85ab13e24bc65c385b198b8dd7edbebfa1a69a5;p=WP-Plugins%2Fglm-member-db-contacts.git Filter for getting employees. Employees being the other members that a member contact can update. --- diff --git a/setup/adminHooks.php b/setup/adminHooks.php index c64224e..fb75a5f 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -126,4 +126,43 @@ add_filter( 'glm_contact_is_moderated', function( $user ) { return false; } } ); + +/** + * Filter to get the user meta for a contact. + */ +add_filter( 'glm_contact_has_employees', function( $content, $member_id ){ + global $wpdb; + if ( isset( $member_id ) && !$member_id ) { + return $content; + } + // First will have to see if this member a member contact. + $contact = $wpdb->get_row( + $wpdb->prepare( + "SELECT id,email,username + FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts + WHERE ref_dest = %d + AND primary_contact", + $member_id + ), + ARRAY_A + ); + if ( !$contact ) { + return $content; + } + // Get the members wordpress user. + if ( $contact['email'] ) { + $wp_user = get_user_by( 'email', $contact['email'] ); + } else if ( $contact['username'] ) { + $wp_user = get_user_by( 'login', $contact['username'] ); + } + $employees = array(); + // Get the users meta data. + $user_meta = get_user_meta( $wp_user->ID, 'glmMembersContactMembers', true ); + if ( $user_meta ) { + $employees = explode( ',', $user_meta ); + // Remove the $member_id from this array if it's in there. + $employees = array_filter( $employees, function( $input ) use( $member_id ) { return $input != $member_id; } ); + } + return $employees; +}, 10, 2 ); ?>