Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

include a debug page discovered through the Facebook plugin menu

  • Loading branch information...
commit 3a0fcd7778336657f6973e0dd494c6e3df94ccb4 1 parent 5fd01d5
Niall Kennedy niallkennedy authored
459 admin/settings-debug.php
View
@@ -0,0 +1,459 @@
+<?php
+
+/**
+ * Summarize the plugin configuration on a single page
+ *
+ * @since 1.1.6
+ */
+class Facebook_Settings_Debugger {
+
+ /**
+ * Page identifier
+ *
+ * @since 1.1.6
+ * @var string
+ */
+ const PAGE_SLUG = 'facebook-debug';
+
+ /**
+ * HTML span noting a feature exists
+ *
+ * @since 1.1.6
+ * @var string
+ */
+ const EXISTS = '<span class="feature-present">&#10003;</span>';
+
+ /**
+ * HTML span noting a feature does not exist
+ *
+ * @since 1.1.6
+ * @var string
+ */
+ const DOES_NOT_EXIST = '<span class="feature-not-present">X</span>';
+
+ /**
+ * Reference the social plugin by name
+ *
+ * @since 1.1.6
+ * @return string social plugin name
+ */
+ public static function social_plugin_name() {
+ return __( 'Debugger', 'facebook' );
+ }
+
+ /**
+ * Navigate to the debugger page through the Facebook top-level menu item
+ *
+ * @since 1.1.6
+ * @uses add_submenu_page()
+ * @param string $parent_slug Facebook top-level menu item slug
+ * @return string submenu hook suffix
+ */
+ public static function add_submenu_item( $parent_slug ) {
+ $hook_suffix = add_submenu_page(
+ $parent_slug,
+ self::social_plugin_name(),
+ self::social_plugin_name(),
+ 'manage_options',
+ self::PAGE_SLUG,
+ array( 'Facebook_Settings_Debugger', 'content' )
+ );
+
+ if ( $hook_suffix ) {
+ add_action( 'load-' . $hook_suffix, array( 'Facebook_Settings_Debugger', 'onload' ) );
+ }
+
+ return $hook_suffix;
+ }
+
+ /**
+ * Load scripts and other setup functions on page load
+ */
+ public static function onload() {
+ add_action( 'admin_enqueue_scripts', array( 'Facebook_Settings_Debugger', 'enqueue_scripts' ) );
+ }
+
+ /**
+ * Enqueue scripts and styles
+ *
+ * @since 1.1.6
+ */
+ public static function enqueue_scripts() {
+ wp_enqueue_style( self::PAGE_SLUG, plugins_url( 'static/css/admin/debug' . ( ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) ? '' : '.min' ) . '.css', dirname( __FILE__ ) ), array(), '1.1.6' );
+ }
+
+ /**
+ * Page content
+ *
+ * @since 1.1.6
+ */
+ public static function content() {
+ global $facebook_loader;
+
+ if ( ! class_exists( 'Facebook_Settings' ) )
+ require_once( dirname(__FILE__) . '/settings.php' );
+
+ echo '<div class="wrap">';
+ echo '<header><h2>' . esc_html( self::social_plugin_name() ) . '</h2></header>';
+
+ // only show users if app credentials stored
+ if ( isset( $facebook_loader->credentials['app_id'] ) ) {
+ self::users_section();
+ self::post_to_page_section();
+ }
+
+ self::enabled_features_by_view_type();
+ self::widgets_section();
+ self::server_info();
+
+ echo '</div>';
+
+ Facebook_Settings::stats_beacon();
+ }
+
+ /**
+ * 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() {
+ global $facebook;
+
+ if ( ! isset( $facebook ) )
+ return array( 'fb' => array(), 'wp' => array() );
+
+ 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();
+ foreach ( $users['fb'] as $user ) {
+ if ( ! isset( $user->fb_data['fb_uid'] ) ) {
+ $users['wp'] = $user;
+ continue;
+ }
+
+ $facebook_user_permissions = $facebook->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;
+ }
+
+ /**
+ * Detail site users and their association with Facebook
+ *
+ * @since 1.1.6
+ */
+ public static function users_section() {
+ global $wpdb;
+
+ $users = self::get_all_wordpress_facebook_users();
+
+ // should only happen if errors
+ if ( empty( $users['fb'] ) && empty( $users['wp'] ) )
+ return;
+
+ echo '<section id="debug-users"><header><h3>' . esc_html( __( 'Authors' ) ) . '</h3></header>';
+
+ if ( ! empty( $users['fb'] ) ) {
+ echo '<table><caption>' . esc_html( __( 'Connected to Facebook', 'facebook' ) ) . '</caption><colgroup><col><col span="2" class="permissions"></colgroup><thead><tr><th>' . esc_html( __( 'Name' ) ) . '</th><th title="' . esc_attr( __( 'Facebook account', 'facebook' ) ) . '"></th><th>' . esc_html( __( 'Post to timeline', 'facebook' ) ) . '</th><th>' . esc_html( __( 'Manage pages', 'facebook' ) ) . '</th></tr></thead><tbody>';
+ foreach( $users['fb'] as $user ) {
+ echo '<tr><th><a href="' . esc_url( get_author_posts_url( $user->id ) ) . '">' . esc_html( $user->display_name ) . '</a></th>';
+
+ echo '<td><a class="facebook-icon" href="' . esc_url( 'https://www.facebook.com/' . ( isset( $user->fb_data['username'] ) ? $user->fb_data['username'] : 'profile.php?' . http_build_query( array( 'id' => $user->fb_data['fb_uid'] ) ) ), array( 'http', 'https' ) ) . '"></a></td>';
+
+ echo '<td>';
+ if ( isset( $user->fb_data['permissions']['publish_stream'] ) && $user->fb_data['permissions']['publish_stream'] )
+ echo self::EXISTS;
+ else
+ echo self::DOES_NOT_EXIST;
+ echo '</td>';
+
+ echo '<td>';
+ if ( isset( $user->fb_data['permissions']['manage_pages'] ) && $user->fb_data['permissions']['manage_pages'] )
+ echo self::EXISTS;
+ else
+ echo self::DOES_NOT_EXIST;
+ echo '</td></tr>';
+ }
+ echo '</tbody></table>';
+ }
+
+ if ( ! empty( $users['wp'] ) ) {
+ // last 90 days
+ $where = ' AND ' . $wpdb->prepare( 'post_date > %s', date( 'Y-m-d H:i:s', time() - 90*24*60*60 ) );
+
+ $public_post_types = get_post_types( array( 'public' => true ) );
+ if ( is_array( $public_post_types ) && ! empty( $public_post_types ) ) {
+ $public_post_types = array_values( $public_post_types );
+ $where .= ' AND post_type';
+ if ( count( $public_post_types ) === 1 ) {
+ $where .= $wpdb->prepare( ' = %s', $public_post_types[0] );
+ } else {
+ $s = '';
+ foreach( $public_post_types as $post_type ) {
+ $s .= "'" . $wpdb->escape( $post_type ) . "',";
+ }
+ $where .= ' IN (' . rtrim( $s, ',' ) . ')';
+ unset( $s );
+ }
+ }
+
+ $public_states = get_post_stati( array( 'public' => true ) );
+ if ( is_array( $public_states ) && ! empty( $public_states ) ) {
+ $public_states = array_values( $public_states );
+ $where .= ' AND post_status';
+ if ( count( $public_states ) === 1 ) {
+ $where .= $wpdb->prepare( ' = %s', $public_states[0] );
+ } else {
+ $s = '';
+ foreach( $public_states as $state ) {
+ $s .= "'" . $wpdb->escape( $state ) . "',";
+ }
+ $where .= ' IN (' . rtrim( $s, ',' ) . ')';
+ unset( $s );
+ }
+ }
+ unset( $public_states );
+
+ echo '<table><caption>' . esc_html( __( 'Not connected to Facebook', 'facebook' ) ) . '</caption><thead><th>' . esc_html( __( 'Name' ) ) . '</th><th><abbr title="' . esc_attr( sprintf( __( 'Number of published posts in the last %u days', 'facebook' ), 90 ) ) . '">' . esc_html( _x( '# of recent posts', 'recent articles. used as a table column header', 'facebook' ) ) . '</abbr></th></thead><tbody>';
+
+ foreach( $users['wp'] as $user ) {
+ echo '<tr><th><a href="' . esc_url( get_author_posts_url( $user->id ) ) . '">' . esc_html( $user->display_name ) . '</a></th>';
+ echo '<td>' . $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = %d $where", $user->id ) ) . '</td>';
+ echo '</tr>';
+ }
+ echo '</tbody></table>';
+ }
+
+ echo '</section>';
+ }
+
+ /**
+ * Display the currently associated Facebook page, if one exists.
+ *
+ * @since 1.1.6
+ */
+ public static function post_to_page_section() {
+ if ( ! class_exists( 'Facebook_Social_Publisher_Settings' ) )
+ require_once( dirname( __FILE__ ) . '/settings-social-publisher.php' );
+
+ $post_to_page = get_option( Facebook_Social_Publisher_Settings::OPTION_PUBLISH_TO_PAGE );
+ if ( ! ( is_array( $post_to_page ) && isset( $post_to_page['id'] ) && isset( $post_to_page['name'] ) && isset( $post_to_page['access_token'] ) ) )
+ return;
+
+ echo '<section id="debug-page"><header><h3>' . esc_html( __( 'Facebook Page', 'facebook' ) ) . '</h3></header>';
+ echo '<p>' . sprintf( esc_html( _x( 'Publishing to %s.', 'publishing to a page name on Facebook.com', 'facebook' ) ), '<a href="' . esc_url( 'https://www.facebook.com/' . $post_to_page['id'], array( 'http', 'https' ) ) . '">' . esc_html( $post_to_page['name'] ) . '</a>' );
+ if ( isset( $post_to_page['set_by_user'] ) ) {
+ $current_user = wp_get_current_user();
+ if ( $current_user->ID == $post_to_page['set_by_user'] ) {
+ echo ' ' . esc_html( __( 'Saved by you.', 'facebook' ) );
+ } else {
+ $setter = get_userdata( $post_to_page['set_by_user'] );
+ if ( $setter ) {
+ echo ' ' . esc_html( sprintf( _x( 'Saved by %s.', 'saved by person name', 'facebook' ), $setter->display_name ) );
+ }
+ unset( $setter );
+ }
+ unset( $current_user );
+ }
+ echo '</p>';
+
+ echo '</section>';
+ }
+
+ /**
+ * Which features are enabled for the site on each major view type?
+ *
+ * @since 1.1.6
+ */
+ public static function enabled_features_by_view_type() {
+ if ( ! class_exists( 'Facebook_Social_Plugin_Settings' ) )
+ require_once( dirname( __FILE__ ) . '/settings-social-plugin.php' );
+ $views = Facebook_Social_Plugin_Settings::get_show_on_choices( 'all' );
+ if ( ! is_array( $views ) || empty( $views ) )
+ return;
+
+
+ echo '<section id="debug-social-plugins"><header><h3>' . esc_html( __( 'Social Plugins', 'facebook' ) ) . '</h3></header>';
+ echo '<table><caption>' . esc_html( _x( 'Features enabled by view type', 'software features available based on different classifications website view', 'facebook' ) ) . '</caption>';
+
+ $features = array(
+ 'like' => array(
+ 'name' => __( 'Like Button', 'facebook' ),
+ 'url' => 'https://developers.facebook.com/docs/reference/plugins/like/'
+ ),
+ 'send' => array(
+ 'name' => __( 'Send Button', 'facebook' ),
+ 'url' => 'https://developers.facebook.com/docs/reference/plugins/send/'
+ ),
+ 'subscribe' => array(
+ 'name' => __( 'Subscribe Button', 'facebook' ),
+ 'url' => 'https://developers.facebook.com/docs/reference/plugins/subscribe/'
+ ),
+ 'recommendations_bar' => array(
+ 'name' => __( 'Recommendations Bar', 'facebook' ),
+ 'url' => 'https://developers.facebook.com/docs/reference/plugins/recommendationsbar/'
+ ),
+ 'comments' => array(
+ 'name' => __( 'Comments Box', 'facebook' ),
+ 'url' => 'https://developers.facebook.com/docs/reference/plugins/comments/'
+ ),
+ 'mentions' => array(
+ 'name' => __( 'Mentions', 'facebook' )
+ )
+ );
+
+ echo '<thead><tr><th>' . esc_html( __( 'View', 'facebook' ) ) . '</th>';
+ foreach ( $features as $slug => $properties ) {
+ echo '<th>';
+ if ( isset( $properties['url'] ) )
+ echo '<a href="' . esc_url( $properties['url'], array( 'http', 'https' ) ) . '">' . esc_html( $properties['name'] ) . '</a>';
+ else
+ echo esc_html( $properties['name'] );
+ echo '</th>';
+ }
+ echo '</tr></thead><tbody>';
+
+ foreach( $views as $view ) {
+ echo '<tr><th>' . $view . '</th>';
+ $view_features = get_option( 'facebook_' . $view . '_features' );
+ if ( ! is_array( $view_features ) )
+ $view_features = array();
+ foreach( $features as $feature => $properties ) {
+ echo '<td>';
+ if ( isset( $view_features[$feature] ) )
+ echo self::EXISTS;
+ else
+ echo ' ';
+ echo '</td>';
+ }
+ echo '</tr>';
+ }
+
+ echo '</tbody></table>';
+ echo '</section>';
+ }
+
+ /**
+ * Widgets enabled for the site
+ *
+ * @since 1.1.6
+ */
+ public static function widgets_section() {
+ if ( ! class_exists( 'Facebook_Settings' ) )
+ require_once( dirname(__FILE__) . '/settings.php' );
+
+ $active_widgets = Facebook_Settings::get_active_widgets();
+ if ( ! is_array( $active_widgets ) || empty( $active_widgets ) )
+ return;
+
+ $all_widgets = array(
+ 'activity-feed' => array(
+ 'name' => __( 'Activity Feed', 'facebook' ),
+ 'url' => 'https://developers.facebook.com/docs/reference/plugins/activity/'
+ ),
+ 'like' => array(
+ 'name' => __( 'Like Button', 'facebook' ),
+ 'url' => 'https://developers.facebook.com/docs/reference/plugins/like/'
+ ),
+ 'recommendations' => array(
+ 'name' => __( 'Recommendations Box', 'facebook' ),
+ 'url' => 'https://developers.facebook.com/docs/reference/plugins/recommendations/'
+ ),
+ 'send' => array(
+ 'name' => __( 'Send Button', 'facebook' ),
+ 'url' => 'https://developers.facebook.com/docs/reference/plugins/send/'
+ ),
+ 'subscribe' => array(
+ 'name' => __( 'Subscribe Button', 'facebook' ),
+ 'url' => 'https://developers.facebook.com/docs/reference/plugins/subscribe/'
+ )
+ );
+
+ echo '<section id="debug-widgets"><header><h3>' . esc_html( __( 'Widgets' ) ) . '</h3></header>';
+ echo '<table><thead><tr><th>' . esc_html( _x( 'Widget name', 'name of a page component', 'facebook' ) ) . '</th><th>' . esc_html( __( 'Active', 'facebook' ) ) . '</th></tr></thead><tbody>';
+ foreach( $all_widgets as $slug => $widget ) {
+ echo '<tr><th><a href="' . esc_url( $widget['url'], array( 'http', 'https' ) ) . '">' . esc_html( $widget['name'] ) . '</a></th><td>';
+ if ( in_array( $slug , $active_widgets ) )
+ echo self::EXISTS;
+ else
+ echo ' ';
+ echo '</td></tr>';
+ }
+ echo '</tbody></table></section>';
+ }
+
+ /**
+ * How does the site communicate with Facebook?
+ *
+ * @since 1.1.6
+ */
+ public static function server_info() {
+ echo '<section id="debug-server"><header><h3>' . esc_html( __( 'Server configuration', 'facebook' ) ) . '</h3></header><table><thead><th>' . esc_html( __( 'Feature', 'facebook' ) ) . '</th><th>' . esc_html( _x( 'Info', 'Information', 'facebook' ) ) . '</th></thead><tbody>';
+
+ // PHP version
+ echo '<tr><th>' . esc_html( sprintf( _x( '%s version', 'software version', 'facebook' ), 'PHP' ) ) . '</th><td>';
+ // PHP > 5.2.7
+ if ( defined( 'PHP_MAJOR_VERSION' ) && defined( 'PHP_MINOR_VERSION' ) && defined( 'PHP_RELEASE_VERSION' ) )
+ echo esc_html( PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION );
+ else
+ esc_html( phpversion() );
+ echo '</td></tr>';
+
+ // WordPress version
+ echo '<tr><th>' . esc_html( sprintf( _x( '%s version', 'software version', 'facebook' ), 'WordPress' ) ) . '</th><td>' . esc_html( get_bloginfo( 'version' ) ) . '</td></tr>';
+
+ if ( isset( $_SERVER['SERVER_SOFTWARE'] ) )
+ echo '<tr><th>' . esc_html( __( 'Server software', 'facebook' ) ) . '</th><td>' . esc_html( $_SERVER['SERVER_SOFTWARE'] ) . '</td></tr>';
+
+ // WP_HTTP connection for SSL
+ echo '<tr id="debug-server-http">';
+ echo '<th>' . sprintf( esc_html( _x( '%s connection method', 'server-to-server connection', 'facebook' ) ), '<a href="http://codex.wordpress.org/HTTP_API">WP_HTTP</a>' ) . '</th><td>';
+ $http_obj = _wp_http_get_object();
+ $http_transport = $http_obj->_get_first_available_transport( array( 'ssl' => true ) );
+ if ( is_string( $http_transport ) && strlen( $http_transport ) > 8 ) {
+ $http_transport = strtolower( substr( $http_transport, 8 ) );
+ if ( $http_transport === 'curl' ) {
+ echo '<a href="http://php.net/manual/book.curl.php">cURL</a>';
+ $curl_version = curl_version();
+ if ( isset( $curl_version['version'] ) )
+ echo ' ' . esc_html( $curl_version['version'] );
+ if ( isset( $curl_version['ssl_version'] ) ) {
+ echo '; ';
+ $ssl_version = $curl_version['ssl_version'];
+ if ( substr_compare( $ssl_version, 'OpenSSL/', 0, 8 ) === 0 )
+ echo '<a href="http://openssl.org/">OpenSSL</a>/' . esc_html( substr( $ssl_version, 8 ) );
+ else
+ echo esc_html( $ssl_version );
+ unset( $ssl_version );
+ }
+ unset( $curl_version );
+ } else if ( $http_transport === 'streams' ) {
+ echo '<a href="http://www.php.net/manual/book.stream.php">Stream</a>';
+ } else if ( $http_transport === 'fsockopen' ) {
+ echo '<a href="http://php.net/manual/function.fsockopen.php">fsockopen</a>';
+ } else {
+ echo $http_transport;
+ }
+ } else {
+ echo __( 'none available', 'facebook' );
+ }
+ echo '</td></tr>';
+ unset( $http_transport );
+ unset( $http_obj );
+
+ echo '</table></section>';
+ }
+}
+
+?>
2  admin/settings-social-publisher.php
View
@@ -324,7 +324,7 @@ public function display_publish_page() {
} else {
$setter = get_userdata( $existing_page['set_by_user'] );
if ( $setter ) {
- echo '. ' . esc_html( sprintf( __( 'Saved by %s.', 'facebook' ), $setter->display_name ) );
+ echo '. ' . esc_html( sprintf( _x( 'Saved by %s.', 'saved by person name', 'facebook' ), $setter->display_name ) );
}
}
}
78 admin/settings.php
View
@@ -23,6 +23,7 @@ public static function init() {
self::migrate_options_10();
add_action( 'admin_menu', array( 'Facebook_Settings', 'settings_menu_items' ) );
add_filter( 'plugin_action_links', array( 'Facebook_Settings', 'plugin_action_links' ), 10, 2 );
+ add_action( 'admin_enqueue_scripts', array( 'Facebook_Settings', 'enqueue_scripts' ) );
if ( self::app_credentials_exist() ) {
$available_features = apply_filters( 'facebook_features', self::$features );
@@ -38,6 +39,15 @@ public static function init() {
}
/**
+ * Enqueue scripts and styles
+ *
+ * @since 1.1.6
+ */
+ public static function enqueue_scripts() {
+ wp_enqueue_style( 'facebook-admin-icons', plugins_url( 'static/css/admin/icons' . ( ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) ? '' : '.min' ) . '.css', dirname( __FILE__ ) ), array(), '1.1' );
+ }
+
+ /**
* Check if Facebook application credentials are stored for the current site
* Limit displayed features based on the existence of app data
*
@@ -120,6 +130,10 @@ public static function settings_menu_items() {
Facebook_Social_Publisher_Settings::add_submenu_item( $menu_slug );
}
+
+ if ( ! class_exists( 'Facebook_Settings_Debugger' ) )
+ require_once( dirname(__FILE__) . '/settings-debug.php' );
+ Facebook_Settings_Debugger::add_submenu_item( $menu_slug );
}
// make an assumption about submenu mappings, but don't fail if our assumption is wrong
@@ -245,46 +259,58 @@ public static function debug_output( $app_id = '' ) {
require_once( dirname(__FILE__) . '/settings-social-plugin.php' );
$enabled_features = array();
- $all_targets = Facebook_Social_Plugin_Settings::get_show_on_choices( 'all' );
- $option_name = 'facebook_%s_features';
- foreach ( $all_targets as $target ) {
- $features = get_option( sprintf( $option_name, $target ) );
+ $views = Facebook_Social_Plugin_Settings::get_show_on_choices( 'all' );
+ foreach ( $views as $view ) {
+ $features = get_option( 'facebook_' . $view . '_features' );
if ( is_array( $features ) && ! empty( $features ) )
- $enabled_features[$target] = $features;
+ $enabled_features[$view] = array_keys( $features );
else
- $enabled_features[$target] = false; // show a potential target where nothing appears
+ $enabled_features[$view] = false; // show a potential target where nothing appears
unset( $features );
}
- unset( $option_name );
- unset( $all_targets );
+ unset( $views );
if ( ! empty( $enabled_features ) )
$debug['features'] = $enabled_features;
unset( $enabled_features );
+ $widgets = self::get_active_widgets();
+ if ( ! empty( $widgets ) )
+ $debug['widgets'] = $widgets;
+
+ return $debug;
+ }
+
+ /**
+ * Get a list of Facebook widgets in one or more sidebars
+ *
+ * @since 1.1.6
+ * @return array widget slugs
+ */
+ public static function get_active_widgets() {
$sidebar_widgets = wp_get_sidebars_widgets();
unset( $sidebar_widgets['wp_inactive_widgets'] ); // no need to track inactives
$sidebar_widgets = array_unique( array_merge( array_values( $sidebar_widgets ) ) ); // track widgets, not sidebar names
- if ( is_array( $sidebar_widgets ) && isset( $sidebar_widgets[0] ) ) {
- $sidebar_widgets = $sidebar_widgets[0];
- $widgets = array();
-
- // iterate through each sidebar configuration
- // note any facebook widgets we find along the way
- foreach( $sidebar_widgets as $widget_id ) {
- if ( strlen( $widget_id ) > 9 && substr_compare( $widget_id, 'facebook-', 0, 9 ) === 0 ) {
- $feature = substr( $widget_id, 9, strrpos( $widget_id, '-' ) - 9 );
- if ( ! isset( $widgets[$feature] ) )
- $widgets[$feature] = true;
- unset( $feature );
- }
+ if ( ! ( is_array( $sidebar_widgets ) && isset( $sidebar_widgets[0] ) ) )
+ return array();
+
+ $sidebar_widgets = $sidebar_widgets[0];
+ $widgets = array();
+
+ // iterate through each sidebar configuration
+ // note any facebook widgets we find along the way
+ foreach( $sidebar_widgets as $widget_id ) {
+ if ( strlen( $widget_id ) > 9 && substr_compare( $widget_id, 'facebook-', 0, 9 ) === 0 ) {
+ $feature = substr( $widget_id, 9, strrpos( $widget_id, '-' ) - 9 );
+ if ( ! isset( $widgets[$feature] ) )
+ $widgets[$feature] = true;
+ unset( $feature );
}
-
- if ( ! empty( $widgets ) )
- $debug['widgets'] = array_keys( $widgets );
- unset( $widgets );
}
- return $debug;
+ if ( ! empty( $widgets ) )
+ return array_keys( $widgets );
+
+ return array();
}
/**
41 facebook-user.php
View
@@ -156,6 +156,47 @@ public static function can_publish_to_facebook() {
return true;
}
+
+ /**
+ * Retrieve a list of all WordPress users for the current site with the given capability
+ * Check each user for stored data indicating a possible association with a Facebook account
+ *
+ * @since 1.1.6
+ * @param string $capability WordPress capability. default: edit_posts
+ * @return array associative array with Facebook-enabled users (fb key) and other users (wp key)
+ */
+ public static function get_wordpress_users_associated_with_facebook_accounts( $capability = 'edit_posts' ) {
+ $authors = array(
+ 'fb' => array(),
+ 'wp' => array()
+ );
+
+ if ( ! $capability )
+ return $authors;
+
+ $site_users = get_users( array(
+ 'fields' => array( 'id', 'display_name', 'user_registered' ),
+ 'orderby' => 'display_name',
+ 'order' => 'ASC'
+ ) );
+
+ foreach( $site_users as $user ) {
+ // post authors only
+ if ( ! ( isset( $user->id ) && user_can( $user->id, $capability ) ) )
+ continue;
+
+ $facebook_user_data = self::get_user_meta( $user->id, 'fb_data', true );
+ if ( is_array( $facebook_user_data ) && isset( $facebook_user_data['fb_uid'] ) ) {
+ $user->fb_data = $facebook_user_data;
+ $authors['fb'][] = $user;
+ } else {
+ $authors['wp'][] = $user;
+ }
+ unset( $facebook_user_data );
+ }
+
+ return $authors;
+ }
}
?>
35 includes/facebook-php-sdk/class-facebook-wp.php
View
@@ -105,6 +105,41 @@ public function get_current_user_permissions( $current_user = '' ) {
}
/**
+ * Retrieve Facebook permissions assigned to the application by a specific Facebook user id
+ *
+ * @since 1.1.6
+ * @param string $facebook_id Facebook user identifier
+ * @return array Facebook permissions
+ */
+ public function get_permissions_by_facebook_user_id( $facebook_id ) {
+ if ( ! ( is_string( $facebook_id ) && $facebook_id ) )
+ return array();
+
+ try {
+ $response = $this->api( '/' . $facebook_id . '/permissions', 'GET', array( 'ref' => 'fbwpp' ) );
+ } catch ( WP_FacebookApiException $e ) {
+ $error_result = $e->getResult();
+ if ( $error_result && isset( $error_result['error_code'] ) ) {
+ // try to extend access token if request failed
+ if ( $error_result['error_code'] === 2500 )
+ $this->setExtendedAccessToken();
+ }
+ return array();
+ }
+
+ if ( is_array( $response ) && isset( $response['data'][0] ) ) {
+ $response = $response['data'][0];
+ $permissions = array();
+ foreach( $response as $permission => $exists ) {
+ $permissions[$permission] = true;
+ }
+ return $permissions;
+ }
+
+ return array();
+ }
+
+ /**
* Provides the implementations of the inherited abstract
* methods. The implementation uses user meta to maintain
* a store for authorization codes, user ids, CSRF states, and
80 static/css/admin/debug.css
View
@@ -0,0 +1,80 @@
+#wpbody-content section {
+ margin-top: 3em;
+}
+
+#wpbody-content table {
+ background-color: transparent;
+ border-collapse: collapse;
+ border-spacing: 0;
+ min-width: 33%;
+ max-width: 100%;
+ margin-top: 2em;
+}
+
+#wpbody-content th, #wpbody-content td {
+ padding: 8px;
+ vertical-align: top;
+ border-top-style: solid;
+ border-top-width: 1px;
+ border-top-color: #ddd;
+}
+
+#wpbody-content th {
+ font-weight: bold;
+}
+
+#wpbody-content td {
+ text-align: center;
+}
+
+#debug-server td {
+ text-align: left;
+}
+
+// Bottom align for column headings
+#wpbody-content thead th {
+ text-align: center;
+ vertical-align: bottom;
+}
+
+#wpbody-content thead th:first-child {
+ text-align: left;
+}
+
+#wpbody-content tbody th {
+ text-align: left;
+}
+
+#wpbody-content caption + thead tr:first-child th, #wpbody-content caption + thead tr:first-child td, #wpbody-content colgroup + thead tr:first-child th, #wpbody-content colgroup + thead tr:first-child td, #wpbody-content thead:first-child tr:first-child th, #wpbody-content thead:first-child tr:first-child td {
+ border-top: 0;
+}
+
+tbody tr:nth-child(odd) td, tbody tr:nth-child(odd) th {
+ background-color: #f9f9f9;
+}
+
+.feature-present {
+ font-style: bold;
+ color: green;
+}
+
+.feature-not-present {
+ font-style: bold;
+ color: red
+}
+
+.facebook-icon {
+ background-image: url( '../../img/icon.png' );
+ background-repeat: no-repeat;
+ background-size: 16px 16px;
+ display: inline-block;
+ height: 16px;
+ width: 16px;
+}
+
+/* high-dpi */
+@media only screen and (-webkit-min-device-pixel-ratio: 1.5) {
+ .facebook-icon {
+ background-image: url( '../../img/icon-2x.png' );
+ }
+}
1  static/css/admin/debug.min.css
View
@@ -0,0 +1 @@
+#wpbody-content section{margin-top:3em}#wpbody-content table{background-color:transparent;border-collapse:collapse;border-spacing:0;min-width:33%;max-width:100%;margin-top:2em}#wpbody-content th,#wpbody-content td{padding:8px;vertical-align:top;border-top-style:solid;border-top-width:1px;border-top-color:#ddd}#wpbody-content th{font-weight:bold}#wpbody-content td{text-align:center}#debug-server td{text-align:left}// Bottom align for column headings #wpbody-content thead th{text-align:center;vertical-align:bottom}#wpbody-content thead th:first-child{text-align:left}#wpbody-content tbody th{text-align:left}#wpbody-content caption+thead tr:first-child th,#wpbody-content caption+thead tr:first-child td,#wpbody-content colgroup+thead tr:first-child th,#wpbody-content colgroup+thead tr:first-child td,#wpbody-content thead:first-child tr:first-child th,#wpbody-content thead:first-child tr:first-child td{border-top:0}tbody tr:nth-child(odd) td,tbody tr:nth-child(odd) th{background-color:#f9f9f9}.feature-present{font-style:bold;color:green}.feature-not-present{font-style:bold;color:red}.facebook-icon{background-image:url('../../img/icon.png');background-repeat:no-repeat;background-size:16px 16px;display:inline-block;height:16px;width:16px}@media only screen and (-webkit-min-device-pixel-ratio:1.5){.facebook-icon{background-image:url('../../img/icon-2x.png')}}
8 static/css/admin/icons.css
View
@@ -5,7 +5,7 @@
/* swap icons on hover */
#toplevel_page_facebook-application-settings .wp-menu-image {
- background-image: url( '../img/icon-bw.png' );
+ background-image: url( '../../img/icon-bw.png' );
background-repeat: no-repeat;
background-position: 6px 6px;
display: inline-block;
@@ -14,18 +14,18 @@
}
#toplevel_page_facebook-application-settings .wp-menu-image:hover {
- background-image: url( '../img/icon.png' );
+ background-image: url( '../../img/icon.png' );
}
/* high-dpi */
@media only screen and (-webkit-min-device-pixel-ratio: 1.5) {
#toplevel_page_facebook-application-settings .wp-menu-image {
- background-image: url( '../img/icon-bw-2x.png' );
+ background-image: url( '../../img/icon-bw-2x.png' );
background-size: 16px 16px;
}
#toplevel_page_facebook-application-settings .wp-menu-image:hover {
- background-image: url( '../img/icon-2x.png' );
+ background-image: url( '../../img/icon-2x.png' );
background-size: 16px 16px;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.