fb_login_wid

The Facebook Login Widget fb login wid class.

Defined (1)

The class is defined in the following location(s).

/login_afo_widget.php  
  1. class fb_login_wid extends WP_Widget { 
  2. private $appId, $appSecret; 
  3. public function __construct() { 
  4. include_once dirname( __FILE__ ) . '/facebook/facebook.php'; 
  5. $this->appId = get_option('afo_fb_app_id'); 
  6. $this->appSecret = get_option('afo_fb_app_secret'); 
  7. add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_styles' ) ); 
  8. parent::__construct( 
  9. 'fb_login_wid',  
  10. 'FB Login Widget AFO',  
  11. array( 'description' => __( 'This is a facebook social login form in the widget.', 'facebook-login-afo' ), ) 
  12. ); 
  13.  
  14. public function widget( $args, $instance ) { 
  15. extract( $args ); 
  16.  
  17. $wid_title = apply_filters( 'widget_title', $instance['wid_title'] ); 
  18.  
  19. echo $args['before_widget']; 
  20. if ( ! empty( $wid_title ) ) 
  21. echo $args['before_title'] . $wid_title . $args['after_title']; 
  22. $this->loginForm( $args['widget_id'] ); 
  23. echo $args['after_widget']; 
  24.  
  25. public function update( $new_instance, $old_instance ) { 
  26. $instance = array(); 
  27. $instance['wid_title'] = strip_tags( $new_instance['wid_title'] ); 
  28. return $instance; 
  29.  
  30.  
  31. public function form( $instance ) { 
  32. $wid_title = @$instance[ 'wid_title' ]; 
  33. ?> 
  34. <p><label for="<?php echo $this->get_field_id('wid_title'); ?>"><?php _e('Title:'); ?> </label> 
  35. <input class="widefat" id="<?php echo $this->get_field_id('wid_title'); ?>" name="<?php echo $this->get_field_name('wid_title'); ?>" type="text" value="<?php echo $wid_title; ?>" /> 
  36. </p> 
  37. <?php  
  38.  
  39. public function social_logins() {  
  40. ?> 
  41. <div class="social-login-text"><?php _e('Login with', 'facebook-login-afo');?> </div> <a href="javascript:void(0);" onClick="FBLogin();"><img src="<?php echo plugins_url( 'facebook.png' , __FILE__ );?>" alt="<?php _e('Fb Connect', 'facebook-login-afo');?>" title="<?php _e('Login with facebook', 'facebook-login-afo');?>" /></a> 
  42. <?php do_action( 'additional_logins_afo' ); ?> 
  43. <?php 
  44.  
  45. public function loginForm( $wid_id = '' ) { 
  46. global $post; 
  47. $default_login_form_hooks = get_option('default_login_form_hooks');  
  48. $this->LoadScript(); 
  49. if(!is_user_logged_in()) { 
  50. ?> 
  51. <div id="log_forms" class="log_forms <?php echo $wid_id;?>"> 
  52. <?php $this->error_message();?> 
  53. <form name="login" id="login" method="post" action=""> 
  54. <input type="hidden" name="option" value="afo_user_login" /> 
  55. <input type="hidden" name="redirect" value="<?php echo esc_url( $redirect ); ?>" /> 
  56. <div class="log-form-group"> 
  57. <label for="username"><?php _e('Username', 'lwa');?> </label> 
  58. <input type="text" name="user_username" required="required"/> 
  59. </div> 
  60. <div class="log-form-group"> 
  61. <label for="password"><?php _e('Password', 'lwa');?> </label> 
  62. <input type="password" name="user_password" required="required"/> 
  63. </div> 
  64.  
  65. <?php $default_login_form_hooks == 'Yes'?do_action('login_form'):'';?> 
  66.  
  67. <div class="log-form-group"><input name="login" type="submit" value="<?php _e('Login', 'lwa');?>" /></div> 
  68.  
  69. <div class="locial-logins"><?php $this->social_logins();?></div> 
  70. </form> 
  71. </div> 
  72. <?php  
  73. } else { 
  74. $current_user = wp_get_current_user(); 
  75.  
  76. $link_with_username = __('Howdy, ', 'facebook-login-afo') . $current_user->display_name; 
  77. ?> 
  78. <div class="logged-in"><?php echo $link_with_username;?> | <a href="<?php echo wp_logout_url(site_url()); ?>" title="<?php _e('Logout', 'facebook-login-afo');?>"><?php _e('Logout', 'facebook-login-afo');?></a></div> 
  79. <?php  
  80.  
  81. private function LoadScript() { 
  82. ?> 
  83. <script type="text/javascript"> 
  84. window.fbAsyncInit = function() { 
  85. FB.init({ 
  86. appId : "<?php echo $this->appId?>", // replace your app id here 
  87. status : true,  
  88. cookie : true,  
  89. xfbml : true  
  90. }); 
  91. }; 
  92. (function(d) { 
  93. var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
  94. if (d.getElementById(id)) {return;} 
  95. js = d.createElement('script'); js.id = id; js.async = true; 
  96. js.src = "//connect.facebook.net/en_US/all.js"; 
  97. ref.parentNode.insertBefore(js, ref); 
  98. }(document)); 
  99.  
  100. function FBLogin() { 
  101. FB.login(function(response) { 
  102. if(response.authResponse) { 
  103. window.location.href = "<?php echo site_url();?>?option=fblogin"; 
  104. }, {scope: 'email, user_likes'}); 
  105. </script> 
  106. <?php 
  107.  
  108. public function error_message() { 
  109. if(isset($_SESSION['msg']) and $_SESSION['msg']) { 
  110. echo '<div class="'.$_SESSION['msg_class'].'">'.$_SESSION['msg'].'</div>'; 
  111. unset($_SESSION['msg']); 
  112. unset($_SESSION['msg_class']); 
  113.  
  114. public function register_plugin_styles() { 
  115. wp_enqueue_style( 'style_login_widget', plugins_url( 'facebook-login-afo/style_login_widget.css' ) ); 
  116.  
  117. }