Updates for custom fields being in member export.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 29 Jun 2018 16:47:51 +0000 (12:47 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 29 Jun 2018 16:47:51 +0000 (12:47 -0400)
This update allows the custom fields to be inserted into the member
export file.

setup/adminHooks.php

index 3825bd6..299aa36 100644 (file)
@@ -196,6 +196,34 @@ add_filter('glm-member-db-admin-search-query', function() {
     return $queryParts;
 });
 
+/**
+ * Filter for returning the memberDb custom fields.
+ *
+ * This can be given UID for members or contacts.
+ *
+ * @param $content Should be false
+ * @param $uid     glm-member-db or glm-member-db-contacts
+ *
+ * @return Array of the id,field_name for custom fields that are for UID.
+ */
+add_filter(
+    'glm-member-db-fields-get-members-fields',
+    function( $content, $uid ){
+        $fields = $this->wpdb->get_results(
+            $this->wpdb->prepare(
+                "SELECT id,field_name
+                   FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields
+                  WHERE uid = %s",
+                $uid
+            ),
+            ARRAY_A
+        );
+        return $fields;
+    },
+    10,
+    2
+);
+
 /**
  * Save the data for the Member Info Custom Fields
  * Returns true if successful
@@ -227,3 +255,22 @@ add_action(
     1,
     2
 );
+
+add_filter(
+    'glm_custom_fields_by_entity_id',
+    function( $attribute, $id = 0 ) {
+        global $wpdb;
+        $query = "SELECT D.field_data, F.field_type FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data D, " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields F "
+            . "WHERE D.entity_id = $id "
+            . "AND D.field_id IN (SELECT id FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_fields WHERE field_name LIKE '$attribute' ) "
+            . "AND F.field_name LIKE '$attribute'";
+
+        $result = $this->wpdb->get_row( $query, ARRAY_A );
+        if ( $result['field_type'] == 'textarea' ) {
+            $result['field_data'] = wpautop( $result['field_data'] );
+        }
+        return $result['field_data'];
+    },
+    10,
+    2
+);