prefix. "user_files_link";
$sql = "CREATE TABLE " . $table_name . " ( ". PHP_EOL
. "user_id mediumint(10) NOT NULL, ". PHP_EOL
. "attachment_id mediumint(10) NOT NULL, ". PHP_EOL
. " PRIMARY KEY id (user_id, attachment_id) ". PHP_EOL
. ");";
dbDelta($sql);
add_option("ftu_db_version", "1.0");
}
/**
* Displays the dashboard widget with the linked files for the logged in user.
*
* @global object $current_user
* @global object $wpdb
*/
function add_dashboard_widget_function()
{
global $current_user, $wpdb;
$table_name = $wpdb->prefix. "user_files_link";
get_currentuserinfo();
// assign the current user's id to $user_ID
$user_ID = $current_user->ID;
$linkList = $wpdb->get_results(
"SELECT * FROM ". $table_name. " WHERE user_id = ". $user_ID
);
$media_query = new WP_Query(
array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'posts_per_page' => -1,
)
);
$fileList = array();
$counter = 0;
foreach ($media_query->posts as $post) {
$fileList[] = array(
$post->post_name,
$post->ID,
$post->post_content,
$post->guid
);
}
echo 'Below are the files assigned to your user account, you can download '
. 'these files by clicking the links, or by right clicking them and '
. 'selecting Save link as...
'
. '
| '. PHP_EOL . ' Files'. PHP_EOL . ' | '. PHP_EOL . '
|---|
| %file '. $fileDesc. ' |
| No files available. |