Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Modify Next Gen Gallery WordPress

  • SOLVED

I am working on a site where users can upload images to be displayed publicly. The two main plugins that I am using are NextGen Gallery and Gravity Forms. So far I have been able to configure gravity forms so that the file the user uploads is placed in the appropriate directory used by a specific NextGen Gallery.

Within the NextGen Gallery Manage Gallery options I can click on the button "scan folder for new images" and it will successfully locate any new images and create thumbnails for them. The problem is...when I click the "scan folder for new images" it makes each new image public. There is an option in NextGen Gallery to mark an image as "exclude" which means it won't be displayed on the front end of the site. I want to use this "exclude" attribute as a means to moderate the images that users upload. So when I click on "scan folder for new images" any new image is automatically marked as "exclude".

There is an existing plugin called the Next Gen Public Uploader which does this already but the plugin lacks the form functionality that I need which is why I'm using Gravity Forms. If someone is pretty savvy this should be really easy to figure out.

I guess the ideal solution would be something that I could place in my functions.php so if I ever needed to update the NGG plugin it wouldn't overwrite it. However, at this point if we have to hack the NGG plugin that is OK.

I appreciate your help in advance.

The NextGen Public Uploader uses a function like this (i think) to set the exclude:


foreach ($image_ids as $pid) {
$wpdb->query("UPDATE $wpdb->nggpictures SET exclude = '$npu_exclude_id' WHERE pid = '$pid'");
$this->arrThumbReturn[] = $this->create_thumbnail($pid);

}

Answers (4)

2012-02-03

Duncan O'Neill answers:

Hi Derek,

Or, you could take a sledgehammer approach and alter a file within the next-gen gallery plugin.

In my version of the plugin ( which is probably outdated ) there is a line within the plugin's admin/functions.php which you can alter. This is part of the function add_Images(), and is on line 523 in my version of next-gen. Find this line;

$result = $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->nggpictures (galleryid, filename, alttext, exclude) VALUES (%s, %s, %s, 0)", $galleryID, $picture, $alttext) );

and alter it to

$result = $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->nggpictures (galleryid, filename, alttext, exclude) VALUES (%s, %s, %s, 1)", $galleryID, $picture, $alttext) );


You're just changing that zero value to 1 for the value of the exclude field in the db.

Of course, you'd have to go back and manually update the images you wanted to include.

hth,

2012-02-03

Sébastien | French WordpressDesigner answers:

which version of nextgengallery do you use ?


if you use the last version of NGG, open the file nextgen-gallery/lib/ngg-db.php
at the line 613 you have this code :
if ( false === $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->nggpictures (image_slug, galleryid, filename, description, alttext, meta_data, post_id, imagedate, exclude, sortorder)
VALUES (%s, %d, %s, %s, %s, %s, %d, %s, %d, %d)", $slug, $id, $filename, $description, $alttext, $meta_data, $post_id, $imagedate, $exclude, $sortorder ) ) ) {
return false;
}


replace it by
if ( false === $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->nggpictures (image_slug, galleryid, filename, description, alttext, meta_data, post_id, imagedate, exclude, sortorder)
VALUES (%s, %d, %s, %s, %s, %s, %d, %s, 1, %d)", $slug, $id, $filename, $description, $alttext, $meta_data, $post_id, $imagedate, $exclude, $sortorder ) ) ) {
return false;
}


this is the same principle of the answer of Duncan O'Neill
but for the last version of NGG


EDIT : Arnav Joy's response is better :-)

2012-02-03

Arnav Joy answers:

try this in your functions.php

I have tested it , it works well

add_action('ngg_after_new_images_added','my_function',10,2);

function my_function($galleryID,$image_ids){
global $wpdb;
foreach($image_ids as $imgID)
$wpdb->query("UPDATE $wpdb->nggpictures SET exclude = '1' WHERE pid = '$imgID' ");

}


derekshirk comments:

This is exactly what I was looking for. Works perfectly so far.
I have one more question that I am going to post and I bet you all would be able to help me out with.

Thank you so much for all of you help.
This is the first question I have asked on this website. I am going to use Arnav's answer but since Duncan and Sebastien also posted good answers is it appropriate for me to award them a small portion of the prize money?

2012-02-03

rizaljohn answers:

derekshirk,

I have tried to use the NGG public uploader that is integrated in the membership site. I think I can help you with that.


derekshirk comments:

Great.

Just for clarification. I do not want to use the NGG public uploader. However the NGG public uploader happens to have a bit of functionality I would like to recreate within the standard NGG plugin and that is any new image that is placed in a designated gallery directory should be marked as exclude when I click on the "scan folder for new images" button.


rizaljohn comments:

Got it. Sent you PM.


rizaljohn comments:

Here you go, add this to your functions.php:


if( is_admin() && class_exists('nggdb') ){
function ext_ngg_exclude_images(){
global $wpdb;

if( isset($_REQUEST['scanfolder']) ) {
$galleryID = (int)$_GET['gid'];
$wpdb->query("UPDATE $wpdb->nggpictures SET exclude = '1' WHERE galleryid = '$galleryID'");
}
return;
}
if( $_GET['page'] == 'nggallery-manage-gallery' && isset($_GET['gid']) ) {
add_action('admin_init', 'ext_ngg_exclude_images', 1);
}
}



Tested it.