Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Very simple module to have a user vote for content automatically as they create it. Have called this module autovote (autovote.module
).
NB: D6 version here.
1. Create a directory under modules
named autovote
.
2. Put the following in autovote.module
:
<?php
/**
* Implementation of hook_nodeapi()
*
* Vote on the node as it's saved.
*/
function autovote_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
/* Only vote on database inserts */
if ($op != 'insert') return;
/* Stop anonymous votes - don't if not logged in. */
global $user;
if (!$user->uid) return;
/* Don't vote if not new */
if (!$node->is_new) return;
/* Optionally filter content types - modify as you wish. */
/* Eg. don't vote for anything but images. */
if ($node->type != 'image') return;
/* OK - let's vote */
votingapi_set_vote('node', $node->nid, 100, $user->uid);
}
?>
3. Put the following in autovote.info
:
name = Autovote
description = "Have a user automatically vote for content as they create it."
package = Voting
version = "5.x-0.1"
4. Visit modules admin page and enable the new module.