How Do I Limit Users with NextGen Public Upload

Just Wondering If This Is Possible? The Author of the plugin won't help anyone so I decided to ask here.

  • PC

    Hello @Sneakheads

    Thanks for posting on the forums.

    I hope that you are referring to http://wordpress.org/plugins/nextgen-public-uploader/ here.

    I am not sure what you mean by "How Do I Limit Users with NextGen Public Upload" you mean how many people can upload images ?

    I will try and find if I can get something on this however as this is a 3rd party plugin so I will not commit a resolution here but I will do my best to point you in the right direction.

    So, what is it that you are trying to achieve here?

    Please advise.

    Cheers
    PC
    Sales &Support

  • PC

    Hello @Sneakheads

    Greetings and thanks for writing back.

    I discussed this with my team members and unfortunately there is no way to do it out of the box as restricting the users to upload only one file using that plugin will include creating a custom function which will check for the number of files a user has uploaded and will also need to check if the user is logged in or not. That means it will only be limited to the logged in users.

    We have a limited scope of support on issues related to custom coding however you can post a job requirement on the Job Board : https://premium.wpmudev.org/wpmu-jobs/ to get someone right on it.

    I have also left the thread open for other members of the community to chime in and provide their thoughts on this.

    Cheers, PC

  • Ignacio

    Hello @Sneakheads.

    Allow only logged users is an easy one: Inside your Admin side, go to Gallery>Public Uploader. You'll see an option called "Minimum User Role". Select Subscriber (this is the user with less capabilities) and that's it.

    If you want to allow users to upload just one image per gallery, then you'll have to save some data about the user ID and the gallery ID. WordPress has a table calles usermeta where you can save this kind of data. In order to save the data in that table you can make use of add_user_meta function, that has the following parameters:

    add_user_meta( $user_id, $meta_key, $meta_value )

    $user_id is pretty clear, $meta_key is the name of the data you're going to save and $meta_value is the value of that data. In our example we want to save an array of values. Each of these values will be the IDs of the galleries where the user has upload an image, so for example:

    add_user_meta( 20, 'nextgen_uploads', array( 1, 5, 7, 10 ) )

    Means that the user with ID = 20 has uploaded images to galleris with IDs 1,5,7 and 10. Easy, right? Ok, let's go back to the plugin code. I'll give you a basic code, I cannot cover every situation with the plugin but at least is a starting point:

    Go to file nextgen-public-uploader/inc/npu-upload.php and in line 397 you'll see something like this:

    if(get_option('npu_upload_success')) {
    	$this->arrImageMsg_widg[] = get_option('npu_upload_success');
    } else {
    	$this->arrImageMsg_widg[] = "Thank you! Your image has been submitted and is pending review.";
    }
    $this->sendEmail();

    Change that by:

    if(get_option('npu_upload_success')) {
    	$this->arrImageMsg_widg[] = get_option('npu_upload_success');
    } else {
    	$this->arrImageMsg_widg[] = "Thank you! Your image has been submitted and is pending review.";
    }
    
    $gal_id = absint( $_POST['galleryselect'] );
    $user_id = get_current_user_id();
    if ( $user_id && $gal_id ) {
    
    	$user_uploads = get_user_meta( $user_id, 'nextgen_uploads', true );
    
    	if ( empty( $user_uploads ) )
    		$user_uploads = array( $gal_id );
    	else
    		$user_uploads[] = $gal_id;
    
    	$result = update_user_meta( $user_id, 'nextgen_uploads', $user_uploads );
    }
    $this->sendEmail();

    So we are saving now the galleries IDs for each user. You'll have to add the same code about line 327. One is for the widget and the other for the shortcode.

    Ok, now that we're saving the galleries IDs for each user, we'll need to disable the uploader id the user has already uploaded a file to the gallery. Go to line 255:

    if (!is_user_logged_in() && get_option('npu_user_role_select') != 99) {
    	$strOutput .= "<div class=\"need_login\">";
    	if(get_option('npu_notlogged')) {
    		$strOutput .= get_option('npu_notlogged');
    	} else {
    		$strOutput .= "You must be registered and logged in to upload images.";
    	}
    	$strOutput .= "</div>";
    } else {

    Add the following lines:

    $user_id = get_current_user_id();
    $already_uploaded = false;
    if ( $user_id ) {
    	$user_uploads = get_user_meta( $user_id, 'nextgen_uploads', true );
    
    	if ( is_array( $user_uploads ) && in_array( $gal_id, $user_uploads ) )
    		$already_uploaded = true;
    }
    
    if (!is_user_logged_in() && get_option('npu_user_role_select') != 99) {
    	$strOutput .= "<div class=\"need_login\">";
    	if(get_option('npu_notlogged')) {
    		$strOutput .= get_option('npu_notlogged');
    	} else {
    		$strOutput .= "You must be registered and logged in to upload images.";
    	}
    	$strOutput .= "</div>";
    } elseif ( $already_uploaded ) {
    	$strOutput .= "You have already uploaded an image in this gallery.";
    } else {

    And, same than before, you'll have to add the same code about in about line 186 for the shortcode.

    And I think that should be enough, but this has no sense if you don't select "Subscriber" in "Minimum User Role". Let me know if is working for you.

    Regards.
    Ignacio.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.