• grasycho

    (@grasycho)


    Hello,
    I’m trying to create a multi vendor marketplace. I would like to limit upload file count to 3 per session.

    I could not find such a code there were only examples about limiting upload sizes. Should I need to change core files? I just need to disable multiple file upload feature or limit it with max 3.

    By the way there was one example but it counts all uploads by user. I want it to count per session.

    add_filter( 'wp_handle_upload_prefilter', 'wp_check_upload_limits' );
    function wp_check_upload_limits( $file ) {
        $current_user = wp_get_current_user();
        $current_user_role = $current_user->roles[0];
    
        if ( $current_user_role != "contributor" )
            return false;
    
        $upload_count = get_user_meta( $current_user->ID, 'upload_count', true );
        $upload_count_limit_reached = apply_filters( 'wpse47580_upload_count_limit_reached', 100 ) > ( $upload_count + 1 );
    
        if ( $upload_count_limit_reached )
            $file['error'] = 'Upload limit has been reached for this user!';
    
        return $file;
    }

    Thank you.
    Best Regards.

  • The topic ‘Limit Upload Count per User Role’ is closed to new replies.