/** * 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_Activity_Feed')) { require_once dirname(dirname(__FILE__)) . '/class-facebook-activity-feed.php'; } $activity_feed = Facebook_Activity_Feed::fromArray($new_instance); if ($activity_feed) { $activity_feed_options = $activity_feed->toHTMLDataArray(); if (isset($activity_feed_options['header'])) { if ($activity_feed_options['header'] === 'false') { $activity_feed_options['header'] = false; } else { $activity_feed_options['header'] = true; } } if (isset($activity_feed_options['border-color'])) { $activity_feed_options['border_color'] = $activity_feed_options['border-color']; unset($activity_feed_options['border-color']); } if (isset($activity_feed_options['max-age'])) { $activity_feed_options['max_age'] = absint($activity_feed_options['max-age']); unset($activity_feed_options['max-age']); } foreach (array('width', 'height') as $option) { $activity_feed_options[$option] = absint($activity_feed_options[$option]); } if (isset($activity_feed_options['recommendations'])) { if ($activity_feed_options['recommendations'] === 'false') { $activity_feed_options['recommendations'] = false; } else { $activity_feed_options['recommendations'] = true; } } return array_merge($instance, $activity_feed_options); } return $instance; }
/** * convert an options array into an object. * * @since 1.1 * * @param array $values associative array * @return Facebook_Activity_Feed activity feed object */ public static function fromArray($values) { if (!is_array($values) || empty($values)) { return; } $feed = new Facebook_Activity_Feed(); if (isset($values['site'])) { $feed->setSite($values['site']); } if (isset($values['action'])) { if (is_string($values['action'])) { $feed->addAction($values['action']); } else { if (is_array($values['action'])) { foreach ($values['action'] as $action) { $feed->addAction($action); } } } } if (isset($values['app_id'])) { $feed->setAppID($values['app_id']); } if (isset($values['width'])) { $feed->setWidth(absint($values['width'])); } if (isset($values['height'])) { $feed->setHeight(absint($values['height'])); } if (isset($values['header']) && ($values['header'] === true || $values['header'] === 'true' || $values['header'] == 1)) { $feed->showHeader(); } else { $feed->hideHeader(); } if (isset($values['recommendations']) && ($values['recommendations'] === true || $values['recommendations'] === 'true' || $values['recommendations'] == 1)) { $feed->includeRecommendations(); } if (isset($values['filter'])) { $feed->setFilter($values['filter']); } if (isset($values['linktarget'])) { $feed->setLinkTarget($values['linktarget']); } if (isset($values['max_age'])) { $feed->setMaxAge(absint($values['max_age'])); } if (isset($values['font'])) { $feed->setFont($values['font']); } if (isset($values['colorscheme'])) { $feed->setColorScheme($values['colorscheme']); } if (isset($values['ref'])) { $feed->setReference($values['ref']); } return $feed; }
/** * Sanitize widget form values as they are saved. * * @since 1.0 * * @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(); $new_instance = (array) $new_instance; if (!empty($new_instance['title'])) { $instance['title'] = strip_tags($new_instance['title']); } // checkboxes foreach (array('header', 'recommendations') as $bool_option) { if (isset($new_instance[$bool_option])) { $new_instance[$bool_option] = true; } else { $new_instance[$bool_option] = false; } } // unsigned ints foreach (array('width', 'height', 'max_age') as $option) { if (isset($new_instance[$option])) { $new_instance[$option] = absint($new_instance[$option]); } } if (!class_exists('Facebook_Activity_Feed')) { require_once dirname(dirname(__FILE__)) . '/class-facebook-activity-feed.php'; } $activity_feed = Facebook_Activity_Feed::fromArray($new_instance); if ($activity_feed) { $activity_feed_options = $activity_feed->toHTMLDataArray(); // int with dash if (isset($activity_feed_options['max-age'])) { $activity_feed_options['max_age'] = absint($activity_feed_options['max-age']); unset($activity_feed_options['max-age']); } // bools foreach (array('header', 'recommendations') as $bool_option) { if (!isset($activity_feed_options[$bool_option])) { continue; } if ($activity_feed_options[$bool_option] === 'true') { $activity_feed_options[$bool_option] = true; } else { if ($activity_feed_options[$bool_option] === 'false') { $activity_feed_options[$bool_option] = false; } } } foreach (array('width', 'height') as $option) { if (isset($activity_feed_options[$option])) { $activity_feed_options[$option] = absint($activity_feed_options[$option]); } } return array_merge($instance, $activity_feed_options); } return $instance; }