Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+5 votes
377 views
in Q2A Core by

HI

I want to control the button to select the "best answer", so that it appears only if the number of letters or words is more than a certain number
 

function a_selection($post)
{
    $this->output('<div class="qa-a-selection f">');
    if (isset($post['select_tags'])) {
        $this->post_hover_button($post, 'select_tags', '', 'qa-a-select');
    } else if (isset($post['unselect_tags'])) {
        $this->post_hover_button($post, 'unselect_tags', '', 'qa-a-unselect');
    } else if ($post['selected']) {
        $this->output('<div class="qa-a-selected"> <span class="fa fa-check"></span> </div>');
    }
    if (isset($post['select_text'])) {
        $this->output('<div class="qa-a-selected-text"> Best answer' . @$post['select_text'] . '</div>');
    }
    $this->output('</div>');
}

1 Answer

+1 vote
by
selected by
 
Best answer

Just update the if statement for the 'select_tags' like this:

if (isset($post['select_tags'])) {
    require_once QA_INCLUDE_DIR . 'util/string.php';

    $text = qa_viewer_text($post['raw']['content'], $post['raw']['format']);
    $letterCount = qa_strlen($text);
    $wordCount = count(qa_string_to_words($text));
    if ($letterCount > 20 && $wordCount > 4) {
        $this->post_hover_button($post, 'select_tags', '', 'qa-a-select');
    }
}

Bare in mind:

  • You will need to update values 20 and 4 accordingly
  • This will not stop the POST request but rather just hide button
  • The concept of a "word" is the same as the one used by the Q2A search
...