WordPress.org

Forums

WP-Members
[resolved] Showing "Real" IP Address? (13 posts)

  1. Nono
    Member
    Posted 1 year ago #

    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/

  2. Chad Butler
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  3. Nono
    Member
    Posted 1 year ago #

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

    Thanks.

  4. Nono
    Member
    Posted 1 year ago #

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

  5. Chad Butler
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  6. Nono
    Member
    Posted 1 year ago #

    Awesome. Merci buckets.

  7. Nono
    Member
    Posted 1 year ago #

    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.

  8. Chad Butler
    Member
    Plugin Author

    Posted 1 year ago #

    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).

  9. Nono
    Member
    Posted 1 year ago #

    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.

  10. Chad Butler
    Member
    Plugin Author

    Posted 1 year ago #

    @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.

  11. Chad Butler
    Member
    Plugin Author

    Posted 1 year ago #

    @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.

  12. Nono
    Member
    Posted 1 year ago #

    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.

  13. Nono
    Member
    Posted 1 year ago #

    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' );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic