Adding function and filter for cloning custom fields
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 12 Apr 2017 16:25:59 +0000 (12:25 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 12 Apr 2017 16:25:59 +0000 (12:25 -0400)
Used when the member info record is cloned.

classes/customFieldPluginSupport.php
setup/adminHooks.php

index 56ad683..b561633 100644 (file)
@@ -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
  *
index e5e5f57..1756f6d 100644 (file)
@@ -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
+);