From: Steve Sutton Date: Fri, 2 Dec 2016 18:38:28 +0000 (-0500) Subject: Setup filter for fetching the primary email for member. X-Git-Tag: v1.0.17^2~7 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=7185b6a3f36a6a49a70055e7aeef8550d45e7edb;p=WP-Plugins%2Fglm-member-db-contacts.git Setup filter for fetching the primary email for member. Looks for a primary contact record. If that is not found then it looks for the email from the members active record. --- diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 7fcc24a..d520aa1 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -44,4 +44,47 @@ add_filter('glm-member-db-admin-management-hooksHelp', function($content) { 2 ); -?> \ No newline at end of file +add_filter( + 'glm-member-db-admin-get-member-primary-email', + function( $content, $memberId ){ + global $wpdb; + //$content = $memberId; + // See if this member has a member contact + $contact_email = $wpdb->get_var( + $wpdb->prepare( + "SELECT email + FROM " . GLM_MEMBERS_CONTACTS_PLUGIN_DB_PREFIX . "contacts + WHERE ref_dest = %d + AND primary_contact", + $memberId + ) + ); + if ( $contact_email ) { + return $contact_email; + } + require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMemberInfo.php'; + // First get the active member info record id + $memberInfoData = new GlmDataMemberInfo( $wpdb, $this->config ); + $activeMemberInfoId = $memberInfoData->getActiveInfoIdForMember( $memberId ); + if ( !$activeMemberInfoId ) { + return false; + } + // If we're here then we didn't find primary contact record so get the email from the member info. + $contact_email = $wpdb->get_var( + $wpdb->prepare( + "SELECT email + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info + WHERE id = %d", + $activeMemberInfoId + ) + ); + if ( $contact_email ) { + return $contact_email; + } + return $content; + }, + 10, + 2 +); + +?>