/** * Generate HTML for a single Like Button * * @param array $options like button options * @return string HTML div for use with the JavaScript SDK */ function facebook_get_like_button($options = array()) { if (!class_exists('Facebook_Like_Button')) { require_once dirname(__FILE__) . '/class-facebook-like-button.php'; } $like_button = Facebook_Like_Button::fromArray($options); if (!$like_button) { return ''; } $html = $like_button->asHTML(array('class' => array('fb-social-plugin'))); if ($html) { return "\n" . $html . "\n"; } return ''; }
/** * 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_Like_Button')) { require_once dirname(dirname(__FILE__)) . '/class-facebook-like-button.php'; } $like_button = Facebook_Like_Button::fromArray($new_instance); if ($like_button) { if (!class_exists('Facebook_Like_Button_Settings')) { require_once dirname(dirname(dirname(__FILE__))) . '/admin/settings-like-button.php'; } return array_merge($instance, Facebook_Like_Button_Settings::html_data_to_options($like_button->toHTMLDataArray())); } return $instance; }
/** * Sanitize Like Button settings before they are saved to the database * * @since 1.1 * @param array $options Like Button options * @return array clean option sets. note: we remove Like 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_like_button_builder(); // Handle like button display preferences first $clean_options = parent::sanitize_options($options); if (isset($clean_options['show_on'])) { self::update_display_conditionals('like', $clean_options['show_on'], self::get_show_on_choices('all')); unset($clean_options['show_on']); } unset($options['show_on']); $like_button = Facebook_Like_Button::fromArray($options); if ($like_button) { $like_button->validate(); return array_merge($clean_options, self::html_data_to_options($like_button->toHTMLDataArray())); } return $clean_options; }
/** * Sanitize widget form values as they are saved. * * @see WP_Widget::update() * * @since 1.0 * * @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(); $new_instance = (array) $new_instance; if (!empty($new_instance['title'])) { $instance['title'] = strip_tags($new_instance['title']); } foreach (array('share', 'show_faces') as $bool_option) { if (isset($new_instance[$bool_option])) { $new_instance[$bool_option] = true; } else { $new_instance[$bool_option] = false; } } if (!class_exists('Facebook_Like_Button')) { require_once dirname(dirname(__FILE__)) . '/class-facebook-like-button.php'; } $like_button = Facebook_Like_Button::fromArray($new_instance); if ($like_button) { if (!class_exists('Facebook_Like_Button_Settings')) { require_once dirname(dirname(dirname(__FILE__))) . '/admin/settings-like-button.php'; } return array_merge($instance, Facebook_Like_Button_Settings::html_data_to_options($like_button->toHTMLDataArray())); } return $instance; }
/** * Facebook Like Button after header * * @since 1.1 */ public static function after_header() { if (!class_exists('Facebook_Like_Button')) { require_once dirname(dirname(__FILE__)) . '/social-plugins/class-facebook-like-button.php'; } // promote Facebook for WordPress page on Facebook Developers site $like_button = new Facebook_Like_Button(false); $like_button->setURL('http://developers.facebook.com/wordpress/'); $like_button->setLayout('button_count'); $like_button->includeSendButton(); $like_button->setFont('arial'); $like_button->setReference('wp-admin'); echo $like_button->asHTML(); do_action('facebook_notify_plugin_conflicts'); }
/** * convert an options array into an object * * @since 1.1 * @param array $values associative array * @return Facebook_Like_Button like object */ public static function fromArray($values) { if (!is_array($values) || empty($values)) { return; } $like_button = new Facebook_Like_Button(); if (isset($values['href']) && is_string($values['href'])) { $like_button->setURL($values['href']); } if (isset($values['layout']) && is_string($values['layout'])) { $like_button->setLayout($values['layout']); } if (isset($values['show_faces']) && ($values['show_faces'] === true || $values['show_faces'] === 'true' || $values['show_faces'] == 1)) { $like_button->showFaces(); } if (isset($values['send']) && ($values['send'] === true || $values['send'] === 'true' || $values['send'] == 1)) { $like_button->includeSendButton(); } if (isset($values['width'])) { $like_button->setWidth(absint($values['width'])); } if (isset($values['action'])) { $like_button->setAction($values['action']); } if (isset($values['font'])) { $like_button->setFont($values['font']); } if (isset($values['colorscheme'])) { $like_button->setColorScheme($values['colorscheme']); } if (isset($values['ref'])) { $like_button->setReference($values['ref']); } return $like_button; }