Support » Plugin: NextGEN Gallery Voting » A way to check if a user can vote from external php file

  • Resolved lagdonkey


    Have been working on implementing your plugin into my theme, and for the most part love it. However, I want to take a different approach to how the voting forms appear.

    What I’m trying to do, is do an external check (from my own php file) to see if a user has the ability to vote on the current image (PID). However, when I try and include ngg-voting.php it seems the $offical function around line 174X causes it to bung up, not allowing me to include the file.

    To clarify I want to:

    Check with Ngg-voting to see if a user can vote on image (Based on the predefined options ie: IP/if voting is enabled etc) from my own php file, and then set a variable on if they can/can’t.

    Just looking for advice on how I can proceed.

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


    Hi lagdonkey

    WordPress automatically includes all active plugins when it ‘boots up’, so you never have to.

    The <?php echo nggv_imageVoteForm($image->pid); ?> function does all the checks to see if a user can vote already. The actual outputting of the voting form happens inside that function.

    I’m not sure why you would want to check all the logic yourself when the function already does it, but perhaps I just don’t understand the end goal correctly.

    If you care to elaborate, I will be happy to give and advice 🙂

    Thanks for the rather quick reply 🙂

    I realize that WP loads all plugins, however if there’s a way to call a function of a loaded plugin from another php file (ie: a template page) I’m not sure how to go about that.

    Basically what I’m after is displaying the vote option per image. After a bit of googling, I was able to figure out that you can put:

    $pid = get_query_var(‘pid’);

    To get the current picture id and Then

    echo nggv_imageVoteForm($pid);

    to show the form based on the picture id.

    What I’m WANTING to do however, is set up the page so that it first checks to see if the user can vote. If they can’t, then I play on displaying my own content where the echo nggv_imageVoteForm($pid); would go.

    So basically:

    If User can vote = Yes then display echo nggv_imageVoteForm($pid);
    Else display blah blah blah.

    If you want to look at what I mean, check out:

    You’ll notice on the bottom right under tags is what I’m referring to.

    Plugin Author shauno


    Check out line 334 of ngg-voting.php. That is the method canVoteImage(). It checks if a user can vote on an image, and will return true if they can, and a string of the reason why not, if they can’t. Remember to use the triple equal for comparison, when checking the result of this method.

    So, based on what you’ve said, something like this should work (not tested, but you get the idea):

    $pid = get_query_var('pid');
    global $officalNggVoting;
    if($officalNggVoting->canVoteImage($pid, 0) === true) {
    	echo nggv_imageVoteForm($pid);
    	//show other info here

    Wow, that was EXACTLY what I was looking for, thank you SO much for your fast response. I spent nearly 2 days looking at ngg-voting.php, trying to somehow decipher the code, but as I said I’m still fairly new to PHP.

    Amazing plugin and amazing support, thanks again 🙂

    Actually, 1 more quick question.

    if($officalNggVoting->canVoteImage($pid, 0) === true) {

    I’m guessing the 0 refers to the kind of check done? Ie: If voting is enabled. Is there different codes based on the check?


    if($officalNggVoting->canVoteImage($pid, 1) === true) { This would check if the users ip has voted.

    Plugin Author shauno


    No, the 0 is for a premium feature. If you use the Premium add on (available here), you can setup more than 1 ‘criteria’ to vote on per image (eg, you can ask a user to rate the color, composition, etc separately per image. More info on that here).

    The 0 is used for the default (or ‘overall’) voting type that is used by the free version.

    The canVoteImage() function checks all the right settings to see if the user can vote, based on the image id passed. You don’t have to worry about figuring out the IP etc.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘A way to check if a user can vote from external php file’ is closed to new replies.