// Build field list string including all but the ID field
$fields = '';
$imageFields = array();
+ $fileFields = array();
$sep = '';
foreach ($this->fieldData as $f) {
}
// Located any fields that require special processing
+ // Images
if ($f['type'] == 'image') {
$imageFields[] = $f['name'];
}
+ // Files
+ if ( $f['type'] == 'file' ) {
+ $fileFields[] = $f['name'];
+ }
}
// Assemble query to duplicate the record.
}
+ if ( count( $fileFields ) > 0 ) {
+ $updateSQL = '';
+ $sep = '';
+ foreach ( $fileFields as $f ) {
+ // If there's an file referenced
+ if ( $newData[$f] != '' ) {
+ // Create new file name
+ $newName = preg_replace('/\d{10}/', time(), $newData[$f]);
+ // Check if we have the original file, then copy it to the new name
+ if ( file_exists( GLM_MEMBERS_PLUGIN_FILES_PATH . '/' . $newData[$f] ) ) {
+ copy(
+ GLM_MEMBERS_PLUGIN_FILES_PATH . '/' . $newData[$f],
+ GLM_MEMBERS_PLUGIN_FILES_PATH . '/' . $newName
+ );
+ }
+ // Add to sql to update this field
+ $updateSQL .= $sep."$f = '$newName'";
+ $sep = ', ';
+ }
+ }
+
+ // If there were any updates
+ if ($updateSQL != '') {
+
+ $sql = "
+ UPDATE ".$this->table."
+ SET $updateSQL
+ WHERE id = $newID
+ ;";
+ $this->wpdb->query( $sql );
+ }
+ }
+
return $newID;
}
}
-?>
\ No newline at end of file
+?>