I'm trying to display the flag link only for the node author, and I'm using the following code:
global $user;
if ($node->uid == $user->uid) {
//print your flag
}
The link doesn't appear.
Do you have any idea on what is causing this?
I'm trying to display the flag link only for the node author, and I'm using the following code:
global $user;
if ($node->uid == $user->uid) {
//print your flag
}
The link doesn't appear.
Do you have any idea on what is causing this?
You may use hook_flag_access(), as in the following code.
function crystal_qa_flag_access($flag, $entity_id, $action, $account) {
// Only the author of the question has right to use flag "Accepeted" on answers.
if (($flag->name == 'accepted') && ($flag->content_type == 'node') && ($node = node_load($entity_id))) {
if ($node->type=='answer') {
// The content type machine name must be answer.
$question_nid = $node->field_answer['und']['0']['target_id'];
$question = node_load($question_nid);
return ($question->uid == $account->uid);
}
}
}
Perhaps by declaring $user
to be a blank variable right before you use it, you're overwriting Drupal's variable?
global $user
.