verygoodplugins

Untitled

May 29th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.18 KB | None | 0 0
  1. add_filter('wpf_crm_object_type', 'set_object_type');
  2.  
  3. function set_object_type($object_type) {
  4.    
  5.     return 'WP_User__c';
  6. }
  7.  
  8. //WP Fusion allow IP
  9.  
  10. function unlock_by_ip( $can_access, $user_id, $post_id ) {
  11.  
  12.     if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
  13.  
  14.         // IP from share internet
  15.         $ip = $_SERVER['HTTP_CLIENT_IP'];
  16.  
  17.     } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
  18.  
  19.         // IP passed from proxy
  20.         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  21.  
  22.     } else {
  23.  
  24.         // Normal IP
  25.         $ip = $_SERVER['REMOTE_ADDR'];
  26.  
  27.     }
  28.    
  29.     if ( $ip == '13.111.63.226' ) {$can_access = true;} // Pardot
  30.    
  31.     if ( $ip == '104.236.230.137' ) {$can_access = true;} // Feedotter
  32.  
  33.     return $can_access;
  34.  
  35. }
  36.  
  37. add_filter( 'wpf_user_can_access', 'unlock_by_ip', 10, 3 );
  38. add_filter( 'wpf_user_can_access', 'wpf_allow_rss', 10, 3 );
  39. add_filter( 'wpf_user_can_access_archive', 'unlock_by_ip', 10, 3 );
  40. add_filter( 'wpf_user_can_access_archive', 'wpf_allow_rss', 10, 3 );
  41.  
  42. // WP Fusion Magic Link login as real user
  43.  
  44. // Disbale "Allow URL Login" in WP Fusion's settings for this to work properly.
  45. // URL format should be https://mysite.com?cid=123&key=KEY
  46. // Where "123" is the contact ID to be logged in, and KEY is the access key from the WPF settings
  47. function wpf_true_auto_login() {
  48. if( ! isset( $_GET['cid'] ) ) {
  49. return;
  50.     }
  51. if( ! isset( $_GET['key'] ) || $_GET['key'] != wp_fusion()->settings->get( 'access_key' ) ) {
  52. return;
  53.     }
  54. $contact_id = sanitize_text_field( $_GET['cid'] );
  55. $user_id = wp_fusion()->user->get_user_id( $contact_id );
  56. if( empty( $user_id ) || user_can( $user_id, 'manage_options' ) ) {
  57. return;
  58.     }
  59. $user = get_user_by( 'id', $user_id );
  60. // Login
  61. wp_set_current_user( $user_id, $user->user_login );
  62. wp_set_auth_cookie( $user_id );
  63. do_action( 'wp_login', $user->user_login, $user );
  64. }
  65. add_action( 'after_setup_theme', 'wpf_true_auto_login' );
  66.  
  67. // WP Fusion Exctra class Filter
  68. function custom_wpf_query_args( $query_args, $method ) {
  69.  
  70.     if ( 'get_contact_id' == $method ) {
  71.  
  72.         $query_args['q'] = str_replace( 'Email', 'Email__c', $query_args['q'] );
  73.  
  74.     }
  75.  
  76.     return $query_args;
  77. }
  78.  
  79. add_filter( 'wpf_salesforce_query_args', 'custom_wpf_query_args', 10, 2 );
Add Comment
Please, Sign In to add comment