From 291a7d50968aa1dd9cefcfeafb5c8f2f311301d7 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 12 Apr 2017 12:25:59 -0400 Subject: [PATCH] Adding function and filter for cloning custom fields Used when the member info record is cloned. --- classes/customFieldPluginSupport.php | 25 +++++++++++++++++++++++++ setup/adminHooks.php | 10 ++++++++++ 2 files changed, 35 insertions(+) diff --git a/classes/customFieldPluginSupport.php b/classes/customFieldPluginSupport.php index 56ad683..b561633 100644 --- a/classes/customFieldPluginSupport.php +++ b/classes/customFieldPluginSupport.php @@ -59,6 +59,31 @@ function customFieldsSaveMemberInfoFields( $memberId ) } } +function customFieldsCloneMemberInfoFields( $oldId, $newId ) +{ + global $wpdb; + $customFields = customFieldsGetMemberInfoFields( $oldId ); + $fieldDataFormat = array( + '%d', + '%d', + '%s' + ); + if ( isset( $customFields ) ) { + foreach ( $customFields as $fieldId => $fieldData ) { + $fieldData =array( + 'ref_dest' => $newId, + 'field_id' => $fieldId, + 'field_data' => $fieldData + ); + $wpdb->insert( + GLM_MEMBERS_FIELDS_PLUGIN_DB_PREFIX . "custom_field_data", + $fieldData, + $fieldDataFormat + ); + } + } +} + /** * customFieldsGetMemberInfoFields * diff --git a/setup/adminHooks.php b/setup/adminHooks.php index e5e5f57..1756f6d 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -45,3 +45,13 @@ add_action( 1, 1 ); +add_action( + 'glm-member-db-member-info-clone-custom-fields', + function( $memberInfoId, $newId ){ + require_once GLM_MEMBERS_FIELDS_PLUGIN_CLASS_PATH . '/customFieldPluginSupport.php'; + // this will clone the custom fields data + customFieldsCloneMemberInfoFields( $memberInfoId, $newId ); + }, + 1, + 2 +); -- 2.17.1