Override vote icons in 4.1.4

Solved8.21K viewsCoreicons mods voting
0

Hi – is there any function that can override the voting icons ? I copied /includes/votes.php to /mytheme/anspress/includes/votes.php to make changes, but this doesn’t seem to work.

Any pointers ?

 

Thanks

Question is closed for new answers.
selected answer
1

Right – none of the functions or hooks here worked for me – they all generated an error, so I decided to change the CSS instead. For anyone else looking to change the voting icons, add this to your CSS

.apicon-thumb-up:before {
content: “\f102”;
font-family: “FontAwesome” !important;
}
.apicon-thumb-down:before {
content: “\f103”;
font-family: “FontAwesome” !important;
}

Use this guide to determine which code value you need

selected as best answer
0

@rahul – the last snippet you supplied results in the below error

The code snippet you are trying to save produced a fatal error on line 1:

syntax error, unexpected ”ap_vote_btn_html” (T_CONSTANT_ENCAPSED_STRING), expecting variable (T_VARIABLE)

0

Like a piece of cake,

https://gist.github.com/rahularyan/0f0e08214e008dd9c76827adf15593e6

Make sure to update to 4.1.5 first.

commented on answer

Hmm. Updated to 4.1.5 and used below snippet
function ap_ap_vote_btn_html( ‘ap_vote_btn_html’, $html, $post ) {
$html = str_replace( ‘apicon-thumb-up’, ‘fa fa-angle-double-up’, $html );

// $html = str_replace( ‘apicon-thumb-down’, ‘fa fa-angle-double-up’, $html );

return $html;
}
add_filter( ‘ap_vote_btn_html’, ‘ap_ap_vote_btn_html’, 10, 2 );

But this doesn’t seem to work. I updated to 4.1.5 yesterday – was this added since then ?

Hello Mark, This is a tested code. If you put it in theme function it will work.

0

@Rahul – what I am looking to achieve is the below

This function, from votes.php – see the bold and italic text.

function ap_vote_btn( $post = null, $echo = true ) {
$post = ap_get_post( $post );
if ( ! $post || ‘answer’ === $post->post_type && ap_opt( ‘disable_voting_on_answer’ ) ) {
return;
}

if ( ‘question’ === $post->post_type && ap_opt( ‘disable_voting_on_question’ ) ) {
return;
}

$vote = is_user_logged_in() ? ap_get_vote( $post->ID, get_current_user_id(), ‘vote’ ) : false;
$voted = $vote ? true : false;

if ( $vote && ‘1’ === $vote->vote_value ) {
$type = ‘vote_up’;
} elseif ( $vote && ‘-1’ === $vote->vote_value ) {
$type = ‘vote_down’;
} else {
$type = ”;
}

$data = [ ‘post_id’ => $post->ID, ‘active’ => $type, ‘net’ => ap_get_votes_net(), ‘__nonce’ => wp_create_nonce( ‘vote_’ . $post->ID ) ];

$html = ”;
$html .= ‘<div id=”vote_’ . $post->ID . ‘” class=”ap-vote net-vote” ap-vote=” . wp_json_encode( $data ) . ”>’;
$html .= ‘<a class=”fa fa-angle-double-up ap-tip vote-up‘ . ($voted ? ‘ voted’ : ”) . ($vote && ‘vote_down’ === $type ? ‘ disable’ : ”) . ‘” href=”#” title=”‘ . __( ‘Up vote this post’, ‘anspress-question-answer’ ) . ‘” ap=”vote_up”></a>’;

$html .= ‘<span class=”net-vote-count” data-view=”ap-net-vote” itemprop=”upvoteCount” ap=”votes_net”>’ . ap_get_votes_net() . ‘</span>’;

if ( (‘question’ === $post->post_type && ! ap_opt( ‘disable_down_vote_on_question’ )) ||
(‘answer’ === $post->post_type && ! ap_opt( ‘disable_down_vote_on_answer’ )) ) {
$html .= ‘<a data-tipposition=”bottom center” class=”apicon-thumb-down ap-tip vote-down’ . ($voted ? ‘ voted’ : ”) . ($vote && ‘vote_up’ === $type ? ‘ disable’ : ”) . ‘” href=”#” title=”‘ . __( ‘Down vote this post’, ‘anspress-question-answer’ ) . ‘” ap=”vote_down”></a>’;
}

$html .= ‘</div>’;

if ( ! $echo ) {
return $html;
}

echo $html; // xss okay.
}

What I am looking for is a function that will override this.

0

Thanks Rahul. Just had a look through the commit and can’t seem to locate the change. Can you provide an example of how this add_filter function will work in terms of syntax ?

Thanks

commented on answer

Thanks Rahul, but that just references the file I changed manually. My changes would then be overwritten on upgrade, no ?

Yes of course it will be overridden. Tell me clearly what you are trying to achieve.

0

Hello Mark,

just added a new hook ap_vote_btn_html. Kindly check GitHUb.