Created
June 12, 2021 15:33
-
-
Save Alimir/73a3b1375215f840825761b9fff5fbcd to your computer and use it in GitHub Desktop.
How to add custom template in wp ulike
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Register custom template | |
* | |
* @param array $templates | |
* @return array | |
*/ | |
function wp_ulike_voting_register_templates( $templates ){ | |
$templates['wpulike-custom-template'] = array( | |
'name' => __('Custom Template', WP_ULIKE_PRO_DOMAIN), | |
'callback' => 'wp_ulike_custom_template_content', | |
'symbol' => WP_ULIKE_ASSETS_URL . '/img/svg/default.svg', | |
'is_text_support' => true | |
); | |
return $templates; | |
} | |
add_filter( 'wp_ulike_add_templates_list', 'wp_ulike_voting_register_templates', 10, 1 ); | |
/** | |
* Custom template content | |
* | |
* @param array $wp_ulike_template | |
* @return string | |
*/ | |
function wp_ulike_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-template <?php echo $wrapper_class; ?>" <?php echo $attributes; ?>> | |
<div class="<?php echo $general_class; ?>"> | |
<button type="button" | |
aria-label="<?php echo wp_ulike_get_option( 'like_button_aria_label', __( 'Like Button',WP_ULIKE_SLUG) ) ?>" | |
data-ulike-id="<?php echo $ID; ?>" | |
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 $button_class; ?>"> | |
<?php | |
echo $up_vote_inner_text; | |
do_action( 'wp_ulike_inside_like_button', $wp_ulike_template ); | |
if($button_type == 'text'){ | |
echo '<span>' . $button_text . '</span>'; | |
} | |
?> | |
</button> | |
</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