Hi,
when you have more than one upload forms on the same page, they need to have different upload IDs in order to work. The ID is defined in the shortcode, so you need to have a mechanism to programmatically assign IDs. However, as I understood you want only one shortcode per table, so there should be only one upload form right?
The upload form can be locked, so that once a file is uploaded the user is not allowed to upload another one, but requires some coding.
All the above can be done in the Free version as well but require some coding. Can you send me the URL of the page so that I can better understand the workflow?
Regards
Nickolas
Hi Nickolas,
thanks for your answer.
I am afraid the page I am referring to is only visibile to logged in users that have a booking (not sure if sharing user data here would be a good idea^^).
However, as I understood you want only one shortcode per table, so there should be only one upload form right?
=> I basically want an upload form per row in my table. But since I am using it with Events Manager, the plugin adds a row with every event I am participating at. So my code right now looks like this:
<table id='dbem-bookings-table' class='widefat post fixed'>
<thead>
<tr>
<th class='manage-column' scope='col'><?php _e('Event', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('Date', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('Schiften/Jobs', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('Status', 'events-manager'); ?></th>
<th class='manage-column' scope='col'>Arbeitsnachweis hochladen</th>
</tr>
</thead>
<tbody>
<?php
$rowno = 0;
$event_count = 0;
$nonce = wp_create_nonce('booking_cancel');
foreach ($EM_Bookings as $EM_Booking) {
/* @var $EM_Booking EM_Booking */
$EM_Event = $EM_Booking->get_event();
if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
$rowno++;
?>
<tr>
<td><?php echo $EM_Event->output("#_EVENTLINK"); ?></td>
<td><?php echo date_i18n( get_option('dbem_date_format'), $EM_Event->start ); ?>- <?php echo date_i18n( get_option('dbem_date_format'), $EM_Event->end ); ?><br/>
</td>
<td><?php echo $EM_Booking->output("#_BOOKINGTICKETS"); ?></td>
<td>
<?php echo $EM_Booking->get_status(); ?>
</td>
<td>
[wordpress_file_upload singlebutton="true"</td>
</tr>
<?php
}
do_action('em_my_bookings_booking_loop',$EM_Booking);
$event_count++;
}
?>
</tbody>
</table>
To give the following result: https://jobs.myeventy.de/wp-content/uploads/overview.JPG
So that is fine and I understood that I have to generate an ID for each form. Do you happen to offer a development service? So I can hire you to develope that along with other tasks? Your plugin goes definitely in the right direction so I feel like you are the most qualified person for that :).
Ok here are some suggested mofications to your code. I added a closing bracket in the shortcode and also added PHP code that generates a different (random) 4-digit shortcode id every time.
<table id='dbem-bookings-table' class='widefat post fixed'>
<thead>
<tr>
<th class='manage-column' scope='col'><?php _e('Event', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('Date', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('Schiften/Jobs', 'events-manager'); ?></th>
<th class='manage-column' scope='col'><?php _e('Status', 'events-manager'); ?></th>
<th class='manage-column' scope='col'>Arbeitsnachweis hochladen</th>
</tr>
</thead>
<tbody>
<?php
$rowno = 0;
$event_count = 0;
$nonce = wp_create_nonce('booking_cancel');
foreach ($EM_Bookings as $EM_Booking) {
/* @var $EM_Booking EM_Booking */
$EM_Event = $EM_Booking->get_event();
if( ($rowno < $limit || empty($limit)) && ($event_count >= $offset || $offset === 0) ) {
$rowno++;
?>
<tr>
<td><?php echo $EM_Event->output("#_EVENTLINK"); ?></td>
<td><?php echo date_i18n( get_option('dbem_date_format'), $EM_Event->start ); ?>- <?php echo date_i18n( get_option('dbem_date_format'), $EM_Event->end ); ?><br/></td>
<td><?php echo $EM_Booking->output("#_BOOKINGTICKETS"); ?></td>
<td>
<?php echo $EM_Booking->get_status(); ?>
</td>
<td>[wordpress_file_upload uploadid="<?php mt_srand((double)microtime()*1000000); echo (string)mt_rand(1000, 9999); ?>" singlebutton="true"]</td>
</tr>
<?php
}
do_action('em_my_bookings_booking_loop',$EM_Booking);
$event_count++;
}
?>
</tbody>
</table>
Try it and let me know.
Nickolas
Hi Nickolas,
thanks so much. Works like a charm.
For
The upload form can be locked, so that once a file is uploaded the user is not allowed to upload another one, but requires some coding.
Does this already comes with the pro Version?
Yes this requires a plugin hook. Since you have the free version you need to put it at the end of functions.php file of your theme. Here it is:
if (!function_exists('wfu_before_upload_handler')) {
function wfu_before_upload_handler($changable_data, $additional_data) {
$limit = 1;
$user = wp_get_current_user();
if ( $user->ID != 0 ) {
$filerecs = wfu_get_recs_of_user($user->ID);
if ( count($filerecs) >= $limit )
$changable_data["error_message"] = "File rejected. Maximum upload limit reached.";
}
return $changable_data;
}
add_filter('wfu_before_upload', 'wfu_before_upload_handler', 10, 2);
}
This will limit the users to one upload. You can change $limit if you want to allow more uploads per user.
Nickolas
Hi Nickolas,
thanks! I am on the pro version now and am using hooks already. I tried the function you gave me but it isn’t doing much I am afraid. Or maybe my expectations aren’t right?
I am basically expecting that once the user uploads something in one of the upload forms on https://jobs.myeventy.de/wp-content/uploads/overview.JPG it then says: you already uploaded a file here. Is that not what happens?
The above script will limit files per user. So, if a logged user has already uploaded a file, he will not be allowed to upload another one.
What you ask is different?
Nickolas
Okay understood :). That makes sense. I haven’t tested the function to limit the uploads til the end now (cause my client was fine with having several uploads) but I will mark the topic as resolved. Thanks for your help!
Moderator
Jan Dembowski
(@jdembowski)
Forum Moderator and Brute Squad
For pro or commercial product support please contact the author directly on their site. This includes pre-sales questions.
As the author is aware, commercial products are not supported in these forums. As you are their potential customer I am sure they will have no problem supporting you there.