Advertisement
Guest User

Untitled

a guest
Sep 27th, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.41 KB | None | 0 0
  1. <?php
  2.  
  3. function wabtn_style() {
  4.     $plugins_url = plugins_url();
  5.     wp_enqueue_style( 'wabtn-style', $plugins_url.'/whatsapp/style.css' );
  6. }
  7.  
  8. add_action( 'wp_enqueue_scripts', 'wabtn_style' );
  9.  
  10. //AUTO BUTTON INSERTION
  11. function wa_btn($content) {
  12.     $options = get_option('wa_btn');
  13.     if (!isset($options['top'])) {$options['top'] = "off";}
  14.     if (!isset($options['btm'])) {$options['btm'] = "off";}
  15.     if (!isset($options['posts'])) {$options['posts'] = "off";}
  16.     if (!isset($options['pages'])) {$options['pages'] = "off";}
  17.     if (!isset($options['homepage'])) {$options['homepage'] = "off";}
  18.     if (!isset($options['tracking'])) {$tracking = "";} else {$tracking='?utm_source=WhatsApp%26utm_medium=IM%26amp;utm_campaign=share%20button';}
  19.     $btn='';
  20.     if (
  21.        (is_single() && $options['posts'] == 'on') ||
  22.        (is_page() && $options['pages'] == 'on') ||
  23.        ((is_home() || is_front_page()) && $options['homepage'] == 'on')) {
  24.         $btn = '<!-- WhatsApp Share Button for WordPress: http://peadig.com/wordpress-plugins/whatsapp-share-button/ --><div class="wabtn_container"><a href="whatsapp://send?text='.get_the_title().' - '.get_permalink().$tracking.'" class="wabtn">Share this on WhatsApp</a></div>';
  25.         if ($options['top'] == 'on' && $options['btm'] == 'on') {$output = $btn.$content.$btn;}
  26.         elseif ($options['top'] == 'on' && $options['btm'] != 'on') {$btn .= $content; $output = $btn;}
  27.         elseif ($options['top'] != 'on' && $options['btm'] == 'on') {$output = $content.$btn;}
  28.         else {$output = $content;}
  29.     } else {$output = $content;}
  30.     return $output;
  31. }
  32. add_filter ('the_content', 'wa_btn', 100);
  33.  
  34.  
  35. function wa_btn_shortcode($waatts) {
  36.     extract(shortcode_atts(array(
  37.         "waatts" => get_option('wa_btn'),
  38.         "title" => get_the_title(),
  39.         "url" => get_permalink(),
  40.     ), $waatts));
  41.     if (!empty($waatts)) {
  42.         foreach ($waatts as $key => $option)
  43.             $waatts[$key] = $option;
  44.     }
  45.     if (!isset($waatts['tracking'])) {$tracking = "";} else {$tracking='?utm_source=WhatsApp%26utm_medium=IM%26amp;utm_campaign=share%20button';}
  46.     $btn = '<!-- WhatsApp Share Button for WordPress: http://peadig.com/wordpress-plugins/whatsapp-share-button/ --><div class="wabtn_container"><a href="whatsapp://send?text='.$title.' - '.$url.$tracking.'" class="wabtn">Compartilhe no WhatsApp</a></div>';
  47.     return $btn;
  48. }
  49. add_filter('widget_text', 'do_shortcode');
  50. add_shortcode('whatsapp', 'wa_btn_shortcode');
  51.  
  52.  
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement