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

    (@nickboss)

    Hi,

    it can be done by implementing wfu_before_file_check filter. This filter performs custom checks before the file is accepted. You can define any checks you want, using PHP.

    I can give you more info if you want.

    Nickolas

    Thread Starter teste123456

    (@teste123456)

    Hi Nickolas, thanks for the fast response!
    Yes an example would be great!

    Plugin Author nickboss

    (@nickboss)

    you have the free or pro version (instructions are a little bit different)?

    Thread Starter teste123456

    (@teste123456)

    No, not yet, i was attempting with free version before.

    Plugin Author nickboss

    (@nickboss)

    ok, if you have the free version you need to install Code Snippets plugin, which you can use to implement the filter, or just add the code below inside wp_functions.php file of your WordPress website.

    With Code Snippets, just create a new Code Snippet, give it any name you want and put the following code in the Code box:

    if (!function_exists('wfu_before_file_check_handler')) {
    	function wfu_before_file_check_handler($changable_data, $additional_data) {
    		// Add code here...
    		$user = get_userdata($additional_data["user_id"]);
    		if ( $user != false ) {
    			$filerecs = wfu_get_recs_of_user($additional_data["user_id"]);
    			$lastupload_time = 0;
    			foreach( $filerecs as $filerec ) {
    				if ( $filerec->uploadtime > $lastupload_time )
    					$lastupload_time = $filerec->uploadtime;
    			}
    			if ( $lastupload_time > 0 ) {
    				$day_same = (date("Ymd", time()) == date("Ymd", $lastupload_time));
    				$month_same = (date("Ym", time()) == date("Ym", $lastupload_time));
    				if ( $day_same ) {
    					$changable_data["error_message"] = "You are allowed to upload only one file per day. Please try again tomorrow.";
    				}
    			}
    		}
    		return $changable_data;
    	}
    	add_filter('wfu_before_file_check', 'wfu_before_file_check_handler', 10, 2);
    }

    Then save and activate the snippet and you are ready.

    The above code will restrict a user to perform a second upload the same day.

    Try it and let me know.

    Nickolas

    Plugin Author nickboss

    (@nickboss)

    marking as resolved

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Limit file upload per month’ is closed to new replies.