/**
  * Front-end display of widget.
  *
  * @since 1.0
  *
  * @see WP_Widget::widget()
  *
  * @param array $args     Widget arguments.
  * @param array $instance Saved values from database.
  * @return void
  */
 public function widget($args, $instance)
 {
     // no follow target. fail early
     if (empty($instance['href'])) {
         return;
     }
     extract($args);
     if (!isset($instance['ref'])) {
         $instance['ref'] = 'widget';
     }
     if (!function_exists('facebook_get_follow_button')) {
         require_once dirname(dirname(__FILE__)) . '/social-plugins.php';
     }
     $follow_button_html = facebook_get_follow_button($instance);
     if (!(is_string($follow_button_html) && $follow_button_html)) {
         return;
     }
     echo $before_widget;
     $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     echo $follow_button_html;
     echo $after_widget;
 }
 /**
  * Generate a HTML div element with data-* attributes to be converted into a Follow Button by the Facebook JavaScript SDK
  * The passed href URL value must be a Facebook User profile URL; this URL is not validated before attempting to use in a Follow Button parameter
  *
  * @since 1.5
  *
  * @param array $attributes shortcode attributes. overrides site options for specific button attributes
  * @param string $content shortcode content. no effect
  * @return string Follow Button div HTML or empty string if minimum requirements not met
  */
 public static function follow_button($attributes, $content = null)
 {
     $site_options = get_option('facebook_follow_button');
     if (!is_array($site_options)) {
         $site_options = array();
     }
     $options = shortcode_atts(array('href' => '', 'layout' => isset($site_options['layout']) ? $site_options['layout'] : '', 'show_faces' => isset($site_options['show_faces']) && $site_options['show_faces'], 'width' => isset($site_options['width']) ? $site_options['width'] : 0, 'font' => isset($site_options['font']) ? $site_options['font'] : '', 'colorscheme' => isset($site_options['colorscheme']) ? $site_options['colorscheme'] : '', 'ref' => 'shortcode'), $attributes, 'facebook_follow_button');
     // Facebook User profile URL required as the target of the follow
     if (is_string($options['href']) && $options['href']) {
         $options['href'] = esc_url_raw(trim($options['href']), array('http', 'https'));
     } else {
         return '';
     }
     $options['show_faces'] = (bool) $options['show_faces'];
     $options['width'] = absint($options['width']);
     if (!$options['width']) {
         unset($options['width']);
     }
     foreach (array('layout', 'font', 'colorscheme') as $key) {
         $options[$key] = trim($options[$key]);
         if (!$options[$key]) {
             unset($options[$key]);
         }
     }
     if (!function_exists('facebook_get_follow_button')) {
         require_once dirname(__FILE__) . '/social-plugins.php';
     }
     return facebook_get_follow_button($options);
 }
Beispiel #3
0
/**
 * Add Follow Button(s) to post content
 *
 * Adds a follow button above the post, below the post, or both above and below the post depending on stored preferences.
 *
 * @since 1.1
 *
 * @param string $content existing content
 * @return string passed content with Follow Button markup prepended, appended, or both.
 */
function facebook_the_content_follow_button($content)
{
    // Follow Button should not be the only content
    if (!$content) {
        return $content;
    }
    $options = get_option('facebook_follow_button');
    if (!is_array($options)) {
        $options = array();
    }
    if (!class_exists('Facebook_User')) {
        require_once dirname(dirname(__FILE__)) . '/facebook-user.php';
    }
    $facebook_user = Facebook_User::get_user_meta(get_the_author_meta('ID'), 'fb_data', true);
    if (!($facebook_user && isset($facebook_user['fb_uid']))) {
        return $content;
    }
    $options['href'] = Facebook_User::facebook_profile_link($facebook_user);
    if (!$options['href']) {
        return $content;
    }
    if ($options['position'] === 'top') {
        $options['ref'] = 'above-post';
        return facebook_get_follow_button($options) . $content;
    } else {
        if ($options['position'] === 'bottom') {
            $options['ref'] = 'below-post';
            return $content . facebook_get_follow_button($options);
        } else {
            if ($options['position'] === 'both') {
                $options['ref'] = 'above-post';
                $above = facebook_get_follow_button($options);
                $options['ref'] = 'below-post';
                return $above . $content . facebook_get_follow_button($options);
            }
        }
    }
    // don't break the filter
    return $content;
}
Beispiel #4
0
/**
 * Add Follow Button(s) to post content
 * Adds a follow button above the post, below the post, or both above and below the post depending on stored preferences.
 *
 * @since 1.1
 * @param string $content existing content
 * @return string passed content with Follow Button markup prepended, appended, or both.
 */
function facebook_the_content_follow_button($content)
{
    global $post;
    // Send Button should not be the only content
    if (!$content) {
        return $content;
    }
    $options = get_option('facebook_follow_button');
    if (!is_array($options)) {
        $options = array();
    }
    if (!class_exists('Facebook_User')) {
        require_once dirname(dirname(__FILE__)) . '/facebook-user.php';
    }
    $facebook_user = Facebook_User::get_user_meta(get_the_author_meta('ID'), 'fb_data', true);
    if (!($facebook_user && isset($facebook_user['fb_uid']))) {
        return $content;
    }
    if (isset($facebook_user['username'])) {
        $options['href'] = 'https://www.facebook.com/' . $facebook_user['username'];
    } else {
        $options['href'] = 'https://www.facebook.com/profile.php?' . http_build_query(array('id' => $facebook_user['fb_uid']));
    }
    if ($options['position'] === 'top') {
        $options['ref'] = 'above-post';
        return facebook_get_follow_button($options) . $content;
    } else {
        if ($options['position'] === 'bottom') {
            $options['ref'] = 'below-post';
            return $content . facebook_get_follow_button($options);
        } else {
            if ($options['position'] === 'both') {
                $options['ref'] = 'above-post';
                $above = facebook_get_follow_button($options);
                $options['ref'] = 'below-post';
                return $above . $content . facebook_get_follow_button($options);
            }
        }
    }
    // don't break the filter
    return $content;
}