/**
  * Test if a provided string is a URL to a Facebook page
  * Sanitize the URL if valid
  *
  * @since 1.1.11
  * @param string $url absolute URL
  * @return string 
  */
 public static function sanitize_facebook_page_url($url)
 {
     global $wpdb, $facebook_loader;
     if (!is_string($url) || !$url) {
         return '';
     }
     // check for basic URL validity
     $url = esc_url_raw($url, array('http', 'https'));
     if (!$url) {
         return '';
     }
     // is the provided URL a Facebook URL?
     try {
         $url_parts = parse_url($url);
     } catch (Exception $e) {
         return '';
     }
     // does the provided string look like a Facebook URL?
     if (!(is_array($url_parts) && isset($url_parts['host']) && $url_parts['host'] === 'www.facebook.com' && !empty($url_parts['path']))) {
         return '';
     }
     // reject a Like Box URL pointing to the Facebook homepage
     $url_parts['path'] = ltrim($url_parts['path'], '\\/');
     if (!$url_parts['path']) {
         return '';
     }
     // attempt to normalize the URL through a Facebook request if an access token is present
     if (isset($facebook_loader) && $facebook_loader->app_access_token_exists()) {
         if (!class_exists('Facebook_WP_Extend')) {
             require_once $facebook_loader->plugin_directory . 'includes/facebook-php-sdk/class-facebook-wp.php';
         }
         // page without a username
         if (strlen($url_parts['path']) > 7 && substr_compare($url_parts['path'], 'pages/', 0, 6) === 0) {
             $page_id = ltrim(substr($url_parts['path'], strrpos($url_parts['path'], '/')), '\\/');
             if (!(is_string($page_id) && $page_id && ctype_digit($page_id))) {
                 return '';
             }
             $where = $wpdb->prepare('page_id=%s', $page_id);
             unset($page_id);
         } else {
             // treat the link as a username
             $where = $wpdb->prepare('username=%s', $url_parts['path']);
         }
         $where .= ' AND is_published=1';
         try {
             $page_info = Facebook_WP_Extend::graph_api_with_app_access_token('/fql', 'GET', array('q' => 'SELECT page_url FROM page WHERE ' . $where));
         } catch (WP_FacebookApiException $e) {
             break;
         }
         unset($where);
         if (isset($page_info['data'][0]['page_url'])) {
             return $page_info['data'][0]['page_url'];
         }
         unset($page_info);
     }
     return 'https://www.facebook.com/' . $url_parts['path'];
 }
Example #2
0
 /**
  * Clean user inputs before saving to database
  *
  * @since 1.1
  * @param array $options form options values
  */
 public static function sanitize_options($options)
 {
     // start fresh
     $clean_options = array();
     if (isset($options['app_id'])) {
         // leading spaces is a common copy-paste mistake
         $app_id = trim($options['app_id']);
         if ($app_id) {
             // digit characters only
             // better to reject a known bad value than remove its bad characters & save bad value
             if (function_exists('ctype_digit')) {
                 // ctype might not always be present
                 if (ctype_digit($app_id)) {
                     $clean_options['app_id'] = $app_id;
                 }
             } else {
                 if (preg_match('/^[0-9]+$/', $app_id)) {
                     $clean_options['app_id'] = $app_id;
                 } else {
                     if (function_exists('add_settings_error')) {
                         add_settings_error('facebook-app-id', 'facebook-app-id-error', __('App ID must contain only digits.', 'facebook'));
                     }
                 }
             }
         } else {
             // removing app id disables other features such as comments
             delete_option('facebook_comments_enabled');
         }
         unset($app_id);
     }
     if (isset($options['app_secret'])) {
         $app_secret = strtolower(trim($options['app_secret']));
         if ($app_secret) {
             if (preg_match('/^[0-9a-f]+$/', $app_secret)) {
                 // hex
                 $clean_options['app_secret'] = $app_secret;
             } else {
                 if (function_exists('add_settings_error')) {
                     add_settings_error('facebook-app-secret', 'facebook-app-secret-error', __('Invalid app secret.', 'facebook'));
                 }
             }
         }
         unset($app_secret);
     }
     // store an application access token and verify additional data
     if (isset($clean_options['app_id']) && isset($clean_options['app_secret'])) {
         if (!class_exists('Facebook_WP_Extend')) {
             require_once dirname(dirname(__FILE__)) . '/includes/facebook-php-sdk/class-facebook-wp.php';
         }
         if (wp_http_supports(array('ssl' => true))) {
             $access_token = Facebook_WP_Extend::get_app_access_token($clean_options['app_id'], $clean_options['app_secret']);
             if ($access_token) {
                 $app_info = Facebook_WP_Extend::get_app_details_by_access_token($access_token, array('id', 'namespace'));
                 if (empty($app_info)) {
                     unset($clean_options['app_id']);
                     unset($clean_options['app_secret']);
                 } else {
                     if (isset($app_info['namespace'])) {
                         $clean_options['app_namespace'] = $app_info['namespace'];
                     }
                     $clean_options['access_token'] = $access_token;
                 }
                 unset($app_info);
             } else {
                 if (function_exists('add_settings_error')) {
                     add_settings_error('facebook-app-auth', 'facebook-app-auth-error', __('Application ID and secret failed on authentication with Facebook.', 'facebook'));
                 }
                 unset($clean_options['app_id']);
                 unset($clean_options['app_secret']);
             }
             unset($access_token);
         } else {
             $app_info = Facebook_WP_Extend::get_app_details($clean_options['app_id'], array('id', 'namespace'));
             if (empty($app_info)) {
                 unset($clean_options['app_id']);
                 unset($clean_options['app_secret']);
             } else {
                 if (isset($app_info['namespace'])) {
                     $clean_options['app_namespace'] = $app_info['namespace'];
                 }
             }
             unset($app_info);
         }
     } else {
         unset($clean_options['app_id']);
         unset($clean_options['app_secret']);
     }
     return $clean_options;
 }
 /**
  * Search for Facebook pages matching a given string up to maximum number of results
  *
  * @since 1.2
  *
  * @param string $search_term search string
  * @param int $limit maximum number of results
  * @return array {
  *     friend results
  *
  *     @type string 'object_type' page. Differentiate between Page and User objects in the same search results set
  *     @type string 'id' Facebook Page id.
  *     @type string 'name' Facebook Page name.
  *     @type string 'image' Facebook Page image URL
  *     @type int 'likes' Number of Likes received by the Page.
  *     @type int 'talking_about_count' Number of Facebook Users talking about the Page.
  *     @type string 'category' Page category.
  *     @type string 'location' Page location (if a physical place).
  * }
  */
 public static function search_pages($search_term, $limit = 4)
 {
     global $facebook_loader;
     $cache_key = 'facebook_12_pages_' . $search_term;
     $matched_pages = get_transient($cache_key);
     if ($matched_pages === false) {
         if (!class_exists('Facebook_WP_Extend')) {
             require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/includes/facebook-php-sdk/class-facebook-wp.php';
         }
         $params = array('type' => 'page', 'fields' => 'id,name,is_published,picture,category,location,likes,talking_about_count', 'limit' => $limit, 'q' => $search_term, 'ref' => 'fbwpp');
         if (isset($facebook_loader) && isset($facebook_loader->locale)) {
             $params['locale'] = $facebook_loader->locale;
         }
         try {
             $pages = Facebook_WP_Extend::graph_api_with_app_access_token('search', 'GET', $params);
         } catch (WP_FacebookApiException $e) {
             return array();
         }
         unset($params);
         if (!(isset($pages['data']) && is_array($pages['data']))) {
             return array();
         }
         $pages = $pages['data'];
         $matched_pages = array();
         $matched_count = 0;
         // cleanup the picture response
         foreach ($pages as $page) {
             if ($matched_count === $limit) {
                 break;
             }
             if (!(isset($page['id']) && isset($page['name']) && isset($page['is_published']))) {
                 continue;
             }
             if (!$page['is_published']) {
                 continue;
             }
             if (isset($page['picture'])) {
                 if (isset($page['picture']['data']['url']) && (!isset($page['picture']['data']['is_silhouette']) || $page['picture']['data']['is_silhouette'] === false)) {
                     $picture = esc_url_raw($page['picture']['data']['url'], array('http', 'https'));
                     if ($picture) {
                         $page['image'] = $picture;
                     }
                     unset($picture);
                 }
                 unset($page['picture']);
             }
             $clean_page = array('object_type' => 'page', 'id' => $page['id'], 'name' => $page['name']);
             if (isset($page['image'])) {
                 $clean_page['image'] = $page['image'];
             }
             if (isset($page['likes'])) {
                 $clean_page['likes'] = absint($page['likes']);
             }
             if (isset($page['talking_about_count'])) {
                 $clean_page['talking_about'] = absint($page['talking_about_count']);
             }
             if (isset($page['category'])) {
                 $clean_page['category'] = $page['category'];
             }
             if (isset($page['location'])) {
                 $clean_page['location'] = $page['location'];
             }
             $matched_pages[] = $clean_page;
             $matched_count++;
             unset($clean_page);
         }
         set_transient($cache_key, $matched_pages, 60 * 60);
     }
     return $matched_pages;
 }
 /**
  * Gets and returns a specific Facebook user.
  *
  * Requires basic_info read access for the account. Customize fields to request exactly what you expect to use.
  *
  * @since 1.5
  *
  * @link https://developers.facebook.com/docs/graph-api/reference/user/ Facebook User fields
  * @param string $facebook_id Facebook user identifier
  * @param array $fields User fields to include in the result
  * @return array a json_decode()d User response from the Facebook Graph API for the requested user and fields
  */
 public static function get_facebook_user($facebook_id, $fields = array())
 {
     // Facebook HTTP helper functions
     if (!class_exists('Facebook_WP_Extend')) {
         require_once dirname(__FILE__) . '/includes/facebook-php-sdk/class-facebook-wp.php';
     }
     $response = Facebook_WP_Extend::graph_api_with_app_access_token($facebook_id, 'GET', $fields);
     if (is_array($response)) {
         return $response;
     }
     return array();
 }
 /**
  * Retrieve a list of comments for the given URL from the Facebook Graph API.
  *
  * @since 1.1
  *
  * @link https://developers.facebook.com/docs/reference/api/Comment/ Individual Facebook Comment object
  * @param string $url absolute URL
  * @return array list of comments
  */
 public static function get_comments_by_url($url)
 {
     global $facebook_loader;
     if (!(isset($facebook_loader) && $facebook_loader->app_access_token_exists() && is_string($url) && $url)) {
         return array();
     }
     if (!class_exists('Facebook_WP_Extend')) {
         require_once $facebook_loader->plugin_directory . 'includes/facebook-php-sdk/class-facebook-wp.php';
     }
     try {
         $comments = Facebook_WP_Extend::graph_api_with_app_access_token('comments', 'GET', array('id' => $url, 'filter' => 'toplevel', 'fields' => 'id,from,created_time,message,comments.fields(id,from,created_time,message)'));
     } catch (WP_FacebookApiException $e) {
         return array();
     }
     if (is_array($comments['data']) && !empty($comments['data'])) {
         return $comments['data'];
     } else {
         return array();
     }
 }
 /**
  * Delete post data from Facebook when deleted in WordPress
  *
  * @since 1.0
  *
  * @global \Facebook_Loader $facebook_loader Reference plugin directory
  * @param int $post_id WordPress post identifer
  * @return void
  */
 public static function delete_facebook_post($post_id)
 {
     global $facebook_loader;
     $post_id = absint($post_id);
     if (!$post_id) {
         return;
     }
     $fb_page_post_id = get_post_meta($post_id, 'fb_fan_page_post_id', true);
     if ($fb_page_post_id) {
         $page_to_publish = self::get_publish_page();
         if (isset($page_to_publish['access_token'])) {
             if (!class_exists('Facebook_WP_Extend')) {
                 require_once $facebook_loader->plugin_directory . 'includes/facebook-php-sdk/class-facebook-wp.php';
             }
             // act as the saved credential, not current user
             try {
                 Facebook_WP_Extend::graph_api($fb_page_post_id, 'DELETE', array('access_token' => $page_to_publish['access_token']));
             } catch (WP_FacebookApiException $e) {
             }
         }
         unset($page_to_publish);
     }
     unset($fb_page_post_id);
     $post = get_post($post_id);
     if (isset($post->post_author) && self::user_can_publish_to_facebook((int) $post->post_author)) {
         if (!class_exists('Facebook_WP_Extend')) {
             require_once $facebook_loader->plugin_directory . 'includes/facebook-php-sdk/class-facebook-wp.php';
         }
         $fb_author_post_id = get_post_meta($post_id, 'fb_author_post_id', true);
         if ($fb_author_post_id) {
             try {
                 Facebook_WP_Extend::graph_api_with_app_access_token($fb_author_post_id, 'DELETE');
             } catch (WP_FacebookApiException $e) {
             }
         }
         unset($fb_author_post_id);
         // support old post mentions
         $fb_mentioned_pages_post_ids = get_post_meta($post_id, 'fb_mentioned_pages_post_ids', true);
         if ($fb_mentioned_pages_post_ids) {
             foreach ($fb_mentioned_pages_post_ids as $page_post_id) {
                 try {
                     Facebook_WP_Extend::graph_api_with_app_access_token($page_post_id, 'DELETE');
                 } catch (WP_FacebookApiException $e) {
                 }
             }
         }
         unset($fb_mentioned_pages_post_ids);
         $fb_mentioned_friends_post_ids = get_post_meta($post_id, 'fb_mentioned_friends_post_ids', true);
         if ($fb_mentioned_friends_post_ids) {
             foreach ($fb_mentioned_friends_post_ids as $page_post_id) {
                 try {
                     Facebook_WP_Extend::graph_api_with_app_access_token($page_post_id, 'DELETE');
                 } catch (WP_FacebookApiException $e) {
                 }
             }
         }
         unset($fb_mentioned_friends_post_ids);
     }
 }
Example #7
0
 /**
  * Display Facebook application details; suggest new values if value not set
  *
  * Request stored details for the site's stored Facebook application. Highlight values relevant to a proper functioning Facebook Login experience
  *
  * @since 1.5.3
  *
  * @param string $app_id Facebook application identifier
  * @return void
  */
 public static function app_details($app_id)
 {
     // HTTP interface to Facebook
     if (!class_exists('Facebook_WP_Extend')) {
         require_once dirname(dirname(__FILE__)) . '/includes/facebook-php-sdk/class-facebook-wp.php';
     }
     // request application data for the app id using stored app access token
     $app_details = Facebook_WP_Extend::graph_api_with_app_access_token($app_id, 'GET', array('fields' => 'name,icon_url,logo_url,app_domains,website_url,privacy_policy_url,terms_of_service_url,auth_dialog_headline,auth_dialog_perms_explanation'));
     if (empty($app_details)) {
         return;
     }
     // link to the relevant Facebook app editor screen
     $app_edit_base_uri = self::get_app_edit_base_uri($app_id);
     echo '<table id="facebook-app-login-fields">';
     echo '<caption>' . esc_html(__('Facebook Login', 'facebook')) . '</caption>';
     echo '<thead><tr><th>' . esc_html(__('Setting', 'facebook')) . '</th><th>' . esc_html(__('Value', 'facebook')) . '</th></tr></thead>';
     echo '<tbody>';
     // app name
     echo '<tr><th><a href="' . $app_edit_base_uri . 'appdetails/#name" target="_blank">' . esc_html(__('App name', 'facebook')) . '</a></th><td';
     if (isset($app_details['name']) && $app_details['name']) {
         echo '>"' . esc_html($app_details['name']) . '"';
     } else {
         echo ' class="error-message">';
         $site_name = trim(get_bloginfo('name'));
         // consider the WordPress default the same as not set
         if ($site_name && $site_name !== __('My Site')) {
             echo esc_html(sprintf(__('Not set. Consider using: %s', 'facebook'), $site_name));
         } else {
             echo esc_html(__('Not set.', 'facebook'));
         }
         unset($site_name);
     }
     echo '</td></tr>';
     // app domains able to act on behalf of the application
     echo '<tr><th><a href="' . $app_edit_base_uri . 'summary/" target="_blank">' . esc_html(__('App Domains', 'facebook')) . '</a></th><td';
     if (isset($app_details['app_domains']) && !empty($app_details['app_domains'])) {
         echo '><ul>';
         foreach ($app_details['app_domains'] as $app_domain) {
             echo '<li><code>' . esc_html($app_domain) . '</code></li>';
         }
         echo '</ul>';
     } else {
         echo ' class="error-message">';
         echo esc_html(sprintf(__('Not set. Consider using: %s', 'facebook'), parse_url(admin_url(), PHP_URL_HOST)));
     }
     echo '</td></tr>';
     // Website with Facebook Login
     echo '<tr><th><a href="' . $app_edit_base_uri . 'summary/#site_url_input" target="_blank">' . esc_html(__('Website', 'facebook')) . '</a></th><td';
     if (isset($app_details['website_url']) && $app_details['website_url']) {
         $app_details['website_url'] = esc_url($app_details['website_url'], array('http', 'https'));
         echo '><a href="' . $app_details['website_url'] . '" target="_blank">' . $app_details['website_url'] . '</a>';
     } else {
         echo ' class="error-message">';
         echo esc_html(sprintf(__('Not set. Consider using: %s', 'facebook'), home_url('/')));
     }
     echo '</td></tr>';
     // One-line description
     echo '<tr><th><a href="' . $app_edit_base_uri . 'appdetails/" target="_blank">' . esc_html(__('One-line description', 'facebook')) . '</a></th><td';
     if (isset($app_details['auth_dialog_headline']) && $app_details['auth_dialog_headline']) {
         echo '>"' . esc_html($app_details['auth_dialog_headline']) . '"';
     } else {
         echo ' class="error-message">';
         $site_description = trim(get_bloginfo('description'));
         // do not suggest WordPress default site description
         if ($site_description && $site_description !== __('Just another WordPress site')) {
             echo esc_html(sprintf(__('Not set. Consider using: %s', 'facebook'), '"' . $site_description . '"'));
         } else {
             echo esc_html(__('Not set.', 'facebook'));
         }
         unset($site_description);
     }
     echo '</td></tr>';
     // publish permissions explanation
     echo '<tr><th><a href="' . $app_edit_base_uri . 'appdetails/" target="_blank">' . esc_html(_x('Publish permissions explanation', 'Explain the reason for requesting publish permissions from a Facebook user', 'facebook')) . '</a></th><td';
     if (isset($app_details['auth_dialog_perms_explanation']) && $app_details['auth_dialog_perms_explanation']) {
         echo '>"' . esc_html($app_details['auth_dialog_perms_explanation']) . '"';
     } else {
         echo ' class="error-message">' . esc_html(sprintf(__('Not set. Consider using: %s', 'facebook'), '"' . __('Publish new posts to your Facebook Timeline or Page.', 'facebook') . '"'));
     }
     echo '</td></tr>';
     // Privacy Policy
     echo '<tr><th><a href="' . $app_edit_base_uri . 'appdetails/#privacy_url" target="_blank">' . esc_html(__('Privacy Policy', 'facebook')) . '</a></th><td';
     if (isset($app_details['privacy_policy_url']) && $app_details['privacy_policy_url']) {
         $app_details['privacy_policy_url'] = esc_url($app_details['privacy_policy_url'], array('http', 'https'));
         echo '><a href="' . $app_details['privacy_policy_url'] . '" target="_blank">' . $app_details['privacy_policy_url'] . '</a>';
     } else {
         echo ' class="error-message">' . esc_html(__('Not set.', 'facebook')) . ' ' . esc_html(_x('Create a new page?', 'Create a new WordPress page', 'facebook'));
     }
     echo '</td></tr>';
     // Terms of Service
     echo '<tr><th><a href="' . $app_edit_base_uri . 'appdetails/#tos_url" target="_blank">' . esc_html(__('Terms of Service', 'facebook')) . '</a></th><td';
     if (isset($app_details['terms_of_service_url']) && $app_details['terms_of_service_url']) {
         $app_details['terms_of_service_url'] = esc_url($app_details['terms_of_service_url'], array('http', 'https'));
         echo '><a href="' . $app_details['terms_of_service_url'] . '" target="_blank">' . $app_details['terms_of_service_url'] . '</a>';
     } else {
         echo ' class="error-message">';
         echo esc_html(__('Not set.', 'facebook')) . ' ' . esc_html(_x('Create a new page?', 'Create a new WordPress page', 'facebook'));
     }
     echo '</td></tr>';
     // Logo
     echo '<tr><th><a href="' . $app_edit_base_uri . 'appdetails/" target="_blank">' . esc_html(_x('Logo', 'Facebook application logo', 'facebook')) . '</a></th><td';
     if (isset($app_details['logo_url']) && $app_details['logo_url']) {
         echo '><img alt="' . esc_attr(__('Facebook application logo', 'facebook')) . '" src="' . esc_url($app_details['logo_url'], array('http', 'https')) . '" />';
     } else {
         echo ' class="error-message">' . esc_html(__('Not set.', 'facebook'));
     }
     echo '</td></tr>';
     // Icon
     echo '<tr><th><a href="' . $app_edit_base_uri . 'appdetails/" target="_blank">' . esc_html(_x('Icon', 'Facebook application icon', 'facebook')) . '</a></th><td';
     if (isset($app_details['icon_url']) && $app_details['icon_url']) {
         echo '><img alt="' . esc_attr(__('Facebook application icon', 'facebook')) . '" src="' . esc_url($app_details['icon_url'], array('http', 'https')) . '" />';
     } else {
         echo ' class="error-message">' . esc_html(__('Not set.', 'facebook'));
     }
     echo '</td></tr>';
     echo '</tbody></table>';
 }
 /**
  * Get all users with edit_posts capabilities broken out into Facebook-permissioned users and non-Facebook permissioned users
  *
  * @since 1.1.6
  */
 public static function get_all_wordpress_facebook_users()
 {
     if (!class_exists('Facebook_User')) {
         require_once dirname(dirname(__FILE__)) . '/facebook-user.php';
     }
     // fb => [], wp => []
     $users = Facebook_User::get_wordpress_users_associated_with_facebook_accounts();
     $users_with_app_permissions = array();
     if (!empty($users['fb'])) {
         if (!class_exists('Facebook_WP_Extend')) {
             require_once dirname(dirname(__FILE__)) . '/includes/facebook-php-sdk/class-facebook-wp.php';
         }
         foreach ($users['fb'] as $user) {
             if (!isset($user->fb_data['fb_uid'])) {
                 $users['wp'][] = $user;
                 continue;
             }
             $facebook_user_permissions = Facebook_WP_Extend::get_permissions_by_facebook_user_id($user->fb_data['fb_uid']);
             if (!is_array($facebook_user_permissions) || !isset($facebook_user_permissions['installed'])) {
                 $users['wp'][] = $user;
                 continue;
             }
             $user->fb_data['permissions'] = $facebook_user_permissions;
             unset($facebook_user_permissions);
             $users_with_app_permissions[] = $user;
         }
     }
     $users['fb'] = $users_with_app_permissions;
     return $users;
 }
 /**
  * Update the Facebook page information stored for the site.
  *
  * @since 1.1
  *
  * @uses update_option()
  * @global Facebook_Loader $facebook_loader request app access secret to hash app access token
  * @param array $page_data data returned from Facebook Graph API permissions call
  * @return void
  */
 public static function update_publish_to_page($page_data)
 {
     global $facebook_loader;
     if (!(is_array($page_data) && !empty($page_data) && isset($page_data['id']))) {
         return;
     }
     $current_user_id = get_current_user_id();
     if (!$current_user_id) {
         return;
     }
     if (!class_exists('Facebook_User')) {
         require_once dirname(dirname(__FILE__)) . '/facebook-user.php';
     }
     // request access token based on current user session and specified page
     $write_pages = Facebook_User::get_permissioned_pages('CREATE_CONTENT');
     if (!($write_pages && is_array($write_pages) && isset($write_pages[$page_data['id']]) && isset($write_pages[$page_data['id']]['name']) && isset($write_pages[$page_data['id']]['access_token']))) {
         return;
     }
     if (!class_exists('Facebook_WP_Extend')) {
         require_once dirname(dirname(__FILE__)) . '/includes/facebook-php-sdk/class-facebook-wp.php';
     }
     // get long lived access token
     $access_token = Facebook_WP_Extend::exchange_token($write_pages[$page_data['id']]['access_token']);
     if (!$access_token) {
         return;
     }
     $value = array('id' => $page_data['id'], 'name' => $write_pages[$page_data['id']]['name'], 'access_token' => $access_token, 'set_by_user' => $current_user_id);
     if (isset($write_pages[$page_data['id']]['link'])) {
         $value['link'] = $write_pages[$page_data['id']]['link'];
     }
     if (isset($facebook_loader->credentials['app_secret'])) {
         $value['appsecret_proof'] = hash_hmac('sha256', $access_token, $facebook_loader->credentials['app_secret']);
     }
     update_option(self::OPTION_PUBLISH_TO_PAGE, $value);
 }
Example #10
0
 /**
  * Save custom user information.
  *
  * @since 1.2
  *
  * @uses current_user_can() current user must be able to edit the passed WordPress user ID
  * @param int $wordpress_user_id WordPress user identifier
  * @return void
  */
 public static function save_data($wordpress_user_id)
 {
     if (!($wordpress_user_id && current_user_can('edit_user', $wordpress_user_id))) {
         return;
     }
     // allow decoupling of a WordPress account and a Facebook account
     if (isset($_POST['facebook_remove'])) {
         // WordPress Facebook User helper functions
         if (!class_exists('Facebook_User')) {
             require_once dirname(dirname(__FILE__)) . '/facebook-user.php';
         }
         $facebook_user_id = Facebook_User::get_facebook_profile_id($wordpress_user_id);
         if ($facebook_user_id) {
             // delete mapped FBID and other data
             Facebook_User::delete_user_meta($wordpress_user_id, 'fb_data');
             // delete post to Timeline opt-in if stored
             Facebook_User::delete_user_meta($wordpress_user_id, 'facebook_timeline_disabled');
             // Load WP HTTP helpers
             if (!class_exists('Facebook_WP_Extend')) {
                 require_once dirname(dirname(__FILE__)) . '/includes/facebook-php-sdk/class-facebook-wp.php';
             }
             // Revoke connection to app and all permissions
             Facebook_WP_Extend::graph_api_with_app_access_token($facebook_user_id . '/permissions', 'DELETE');
         }
         unset($facebook_user_id);
         // no need to store any other Facebook data
         return;
     }
     if (isset($_POST['facebook_fbid']) && ctype_digit($_POST['facebook_fbid'])) {
         // WordPress Facebook User helper functions
         if (!class_exists('Facebook_User')) {
             require_once dirname(dirname(__FILE__)) . '/facebook-user.php';
         }
         try {
             $facebook_user = Facebook_User::get_facebook_user($_POST['facebook_fbid'], array('fields' => array('id', 'username', 'link', 'third_party_id')));
             if (isset($facebook_user['id'])) {
                 $facebook_user_data = array('fb_uid' => $facebook_user['id'], 'activation_time' => time());
                 if (!empty($facebook_user['username'])) {
                     $facebook_user_data['username'] = $facebook_user['username'];
                 }
                 if (!empty($facebook_user['link'])) {
                     $facebook_user_data['link'] = $facebook_user['link'];
                 }
                 if (!empty($facebook_user['third_party_id'])) {
                     $facebook_user_data['third_party_id'] = $facebook_user['third_party_id'];
                 }
                 Facebook_User::update_user_meta($wordpress_user_id, 'fb_data', $facebook_user_data);
                 unset($facebook_user_data);
             }
             unset($facebook_user);
         } catch (Exception $e) {
         }
     }
     if (isset($_POST['facebook_timeline']) && $_POST['facebook_timeline'] == '1') {
         // WordPress Facebook User helper functions
         if (!class_exists('Facebook_User')) {
             require_once dirname(dirname(__FILE__)) . '/facebook-user.php';
         }
         Facebook_User::delete_user_meta($wordpress_user_id, 'facebook_timeline_disabled');
         // delete if stored
     } else {
         // WordPress Facebook User helper functions
         if (!class_exists('Facebook_User')) {
             require_once dirname(dirname(__FILE__)) . '/facebook-user.php';
         }
         Facebook_User::update_user_meta($wordpress_user_id, 'facebook_timeline_disabled', '1');
     }
 }