From: Steve Sutton Date: Fri, 29 Jun 2018 16:47:51 +0000 (-0400) Subject: Updates for custom fields being in member export. X-Git-Tag: v1.1.0^2~5 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=7e10e7649daefa5f49a350a08ba0c4cde4c2b3f4;p=WP-Plugins%2Fglm-member-db-fields.git Updates for custom fields being in member export. This update allows the custom fields to be inserted into the member export file. --- diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 3825bd6..299aa36 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -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 +);