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
+);
+
+?>