WordPress.org

Support

Support » Plugins and Hacks » WP-Members: Membership Framework » [Resolved] Showing "Real" IP Address?

[Resolved] Showing "Real" IP Address?

  • The plugin runs on a site that uses a proxy and only returns variations of 10.x.x.x in the user IP address when registering. Is there a way to use HTTP_X_FORWARDED_FOR (which works for us) assuming you are using REMOTE_ADDR?

    Thanks for the reply.

    http://wordpress.org/plugins/wp-members/

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Chad Butler

    @cbutlerjr

    It does use REMOTE_ADDR.

    You could write a filter function hooked to wpmem_register_data to filter the value for $fields[‘wpmem_reg_ip’]

    See: http://rocketgeek.com/plugins/wp-members/users-guide/filter-hooks/wpmem_register_data/ for hook documentation.

    See: http://rocketgeek.com/plugins/wp-members/users-guide/filter-hooks/ for a full list of hooks.

    Very cool. I will experiment with that. I patched your code, for now, which I know is uncool. Will improve with your recommendation.

    Thanks.

    If I put the code in functions.php in the same folder, will it be overwritten with the next plugin update?

    Plugin Author Chad Butler

    @cbutlerjr

    Yes, it should go in functions.php, but that should be in your theme folder. No customizations should go in the plugin folder or you’ll lose them when you update.

    Awesome. Merci buckets.

    Hi again, Chad.

    I have tried multiple times but I keep on failing. I put these in functions.php of my theme:

    function my_register_data( $fields )
    {
    	$fields['wpmem_reg_ip'] = '127.0.0.1';
    
    	return $fields;
    }
    
    add_filter( 'wpmem_register_data', 'my_register_data' );
    add_action( 'wpmem_pre_register_data', 'my_register_data', 1 );

    but the code above does not update wpmem_reg_ip. Anything I am doing wrong?

    Thanks.

    Plugin Author Chad Butler

    @cbutlerjr

    You used the word “update” in your question, so I’m assuming that you are talking about “updating” the user (as opposed to a new registration)?

    The IP is only captured by the plugin at registration, not user update. Also, those two hooks are only part of the the registration process. There are other filter hooks in the user update state.

    Otherwise, that code should work just fine (although you only need one – I would use the filter and not the action).

    Hi again. Sorry if it didn’t really appear clear when the IP capture should happen.

    So, finally, I wanted to correct the IP address being captured/sent during moderated user registration. That explains my code snippet above which would supposedly override/update the IP of the user.

    I looked at wpmem_email_notify, wpmem_email_newmod and wpmem_email_newreg but I have no idea how $email_content is structured and how I would override the contents of $fields before they get sent by email and saved to the dbase. (Also not sure if I am looking at the correct hooks, at all.)

    Thanks for your time spent replying.

    Plugin Author Chad Butler

    @cbutlerjr

    @nono – Your question actually helped me track down an item in need of correction…

    In the registration function, when the filter was added to allow filtering the $fields values prior to finalizing registration, there were two elements that were missed – after the values are added with wp_insert_user and the usermeta are added, then the IP and the URL they registered on are added. Those two update_user_meta calls did not use the value from the $fields array, which is why you weren’t getting an updated value.

    I have an update that should be coming out tonight or tomorrow. But in the meantime, if you change line 197 in wp-members-register.php from this:

    update_user_meta( $fields['ID'], 'wpmem_reg_ip', $_SERVER['REMOTE_ADDR'] );

    to this:

    update_user_meta( $fields['ID'], 'wpmem_reg_ip', $fields['wpmem_reg_ip'] );

    then you should be fine.

    You should also change line 200 from:

    update_user_meta( $fields['ID'], 'wpmem_reg_url', $_REQUEST['redirect_to'] );

    to:

    update_user_meta( $fields['ID'], 'wpmem_reg_url', $fields['wpmem_reg_url'] );

    This should correct any issues with the email notification as well, as the email process comes after finalizing registration, so the values would already be filtered by that point.

    Plugin Author Chad Butler

    @cbutlerjr

    @nono – Your question actually helped me track down an item in need of correction…

    In the registration function, when the filter was added to allow filtering the $fields values prior to finalizing registration, there were two elements that were missed – after the values are added with wp_insert_user and the usermeta are added, then the IP and the URL they registered on are added. Those two update_user_meta calls did not use the value from the $fields array, which is why you weren’t getting an updated value.

    I need to spend a little time reviewing this to determine the appropriate update needed.

    Hey Chad. That did the trick! Thank you.

    I didn’t want to suggest that there must something in the plugin code that’s overwriting the values. Glad that you were the one to catch the bug.

    Will look forward to the update, Meanwhile, I am happy with the patch I did to the code.

    In case anyone would like to reference this, here’s my code snippet:

    function my_register_data( $fields )
    {
    	if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    		$fields['wpmem_reg_ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
    	}
    
    	return $fields;
    }
    
    add_filter( 'wpmem_register_data', 'my_register_data' );
Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[Resolved] Showing "Real" IP Address?’ is closed to new replies.
Skip to toolbar