glm_custom_fields filter only wpautop on textareas
authorLaury GvR <laury@gaslightmedia.com>
Fri, 30 Jun 2017 14:05:03 +0000 (10:05 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Fri, 30 Jun 2017 14:05:03 +0000 (10:05 -0400)
wpautop() was being applied to all results from the glm_custom_fields,
so the query was expanded to check for the field's type, and only
apply to textareas, so that not every field gets a paragraph tag
wrapped around it.

setup/frontHooks.php

index 916b023..4c7bf9a 100644 (file)
@@ -111,10 +111,17 @@ add_filter('glm-member-db-fields-front-list-query-params', function( $query ){
 add_filter('glm_custom_fields', function($attribute, $id = 0) {
 
     global $wpdb;
-    $query = "SELECT field_data FROM " . GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data WHERE ref_dest = $id "
-            . "AND field_id IN (SELECT id FROM ".GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX."custom_fields WHERE field_name LIKE '$attribute' )";
-    $result = wpautop($wpdb->get_var( $query ));
-    return $result;
+    $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.ref_dest = $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']);
+    }
+//    echo "<pre>AA" . print_r($result) . "ZZ";
+    return $result['field_data'];
     },
     10,
     2