Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Facebook Social Widgets
- Plugin URI: http://www.jakespurlock.com/fb-social-widgets
- Description: Easily integrate Facebook Social Commenting into your WordPress website.
- Author: Jake Spurlock
- Version: 0.5
- Author URI: http://jakespurlock.com
- */
- // create custom plugin settings menu
- add_action('admin_menu', 'fb_create_menu');
- function fb_create_menu() {
- add_options_page('Facebook Comments', 'Facebook Comments', 'administrator', __FILE__, 'buildinternet_settings_page');
- add_action( 'admin_init', 'register_mysettings' );
- }
- function register_mysettings() {
- //register our settings
- register_setting( 'fb-settings-group', 'fb_app_id' );
- register_setting( 'fb-settings-group', 'fb_width' );
- register_setting( 'fb-settings-group', 'fb_number' );
- register_setting( 'fb-settings-group', 'fb_widget' );
- register_setting( 'fb-settings-group', 'fb_connections' );
- register_setting( 'fb-settings-group', 'fb_location_yes' );
- register_setting( 'fb-settings-group', 'fb_location_no');
- register_setting( 'fb-settings-group', 'fb_location');
- }
- function buildinternet_settings_page() { ?>
- <div class="wrap">
- <h2>Facebook Social Widget Options</h2>
- <div id="custom_form">
- <form method="post" action="options.php">
- <?php settings_fields('fb-settings-group'); ?>
- <table summary="Facebook Options">
- <tbody>
- <tr>
- <td style="width:25%;padding-right:10px;">Unique Application ID</td>
- <td><input type="text" name="fb_app_id" value="<?php echo get_option('fb_app_id'); ?>"></td>
- </tr>
- <tr>
- <td style="padding-right:10px;">Nuber of Comments to Show Per Page</td>
- <td><input type="text" name="fb_number" value="<?php echo get_option('fb_number'); ?>"></td>
- </tr>
- <tr>
- <td style="padding-right:10px;">Width of Comment Div</td>
- <td><input type="text" name="fb_width" value="<?php echo get_option('fb_width'); ?>"></td>
- </tr>
- <tr>
- <td style="padding-right:10px;">Number of Connections to show in Like Widget</td>
- <td><input type="text" name="fb_connections" value="<?php echo get_option('fb_connections'); ?>"></td>
- </tr>
- <tr>
- <td style="padding-right:10px;">Width of Sidebar Widget</td>
- <td><input type="text" name="fb_widget" value="<?php echo get_option('fb_widget'); ?>"></td>
- </tr>
- <tr>
- <td style="padding-right:10px;">Display a like button below the post?</td>
- <td><select name="fb_location" id="fb_location">
- <option name="fb_location_yes" value="<?php echo get_option('fb_location_yes'); ?>">Yes</option>
- <option name="fb_location_no" value="<?php echo get_option('fb_location_no'); ?>">No</option>
- </select>
- </td>
- </tr>
- </tbody>
- </table>
- <p class="submit">
- <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
- </p>
- </div>
- </form>
- </div>
- <?php }
- add_filter('comments_template', 'fb_comments');
- function fb_comments() {
- echo '<fb:comments xid="'.get_option('fb_app_id').'" numposts="'.get_option('fb_number').'" width="'.get_option('fb_width').'"></fb:comments>';
- }
- add_action('wp_footer', 'fb_js');
- function fb_js(){
- ?>
- <div id="fb-root"></div>
- <script>
- window.fbAsyncInit = function() {
- FB.init({appId: '<?php echo get_option('fb_app_id'); ?>', status: true, cookie: true,
- xfbml: true});
- };
- (function() {
- var e = document.createElement('script'); e.async = true;
- e.src = document.location.protocol +
- '//connect.facebook.net/en_US/all.js';
- document.getElementById('fb-root').appendChild(e);
- }());
- </script>
- <?php }
- add_action('wp_head', 'og_head');
- function og_head(){ ?>
- <meta property="og:title" content="<?php the_title(); ?>" />
- <meta property="og:type" content="blog" />
- <meta property="og:url" content="<?php the_permalink(); ?>" />
- <?php if ($src){ ?>
- <meta property="og:image" content="<?php echo $src; ?>" />
- <?php } ?>
- <?php $special_text = get_the_content(); ?>
- <meta property="og:description" content="<?php echo strip_tags($special_text); ?>" />
- <meta property="og:site_name" content="<?php bloginfo('name'); ?>" />
- <meta property="fb:app_id" content="<?php echo get_option('fb_app_id'); ?>" />
- <?php }
- add_action("widgets_init", array('Recommendations_Widget', 'register'));
- class Recommendations_Widget {
- function control(){
- echo '<fb:friendpile>';
- }
- function widget($args){
- echo $args['before_widget'];
- echo '<fb:recommendations width="'.get_option('fb_widget').'"></fb:recommendations>';
- echo $args['after_widget'];
- }
- function register(){
- register_sidebar_widget('Facebook Recommendations Widget', array('Recommendations_Widget', 'widget'));
- register_widget_control('Facebook Recommendations Widget', array('Recommendations_Widget', 'control'));
- }
- }
- add_action("widgets_init", array('Activity_Feed', 'register'));
- class Activity_Feed {
- function control(){
- echo '<fb:friendpile>';
- }
- function widget($args){
- echo $args['before_widget'];
- echo '<fb:activity width="'.get_option('fb_widget').'"></fb:recommendations>';
- echo $args['after_widget'];
- }
- function register(){
- register_sidebar_widget('Facebook Activity Feed', array('Activity_Feed', 'widget'));
- register_widget_control('Facebook Activity Feed', array('Activity_Feed', 'control'));
- }
- }
- add_action("widgets_init", array('Like_Box', 'register'));
- class Like_Box {
- function control(){
- echo '<fb:friendpile>';
- }
- function widget($args){
- echo $args['before_widget'];
- echo '<fb:like-box profile_id="'.get_option('fb_app_id').'" width="'.get_option('fb_widget').'" connections="10"></fb:like-box>';
- echo $args['after_widget'];
- }
- function register(){
- register_sidebar_widget('Facebook Like Box', array('Like_Box', 'widget'));
- register_widget_control('Facebook Like Box', array('Like_Box', 'control'));
- }
- }
- add_action("widgets_init", array('Like_Button', 'register'));
- class Like_Button {
- function control(){
- echo '<fb:friendpile>';
- }
- function widget($args){
- echo $args['before_widget'];
- echo '<fb:like href="'.the_permalink().'" width="'.get_option('fb_widget').'"></fb:like-box>';
- echo $args['after_widget'];
- }
- function register(){
- register_sidebar_widget('Facebook Like Button', array('Like_Button', 'widget'));
- register_widget_control('Facebook Like Button', array('Like_Button', 'control'));
- }
- }
- function facebook_like($content)
- {
- $like_me = '<fb:like href="'.get_permalink().'"></fb:like-box>';
- return $content.$like_me;
- }
- add_filter('the_content', 'facebook_like');
Add Comment
Please, Sign In to add comment