/**
  * 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_Subscribe_Button')) {
         require_once dirname(dirname(__FILE__)) . '/class-facebook-subscribe-button.php';
     }
     $subscribe_button = Facebook_Subscribe_Button::fromArray($new_instance);
     if ($subscribe_button) {
         if (!class_exists('Facebook_Subscribe_Button_Settings')) {
             require_once dirname(dirname(dirname(__FILE__))) . '/admin/settings-subscribe-button.php';
         }
         return array_merge($instance, Facebook_Subscribe_Button_Settings::html_data_to_options($subscribe_button->toHTMLDataArray()));
     }
     return $instance;
 }
 /**
  * Sanitize Subscribe Button settings before they are saved to the database
  *
  * @since 1.1
  * @param array $options Subscribe Button options
  * @return array clean option sets. note: we remove Subscribe 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();
     }
     $clean_options = array();
     self::require_subscribe_button_builder();
     // Handle display preferences first
     $clean_options = parent::sanitize_options($options);
     if (isset($clean_options['show_on'])) {
         self::update_display_conditionals('subscribe', $clean_options['show_on'], self::get_show_on_choices('all'));
         unset($clean_options['show_on']);
     }
     unset($options['show_on']);
     // href required for subscribe 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';
     $subscribe_button = Facebook_Subscribe_Button::fromArray($options);
     if ($subscribe_button) {
         $subscribe_button_options = self::html_data_to_options($subscribe_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($subscribe_button_options['href']);
         return array_merge($clean_options, $subscribe_button_options);
     }
     return $clean_options;
 }
Beispiel #3
0
/**
 * Generate HTML for a subscribe button based on passed options
 *
 * @since 1.1
 * @param array $options customizations
 * @return string subscribe button HTML for use with the JavaScript SDK
 */
function facebook_get_subscribe_button($options = array())
{
    // need a subscription target
    if (!is_array($options) || empty($options['href'])) {
        return '';
    }
    if (!class_exists('Facebook_Subscribe_Button')) {
        require_once dirname(__FILE__) . '/class-facebook-subscribe-button.php';
    }
    $subscribe_button = Facebook_Subscribe_Button::fromArray($options);
    if (!$subscribe_button) {
        return '';
    }
    $html = $subscribe_button->asHTML(array('class' => array('fb-social-plugin')));
    if (is_string($html) && $html) {
        return "\n" . $html . "\n";
    }
    return '';
}
 /**
  * convert an options array into an object
  *
  * @since 1.1
  * @param array $values associative array
  * @return Facebook_Subscribe_Button subscribe object
  */
 public static function fromArray($values)
 {
     if (!is_array($values) || empty($values)) {
         return;
     }
     $subscribe_button = new Facebook_Subscribe_Button();
     if (isset($values['href'])) {
         $subscribe_button->setURL($values['href']);
     }
     if (isset($values['layout'])) {
         $subscribe_button->setLayout($values['layout']);
     }
     if (isset($values['show_faces']) && ($values['show_faces'] === true || $values['show_faces'] === 'true' || $values['show_faces'] == 1)) {
         $subscribe_button->showFaces();
     }
     if (isset($values['width'])) {
         $subscribe_button->setWidth(absint($values['width']));
     }
     if (isset($values['font'])) {
         $subscribe_button->setFont($values['font']);
     }
     if (isset($values['colorscheme'])) {
         $subscribe_button->setColorScheme($values['colorscheme']);
     }
     return $subscribe_button;
 }