/**
  * Sanitize widget form values as they are saved.
  *
  * @see WP_Widget::update()
  *
  * @param array $new_instance Values just sent to be saved.
  * @param array $old_instance Previously saved values from database.
  *
  * @return array Updated safe values to be saved.
  */
 public function update($new_instance, $old_instance)
 {
     $instance = array();
     if (!empty($new_instance['title'])) {
         $instance['title'] = strip_tags($new_instance['title']);
     }
     if (!class_exists('Facebook_Follow_Button')) {
         require_once dirname(dirname(__FILE__)) . '/class-facebook-follow-button.php';
     }
     $follow_button = Facebook_Follow_Button::fromArray($new_instance);
     if ($follow_button) {
         if (!class_exists('Facebook_Follow_Button_Settings')) {
             require_once dirname(dirname(dirname(__FILE__))) . '/admin/settings-follow-button.php';
         }
         return array_merge($instance, Facebook_Follow_Button_Settings::html_data_to_options($follow_button->toHTMLDataArray()));
     }
     return $instance;
 }
 /**
  * Sanitize Follow Button settings before they are saved to the database.
  *
  * @since 1.1
  *
  * @param array $options Follow Button options
  * @return array clean option sets. note: we remove Follow Button social plugin default options, storing only custom settings (e.g. dark color scheme stored, light is default and therefore not stored)
  */
 public static function sanitize_options($options)
 {
     if (!is_array($options) || empty($options)) {
         return array();
     }
     self::require_follow_button_builder();
     // Handle display preferences first
     $clean_options = parent::sanitize_options($options);
     if (isset($clean_options['show_on'])) {
         self::update_display_conditionals('follow', $clean_options['show_on'], self::get_show_on_choices());
         unset($clean_options['show_on']);
     }
     unset($options['show_on']);
     if (isset($options['show_faces'])) {
         $options['show_faces'] = true;
     } else {
         $options['show_faces'] = false;
     }
     if (isset($options['width'])) {
         $options['width'] = absint($options['width']);
     }
     // href required for follow button
     // set href contextual to the post author, not at settings
     // fake it here to pass sanitization, then remove before save
     $options['href'] = 'https://www.facebook.com/zuck';
     $follow_button = Facebook_Follow_Button::fromArray($options);
     if ($follow_button) {
         $follow_button_options = self::html_data_to_options($follow_button->toHTMLDataArray());
         // remove the dummy value set above
         // remove here instead of html_data_to_options to separate widget usage with its real href
         unset($follow_button_options['href']);
         return array_merge($clean_options, $follow_button_options);
     }
     return $clean_options;
 }
 /**
  * convert an options array into an object.
  *
  * @since 1.1
  *
  * @param array $values associative array
  * @return Facebook_Follow_Button follow object
  */
 public static function fromArray($values)
 {
     if (!is_array($values) || empty($values)) {
         return;
     }
     $follow_button = new Facebook_Follow_Button();
     if (isset($values['href'])) {
         $follow_button->setURL($values['href']);
     }
     if (isset($values['layout'])) {
         $follow_button->setLayout($values['layout']);
     }
     if (isset($values['show_faces']) && ($values['show_faces'] === true || $values['show_faces'] === 'true' || $values['show_faces'] == 1)) {
         $follow_button->showFaces();
     }
     if (isset($values['width'])) {
         $follow_button->setWidth(absint($values['width']));
     }
     if (isset($values['font'])) {
         $follow_button->setFont($values['font']);
     }
     if (isset($values['colorscheme'])) {
         $follow_button->setColorScheme($values['colorscheme']);
     }
     if (isset($values['kid_directed_site']) && ($values['kid_directed_site'] === true || $values['kid_directed_site'] === 'true' || $values['kid_directed_site'] == 1)) {
         $follow_button->isKidDirectedSite();
     }
     return $follow_button;
 }
Example #4
0
/**
 * Generate HTML for a follow button based on passed options.
 *
 * @since 1.1
 *
 * @param array $options customizations
 * @return string follow button HTML for use with the Facebook SDK for JavaScript
 */
function facebook_get_follow_button($options = array())
{
    // need a subscription target
    if (!is_array($options) || empty($options['href'])) {
        return '';
    }
    if (!class_exists('Facebook_Follow_Button')) {
        require_once dirname(__FILE__) . '/class-facebook-follow-button.php';
    }
    $follow_button = Facebook_Follow_Button::fromArray($options);
    if (!$follow_button) {
        return '';
    }
    $html = $follow_button->asHTML(array('class' => array('fb-social-plugin')));
    if (is_string($html) && $html) {
        return "\n" . $html . "\n";
    }
    return '';
}