jfb_output_facebook_callback

The WP-FB-AutoConnect jfb output facebook callback function.

Description

jfb_output_facebook_callback( (int) $redirectTo = 0, (int) $callbackName = 0 ); 

Parameters (2)

0. $redirectto (int)
The redirectto.
1. $callbackname (int)
The callbackname.

Usage

  1. if ( !function_exists( 'jfb_output_facebook_callback' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'wp-fb-autoconnect/Main.php'; 
  3.  
  4. // The redirectto. 
  5. $redirectto = -1; 
  6.  
  7. // The callbackname. 
  8. $callbackname = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = jfb_output_facebook_callback($redirectto, $callbackname); 
  12.  

Defined (1)

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

/Main.php  
  1. function jfb_output_facebook_callback($redirectTo=0, $callbackName=0) 
  2. //Make sure the plugin is setup properly before doing anything 
  3. global $jfb_name, $jfb_version, $opt_jfb_ask_perms, $opt_jfb_valid, $jfb_nonce_name; 
  4. global $jfb_js_callbackfunc, $opt_jfb_ask_stream, $jfb_callback_list; 
  5. if( !get_option($opt_jfb_valid) ) return; 
  6.  
  7. //Get out our params 
  8. if( !$redirectTo ) $redirectTo = htmlspecialchars($_SERVER['REQUEST_URI']); 
  9. if( !$callbackName )$callbackName = $jfb_js_callbackfunc; 
  10. echo "\n<!-- $jfb_name Callback v$jfb_version -->\n"; 
  11.  
  12. //Make sure we haven't already output a callback with this name 
  13. if( in_array($callbackName, $jfb_callback_list) ) 
  14. echo "\n<!--jfb_output_facebook_callback has already generated a callback named $callbackName! Skipping.-->\n"; 
  15. return; 
  16. else 
  17. array_push($jfb_callback_list, $callbackName); 
  18.  
  19. //Output an html form that we'll submit via JS once the FB popup is dismissed. 
  20. //NOTE: Regardless of where we submit the form to (the "action"), the FB login is handled completely by _process_login.php,  
  21. //which runs in the "init" action and then immediately redirects elsewhere. We could basically submit this form to  
  22. //anywhere and it'd still work; I just use wp-login.php for simplicity (and because WP will guarantee that it's https 
  23. //if ssl logins are required). 
  24. //NOTE: I was previously submitting to wp_login_url(), which broke WPEngine. They specifically require I post to  
  25. // site_url(), with the 'login_post' param...) 
  26. ?><form id="wp-fb-ac-fm" name="<?php echo $callbackName ?>_form" method="post" action="<?php echo esc_url(site_url( 'wp-login.php', 'login_post' )); ?>" > 
  27. <input type="hidden" name="redirectTo" value="<?php echo $redirectTo?>" /> 
  28. <input type="hidden" name="access_token" id="jfb_access_token" value="0" /> 
  29. <input type="hidden" name="fbuid" id="jfb_fbuid" value="0" /> 
  30. <?php wp_nonce_field ($jfb_nonce_name, $jfb_nonce_name) ?> 
  31. <?php do_action('wpfb_add_to_form'); ?>  
  32. </form> 
  33.  
  34. <?php //Output the JS callback, which Facebook will automatically call once it's been logged in. ?> 
  35. <script type="text/javascript">//<!-- 
  36. function <?php echo $callbackName ?>() 
  37. //wpfb_add_to_js: An action to allow the user to inject additional JS to be executed before the login takes place 
  38. <?php do_action('wpfb_add_to_js', $callbackName); ?> 
  39. //wpfb_add_to_js: Finished 
  40.  
  41. //Make sure the user logged into Facebook (didn't click "cancel" in the login prompt) 
  42. FB.getLoginStatus(function(response) 
  43. if (!response.authResponse) 
  44. //Note to self: if this is happening unexpectedly, it could be because third-party browser cookies are disabled. 
  45. <?php echo apply_filters('wpfb_login_rejected', ''); ?> 
  46. return; 
  47.  
  48. //Set the uid & access token to be sent in to our login script 
  49. jQuery('#jfb_access_token').val(response.authResponse.accessToken); 
  50. jQuery("#jfb_fbuid").val(response.authResponse.userID); 
  51.  
  52. //Submit the login and close the FB.getLoginStatus call 
  53. <?php echo apply_filters('wpfb_submit_loginfrm', "document." . $callbackName . "_form.submit();\n" ); ?> 
  54. }) 
  55. //--></script> 
  56. <?php