Adding new filters for fields
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 8 Aug 2018 18:58:21 +0000 (14:58 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 8 Aug 2018 18:58:21 +0000 (14:58 -0400)
For the grouped fields.

setup/frontHooks.php

index 79cd784..2d68139 100644 (file)
@@ -136,20 +136,82 @@ add_filter('get_glm_custom_fields', function($uid,$entity_id) {
     . "FROM $dataTable "
     . "LEFT JOIN $fieldsTable "
     . "ON $dataTable.field_id = $fieldsTable.id WHERE $dataTable.entity_id = $entity_id;";
-    
+
     $result = $this->wpdb->get_results( $query, ARRAY_A );
     foreach($result as $key=>$value){
         if ($result[$key]['field_type'] == 'textarea') {
             $result[$key]['field_data'] = wpautop($result[$key]['field_data']);
         }
     }
-    
+
 //    echo "<pre>AA" . print_r($result) . "ZZ";
     return $result;
     },
     10,
     2
 );
+
+/**
+ * Filter to get grouped custom fields for template output
+ */
+add_filter(
+    'get_glm_custom_grouped_fields',
+    function( $uid, $entity_id ){
+        global $wpdb;
+        $groupedFields = array();
+
+        $fieldsTable = GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . 'custom_fields';
+        $dataTable   = GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . 'custom_field_data';
+        $groupTable  = GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . 'custom_field_groups';
+
+        $groups = $wpdb->get_results(
+            $wpdb->prepare(
+                "SELECT *
+                   FROM $groupTable
+                  WHERE uid = %s",
+                $uid
+            )
+            , ARRAY_A
+        );
+
+        if ( $groups ) {
+            foreach ( $groups as $group ) {
+                $results = $wpdb->get_results(
+                    $wpdb->prepare(
+                        "SELECT DT.field_data, FT.field_type, FT.field_name
+                           FROM $dataTable DT
+                                LEFT OUTER JOIN $fieldsTable FT ON (DT.field_id = FT.id)
+                          WHERE DT.entity_id = %d
+                            AND FT.gid = %d",
+                        $entity_id,
+                        $group['id']
+                    ),
+                    ARRAY_A
+                );
+                if ( $results ) {
+                    foreach($result as $key=>$value){
+                        if ($result[$key]['field_type'] == 'textarea') {
+                            $result[$key]['field_data'] = wpautop($result[$key]['field_data']);
+                        }
+                    }
+                }
+                $groupedFields[$group['group_name']] = $results;
+            }
+        }
+        return $groupedFields;
+
+    },10,2
+);
+
+/**
+ * Filter to get the wp_option for the name of the custom field
+ */
+add_filter(
+    'get_glm_custom_field_tab_name',
+    function( $uid ){
+    },10,1
+);
+
 add_filter('glm_custom_fields', function($attribute, $id = 0) {
 
     global $wpdb;