prefix . "user_files_link"; if (count($_POST) > 0) { if ($_POST['action'] == 'add') { $rows_affected = $wpdb->insert( $table_name, array( 'user_id' => $_POST['users'], 'attachment_id' => $_POST['files'] ) ); } if ($_POST['action'] == 'delete') { $rows_affected = $wpdb->query( "DELETE FROM ". $table_name. " WHERE user_id = ". $_POST['userID'] . " AND attachment_id = ". $_POST['fileID'] ); } } $media_query = new WP_Query( array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'posts_per_page' => -1, ) ); $fileList = array(); foreach ($media_query->posts as $post) { $fileList[] = array( $post->post_name, $post->ID ); } ?>

User Files Settings

To assign a file to a user, select the file from the left dropdown below, select the user you want to assign it to from the right dropdown below, and click the Assign File to User button.

Files: '; foreach ($fileList as $file) { echo ''; } echo ''; ?> Users:

Existing User File Links

Below are the files that are already assigned to the users. If you would like to remove a file from a user, click the Delete button on the line of the user file link you would like to remove.

get_results("SELECT * FROM ". $table_name); // Iterate through existing links foreach ($linkList as $record) { // Go through the user array to find the user of this link foreach ($userArray as $user) { if ($user->ID == $record->user_id) { $username = $user->user_nicename; } } // Go through the file array to find the file foreach ($fileList as $file) { if ($file[1] == $record->attachment_id) { $filename = $file[0]; } } // Display it in the table echo str_replace( array("%user", "%file"), array(ucwords( strtolower($username)), ucwords( strtolower($filename))), '' ); } ?>
Users Files Delete
%user%file '. PHP_EOL . '
'. PHP_EOL . ' '. PHP_EOL . ' '. PHP_EOL . ' '. PHP_EOL . ' '. PHP_EOL . '