• Resolved findingitontheway

    (@findingitontheway)


    Hi Nicholas,

    I am using the Pro Version and following hook to change my file pattern:

    if (!function_exists('wfu_before_file_check_handler')) {
    
    	function wfu_before_file_check_handler($changable_data, $additional_data) {
    		$user = get_userdata($additional_data["user_id"]);
    		if ( $user != false ) {
    			$filepath = wfu_basedir($changable_data["file_path"]);
    			$username = $user->user_login;
    			$new_filename = $changable_data["user_data"][0]["value"];
    			$fileext = wfu_fileext($changable_data["file_path"], true);
    			$changable_data["file_path"] = $filepath.$username."-".$new_filename.$fileext;
    		}
    		return $changable_data;
    	}
    	add_filter('wfu_before_file_check', 'wfu_before_file_check_handler', 10, 2); 
    }

    Is it possible to “call” other things as well? I am using it with Event Manager and ideally would want to put the event ID or Event – Name into the filepath. If so, could you point me in the right direction how to do that?

    Thanks in advance!

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author nickboss

    (@nickboss)

    This requires integration with Event Manager. Can you show me the page where you have them?

    What is required is Event ID to be passed together with the file when the file is uploaded. This can be done if you create a second user data field, which is not visible to the user and which takes automatically the Event ID.

    This can be done with little javascript code probably, but I need to see the page.

    Nickolas

    Thread Starter findingitontheway

    (@findingitontheway)

    It’s basically the same page, we discussed here : https://ww.wp.xz.cn/support/topic/questions-about-the-pro-version-2/

    To call the EventID I could use <?php echo $EM_Event->output(“#_EVENTNAME”); ?> in

    <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>

    but I am not sure how to pass that on into your plugin.

    Plugin Author nickboss

    (@nickboss)

    Ok, you can replace [wordpress_file_upload singlebutton="true" with the following:

    [wordpress_file_upload singlebutton="true" userdatalabel="EventID|t:text|s:left|r:0|a:0|p:inline|d:<?php echo $EM_Event->output("#_EVENTNAME"); ?>"]

    I added a user field in the upload form which takes the Event ID from the PHP script as default value. Then we need to use little css to hide to field, so it is not visible to the user, but before we do that first check that this solution works.

    Nickolas

    Thread Starter findingitontheway

    (@findingitontheway)

    Awesome you are a hero! It works like a charm and I hide the field.

    Is there a chance to hide the upload progress bar as well other than by CSS? Ideally I would just see the success message as it was in the free version (I might be blind, but I just can’t find the settings for that).

    And: Is there a chance to use userfirst name and user lastname instead of userID?

    Thread Starter findingitontheway

    (@findingitontheway)

    And to add another question: How can I change the pattern for duplicated files? Right now it adds the date and time 201711131842 which is quite long. Ideally I would only show 1, 2, 3,…

    Plugin Author nickboss

    (@nickboss)

    Just one question, do you really see the EventID field? I am asking because we forgot to put userdata=”true” inside the shortcode.

    If you want to remove the progressbar, then the shortcode should be like this:

    [wordpress_file_upload singlebutton="true" placements="title/filename+selectbutton+uploadbutton/userdata/message" userdata="true" userdatalabel="EventID|t:text|s:left|r:0|a:0|p:inline|d:<?php echo $EM_Event->output("#_EVENTNAME"); ?>"]

    Regarding userID, where you have this? and also the duplicates policy? are these in another shortcode or the same?

    Nickolas

    Thread Starter findingitontheway

    (@findingitontheway)

    I basically started to create my own shortcode cause it wasn’t working at the beginning (probably cause the userdata=”true” was missing. So I basically have:

    [wordpress_file_upload multiple="true" notifysubject="Es wurde ein neuer Arbeitsnachweise für das Event %userdata1% hochgeladen " notifymessage="Es wurde ein neuer Arbeitsnachweis von %username% für das Event %userdata1% hochgeladen. Dieser befindet sich im Anhang oder unter %filepath%" userdata="true" userdatalabel="EventID|t:text|s:none|r:0|a:0|p:none|d:"]

    on the connected side (where it is not showing cause I am already using another shortcode from Events Manager) and then:

    [wordpress_file_upload uploadid="<?php mt_srand((double)microtime()*1000000); echo (string)mt_rand(1000, 9999); ?>" multiple="true" uploadpath="/uploads/arbeitsnachweise/" notifysubject="Es wurde ein neuer Arbeitsnachweise f&uuml;r das Event %userdata1% hochgeladen" notifymessage="Es wurde ein neuer Arbeitsnachweis von %username% f&umml;r das Event %userdata1% hochgeladen. Dieser befindet sich im Anhang oder unter %filepath%" userdata="true" userdatalabel="EventID|t:text|s:none|r:0|a:0|p:none|d:<?php echo $EM_Event->output("#_EVENTNAME"); ?>"] within the mybookings.php from Events Manager.

    It sounds like a weird workaround but I experienced that I would need to have both shortcodes, cause they wouldn’t want to work without the other.

    I then used the advanced settings for Default Duplicate File Action to maintain both (that is where the duplicates policy is coming from).

    And the hook:

    if (!function_exists('wfu_before_file_check_handler')) {
    
    	function wfu_before_file_check_handler($changable_data, $additional_data) {
    		$user = get_userdata($additional_data["user_id"]);
    		if ( $user != false ) {
    			$filepath = wfu_basedir($changable_data["file_path"]);
    			$username = $user->user_login;
    			$new_filename = $changable_data["user_data"][0]["value"];
    			$fileext = wfu_fileext($changable_data["file_path"], true);
    			$changable_data["file_path"] = $filepath.$username."-".$new_filename.$fileext;
    		}
    		return $changable_data;
    	}
    	add_filter('wfu_before_file_check', 'wfu_before_file_check_handler', 10, 2); 
    }

    to create the filepattern. Not sure if there would have been a better way, but it is more or less working.

    Plugin Author nickboss

    (@nickboss)

    ok, if you have problems let me know

    Nickolas

    Thread Starter findingitontheway

    (@findingitontheway)

    Hi Nicholas,

    thanks for your help so far. I have your plugin almost where I want it to be :).

    Just one last question for the file pattern. Is it possible to use the users first and lastname instead of the username?

    Thread Starter findingitontheway

    (@findingitontheway)

    Already figured it out using

    if (!function_exists('wfu_before_file_check_handler')) {
    
    	function wfu_before_file_check_handler($changable_data, $additional_data) {
    		$user = get_userdata($additional_data["user_id"]);
    		if ( $user != false ) {
    			$filepath = wfu_basedir($changable_data["file_path"]);
    			$username = $user->user_login;
    			$first_name = $user->first_name;
          $last_name = $user->last_name;
    			$new_filename = $changable_data["user_data"][0]["value"];
    			$fileext = wfu_fileext($changable_data["file_path"], true);
    			$changable_data["file_path"] = $filepath.$new_filename."_".$first_name.$last_name.$fileext;
    		}
    		return $changable_data;
    	}
    	add_filter('wfu_before_file_check', 'wfu_before_file_check_handler', 10, 2); 
    }
    Plugin Author nickboss

    (@nickboss)

    Yep you ‘ve done it right

    Nickolas

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    I am using the Pro Version

    For pro or commercial product support please contact the author directly on their site.

    As the author is aware, commercial products are not supported in these forums. As you are their customer I am sure they will have no problem supporting you there.

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Change Filepattern’ is closed to new replies.