Skip to content

Instantly share code, notes, and snippets.

@Alimir
Last active November 1, 2021 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alimir/27dbd2cdd4721a77fd8c8e7e12fee0a3 to your computer and use it in GitHub Desktop.
Save Alimir/27dbd2cdd4721a77fd8c8e7e12fee0a3 to your computer and use it in GitHub Desktop.
Sample voting template with inline SVG icon (only for pro version)
<style>
.wpulike-custom-pro-template .wp_ulike_btn {
background: none;
padding: 0;
width: auto;
height: auto;
}
.wpulike-custom-pro-template .wp_ulike_btn:hover, .wpulike-custom-pro-template .wp_ulike_btn:focus {
color: black;
background-color: transparent;
text-decoration: none;
}
.wpulike-custom-pro-template .count-box {
padding: 0 12px;
font-size: 17px;
line-height: normal;
}
.wpulike-custom-pro-template .wp_ulike_put_image .wp-ulike-svg-icon {
display: block;
width: 20px;
height: 20px;
}
.wpulike-custom-pro-template .wp_ulike_put_image svg {
width: 100%;
height: 100%;
fill: #767676;
opacity: 0.7;
}
.wpulike-custom-pro-template .wp_ulike_put_image:after {
content: '';
}
.wpulike-custom-pro-template .wp_ulike_put_image.wp_ulike_btn_is_active svg {
fill: #ff6162;
}
.wpulike-custom-pro-template .wpulike_down_vote .wp_ulike_put_image.wp_ulike_btn_is_active svg {
fill: #3b354d;
}
</style>
<?php
/**
* Register custom template
*
* @param array $templates
* @return array
*/
function wp_ulike_voting_register_templates( $templates ){
$templates['wpulike-pro-custom-template'] = array(
'name' => __('WP ULike PRO Template', WP_ULIKE_PRO_DOMAIN),
'callback' => 'wp_ulike_pro_custom_template_content',
'symbol' => WP_ULIKE_ASSETS_URL . '/img/svg/default.svg',
'is_percentage_support' => true,
'is_text_support' => false
);
return $templates;
}
add_filter( 'wp_ulike_add_templates_list', 'wp_ulike_voting_register_templates', 20, 1 );
/**
* Custom template content
*
* @param array $wp_ulike_template
* @return string
*/
function wp_ulike_pro_custom_template_content( array $wp_ulike_template ){
//This function will turn output buffering on
ob_start();
do_action( 'wp_ulike_before_template', $wp_ulike_template );
// Extract input array
extract( $wp_ulike_template );
?>
<div class="wpulike wpulike-custom-pro-template <?php echo $wrapper_class; ?>" <?php echo $attributes; ?>>
<div class="<?php echo $pro_general_class['up']; ?>">
<button type="button"
aria-label="<?php echo wp_ulike_get_option( 'like_button_aria_label', __( 'Like Button',WP_ULIKE_PRO_DOMAIN) ) ?>"
data-ulike-id="<?php echo $ID; ?>" data-ulike-factor="up"
data-ulike-nonce="<?php echo wp_create_nonce( $type . $ID ); ?>" data-ulike-type="<?php echo $type; ?>"
data-ulike-template="<?php echo $style; ?>" data-ulike-display-likers="<?php echo $display_likers; ?>"
data-ulike-likers-style="<?php echo $likers_style; ?>" class="<?php echo $pro_button_class['up']; ?>">
<span class="wp-ulike-svg-icon">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24.144 24.144">
<path class="a"
d="M20.072,8A12.072,12.072,0,1,0,32.144,20.072,12.082,12.082,0,0,0,20.072,8ZM13.03,17.054a2.012,2.012,0,1,1,2.013,2.012A2.018,2.018,0,0,1,13.03,17.054ZM25.814,26.03a8.12,8.12,0,0,1-11.484,0,1.006,1.006,0,1,1,1.423-1.423,6.108,6.108,0,0,0,8.638,0,1.007,1.007,0,0,1,1.423,1.425ZM25.1,19.066a2.012,2.012,0,1,1,2.012-2.012A2.018,2.018,0,0,1,25.1,19.066Z"
transform="translate(-8 -8)" />
</svg>
</span>
</button>
<?php
echo $display_counters ? sprintf( '<span class="count-box wp_ulike_counter_up" data-ulike-counter-value="%s"></span>', esc_attr( $formatted_total_likes ) ) : '';
do_action( 'wp_ulike_after_up_vote_button', $wp_ulike_template );
?>
</div>
<div class="<?php echo $pro_general_class['down']; ?>">
<button type="button"
aria-label="<?php echo wp_ulike_get_option( 'dislike_button_aria_label', __( 'Dislike Button',WP_ULIKE_PRO_DOMAIN) ) ?>"
data-ulike-id="<?php echo $ID; ?>" data-ulike-factor="down"
data-ulike-nonce="<?php echo wp_create_nonce( $type . $ID ); ?>" data-ulike-type="<?php echo $type; ?>"
data-ulike-template="<?php echo $style; ?>" data-ulike-display-likers="<?php echo $display_likers; ?>"
data-ulike-likers-style="<?php echo $likers_style; ?>" class="<?php echo $pro_button_class['down']; ?>">
<span class="wp-ulike-svg-icon">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24.144 24.144">
<path class="a"
d="M20.072,8A12.072,12.072,0,1,0,32.144,20.072,12.082,12.082,0,0,0,20.072,8ZM13.03,16.552a.755.755,0,0,1,1.509,0,1.007,1.007,0,1,0,2.013,0,.755.755,0,0,1,1.509,0,2.516,2.516,0,1,1-5.031,0ZM25.868,27.668a1.005,1.005,0,0,1-1.421,0,6.191,6.191,0,0,0-8.746,0,1.006,1.006,0,0,1-1.423-1.423,8.2,8.2,0,0,1,11.591,0A1.007,1.007,0,0,1,25.868,27.668Zm-1.269-8.6a2.517,2.517,0,0,1-2.516-2.516.755.755,0,1,1,1.509,0,1.007,1.007,0,1,0,2.013,0,.755.755,0,1,1,1.509,0A2.516,2.516,0,0,1,24.6,19.066Z"
transform="translate(-8 -8)" />
</svg>
</span>
</button>
<?php
echo $display_counters ? sprintf( '<span class="count-box wp_ulike_counter_down" data-ulike-counter-value="%s"></span>', esc_attr( $formatted_total_dislikes ) ) : '';
do_action( 'wp_ulike_after_down_vote_button', $wp_ulike_template );
?>
</div>
<?php
do_action( 'wp_ulike_inside_template', $wp_ulike_template );
?>
</div>
<?php
do_action( 'wp_ulike_after_template', $wp_ulike_template );
return ob_get_clean(); // data is now in here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment