WordPress.org

Ready to get started?Download WordPress

Forums

Invite Anyone
Replace Accept URL With My Own Link (18 posts)

  1. takinglife2themax
    Member
    Posted 4 months ago #

    Hi there Boone,
    This is an awesome plugin! I've been having some issues with the accept invitation link. I can't figure out why it always gives me a 404 error.

    I'm trying to create a workaround for this that will allow me to use my own link and still mark the invitation as accepted automatically. I'm using WP-Achievements at the moment, and I want to be able to actually trigger an achievement when someone's invite is accepted.

    Can you please point me in the right direction? Specifically, which plugin files and functions do I need to modify to accomplish this?

    Thanks again for creating such an incredible plugin, and keep up the good work!

    https://wordpress.org/plugins/invite-anyone/

  2. Boone Gorges
    Moderator
    Plugin Author

    Posted 4 months ago #

    takinglife2themax - I'm not sure I totally grasp what you're trying to do, but if you want to be able to trigger the invitation-acceptance process manually (instead of requiring account activation), check out the function invite_anyone_activate_user() in invite-anyone/by-email/by-email.php. That should be a good starting point.

  3. bridieamelia
    Member
    Posted 3 months ago #

    Hi Boone, I'm getting the same issue. The link in the email that is generated from my end (as an example) is http://www.mydomain.com.au/register/accept-invitation/username%40gmail.com.

    When you click on it it returns to a 404 error on the website, and consequently the user cannot accept the invitation.

    Would you know why this is happening?

    Perfect plugin for my needs other than that! Thanks.

  4. bridieamelia
    Member
    Posted 3 months ago #

    Hi, I found the answer here: have you associated ther Register and Activate page in the Buddypress settings? Also make sure you test acceptance when not logged in.

    http://wordpress.org/support/topic/accept-url-gives-404-error

  5. takinglife2themax
    Member
    Posted 3 months ago #

    Hi guys,

    Thanks for your help. To answer your question Boone, I have a Membership plugin with an integrated affiliate system and I'm trying to replace the accept invite url with the affiliate referral link from my affiliate system. I am able to do this by swapping it out manually every time, but I want my users to be able to trigger the invite acceptance for WP-Achievements to recognize it.

    My Membership plugin has its own registration process, which excludes activation also. I'm just wondering if the invite_anyone_activate_user() function will conflict with the plugins normal user activation functions.

    But I'll take a look at the file.

    Thanks again.

  6. takinglife2themax
    Member
    Posted 3 months ago #

    Hi Boone,
    I have a quick question regarding the invite_anyone_wildcard_replace() function. It appears to me that this is the function that creates the accept url. This is what I want to modify to interface with the affiliate's referral link.(http://www.mydomain.com.au/register/accept-invitation/john%40gmail.com?ref=max-32)

    The ?ref=max-32 passes the referring affiliate's id to link the referral to them. My question is, will the url encoded email address confilct with the ref?

    And as far as the invite_anyone_activate_user() function is concerned, I see that the action has been added to bp_core_activated_user(). My membership plugin does hook into buddypress, but it has its own registration form. In theory, would it be possible to simply call the bp_core_activated_user() function during my membership plugin's registration process? And will I need to create an add_action for the invite_anyone_register_screen_message() function, in order to validate the invitation when the user clicks the accept link (before they arrive at the registration page)?

  7. Boone Gorges
    Moderator
    Plugin Author

    Posted 3 months ago #

    takinglife2themax - It looks like there's a filter on the $accept_link in invite_anyone_wildcard_replace(), so you should be able to do something like this:

    function bbg_add_ref_max( $email ) {
        return add_query_arg( 'ref', 'max-32', $email );
    }
    add_filter( 'invite_anyone_accept_url', 'bbg_add_ref_max' );

    I don't see any reason why that would interfere with the parsing of the email address, but if it does, please let me know.

    > In theory, would it be possible to simply call the bp_core_activated_user() function during my membership plugin's registration process?

    Yes. Not only is it possible, but it is recommended, if you're going to skip BP's registration process.

    > And will I need to create an add_action for the invite_anyone_register_screen_message() function, in order to validate the invitation when the user clicks the accept link (before they arrive at the registration page)?

    This is a little late to be validating the invitation - at this point, the page has already begun to render. If you are going to need to be able to redirect away from the requested URL based on the results of the validation, you'll want to hook in earlier; see invite_anyone_bypass_registration_lock() for an example. If the only validation you need is to display a message, then yes, invite_anyone_register_screen_message() is probably the right place. (add_action( 'accept_email_invite_before', 'whatever_your_callback_is' ))

  8. takinglife2themax
    Member
    Posted 3 months ago #

    Thanks Boone!
    The response you provided was an amazing help. Especially the function for filtering invite_anyone_accept_url. I see that the filter originally looks like this: $accept_link = apply_filters( 'invite_anyone_accept_url', bp_get_root_domain() . '/' . bp_get_signup_slug() . '/accept-invitation/' . urlencode( $email ) );
    With the accept url filtering function that you provided, will bp_get_root_domain(), bp_get_signup_slug(), and the /accept-invitation/ parts of the URL be added as well? Ideally, I would like to replace bp_get_root_domain() and bp_get_signup_slug() with my own url. Is that possible without changing the invite anyone core files?

  9. Boone Gorges
    Moderator
    Plugin Author

    Posted 3 months ago #

    > With the accept url filtering function that you provided, will bp_get_root_domain(), bp_get_signup_slug(), and the /accept-invitation/ parts of the URL be added as well? Ideally, I would like to replace bp_get_root_domain() and bp_get_signup_slug() with my own url. Is that possible without changing the invite anyone core files?

    Yes. The code snippet I gave you should go in a custom plugin or theme file, separate from Invite Anyone. Here's a great introduction to the WordPress plugins API: http://www.smashingmagazine.com/2012/02/16/inside-wordpress-actions-filters/ Good luck!

  10. takinglife2themax
    Member
    Posted 3 months ago #

    Thanks again Boone.
    I'm still a bit new to action hooks and filters and the info you provided helped clear a few things up.

    I just modified the filtering function so that the inviter's affiliate id (the max-32 part) is dynamically added based on the logged in user. That's working smoothly, but I'm still getting the 404 error. I followed bridieamelia's instructions and set the register and activate pages in my buddypress settings and the only way to bypass the 404 error is to use the Buddypress registration form.

    This is a problem for me, because as I said previously, my membership plugin uses a different registration form. I do see that the accept URL is generating the link to the form for my membership plugin via bp_get_signup_slug(). The URL appears like this: http://teamextremesupport.com/member-center/join/accept-invitation/takinglife2themax%40gmail.com?ref=max-63

    I also tried changing the slug for my membership signup form from join to register, but it still returns the 404 error, unless I set the page in buddypress. Do you know of any way that I can trick the system to use the form from my membership plugin instead of the one set in buddypress?

    Your help is much appreciated, and I'm quite impressed with your support. Keep up the good work.

  11. Boone Gorges
    Moderator
    Plugin Author

    Posted 3 months ago #

    If you are using a different registration page, then you'll have to change the URL of the link when filtering 'invite_anyone_accept_url' (you can either rebuild the link, or use str_replace() to swap it out of the existing link). If you want to use any of Invite Anyone's registration forms features (like the message that says "You have been invited by x to join the site"), you will have to write that logic yourself, because IA is set up to work specifically with the BP registration page.

    If you're still having problems accessing your custom registration page, then it sounds like it's probably got nothing to do with IA or BuddyPress. You may want to contact the author of your membership plugin.

  12. takinglife2themax
    Member
    Posted 3 months ago #

    Ideally, I would like the accept url filter to appear like this:
    apply_filters( 'invite_anyone_accept_url', get_permalink($M_options['registration_page']) . '/accept-invitation/' . urlencode( $email ) );
    With the added query argument for the referral.

    My function looks like this:

    function ia_add_aff_ref( $email ) {
    	global $wpdb;
    	global $bp;
    	global $M_options;
    
    	$url = get_permalink($M_options['registration_page']);
    	$inviter_id = bp_loggedin_user_id();
    	$inviter_aff_ref = get_user_meta($inviter_id, 'affiliate_reference', true);
    
        return add_query_arg( 'ref', $inviter_aff_ref, $email );
    }
    add_filter( 'invite_anyone_accept_url', 'ia_add_aff_ref' );

    I'm just not sure how or where to use str_replace() within this function. Or would I need to create another function to swap out the bp_get_root_domain(), and the bp_get_signup_slug() parts of the URL?
    And what do you mean by rebuild the link?

  13. takinglife2themax
    Member
    Posted 3 months ago #

    I'm making progress here. As of now, I've mdified my function to replace the the bp_get_root_domain(), and the bp_get_signup_slug() parts of the URL using str_replace(), as you suggested. But somehow, I'm still getting the 404 error.

    I have no issues accessing my custom registration page when I remove the
    /accept-invitation/takinglife2themax%40gmail.com part of the URL. What I'm trying to figure out is, what's different about the Buddypress registration form that enables this URL to work? I understand that the urlencode( $email ) portion of the URL is read as an action variable, but I don't understand what makes the /accept-invitation/ part a viable URL.

    Could you please shed some light on this for me?

  14. Boone Gorges
    Moderator
    Plugin Author

    Posted 3 months ago #

    When you add /accept-invitation/foo@bar.com to the end of a WP URL, WP expects to find a page object there. In the case of BP and Invite Anyone, those items are faked, so that WP doesn't throw a 404. But your registration plugin is bypassing BP's faked pages. So you'll either have to fake the pages yourself, or do something like ?action=accept-invitation&email=foo@bar.com and then parse the data out of the $_GET global.

  15. takinglife2themax
    Member
    Posted 3 months ago #

    Ok, that makes sense.
    That's a great idea Boone. I'll turn the action and email into query arguments as you suggested. Then, I should be able to use something like this to show the validation messages: `function ia_member_register_message() {
    global $wp;
    global $M_options;
    $membership_url = get_permalink($M_options['registration_page']);
    $current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
    if ($current_url == $membership_url && $_GET['action'] == 'accept-invitation' && $email = urldecode($_GET['email']) ){
    // Then the validation logic from invite_anyone_register_screen_message()
    }
    add_action( 'accept_email_invite_before', 'ia_member_register_message' )`

    In this scenario, the one thing I'm not sure about, is the fact the the do_action( 'accept_email_invite_before' ) exists within the conditional statement that checks for $bp->current_action and action_variables, so my code may not even execute if I use an add_action for this function.

    I should be able to just call the invite_anyone_activate_user() function from within my membership plugin after the new member has been registered. So, that should be simple enough.

  16. Boone Gorges
    Moderator
    Plugin Author

    Posted 3 months ago #

    Cool, I'm glad you're getting close.

    > the fact the the do_action( 'accept_email_invite_before' ) exists within the conditional statement that checks for $bp->current_action and action_variables, so my code may not even execute if I use an add_action for this function.

    Yes. And for this reason, I would hook somewhere else. You are already doing plenty of checks to make sure that you're on the right page (the $current_url checks). So I'd suggest something like:

    add_action( 'wp', 'ia_member_register_message', 1 );

    The action 'wp' is pretty general and will fire on all pageloads. And the priority '1' ensures that it'll happen before other plugins have a chance to interfere.

  17. takinglife2themax
    Member
    Posted 3 months ago #

    Things are beginning to shape up.
    And thanks to you, I finally understand how action hooks and filters work.

    I'm still working on the invite validation message function, but I did manage to get invite_anyone_activate_user() working with my membership plugin by adding:
    add_action('bp_complete_signup', 'invite_anyone_activate_user', 10, 3);
    So now, it marks the invite as accepted (thank god), but I can't figure out why the auto-friending isn't working. I think that the $inviter_id is working, because it's recognizing the existing invite. Otherwise, it would not mark the invite as accepted. So I'm wondering if the problem lies in the user_id?

  18. takinglife2themax
    Member
    Posted 3 months ago #

    Alright, I have to retract my last statement. I was able to hook into bp_complete_signup, but I've realized that it returns this error:

    Warning: Missing argument 2 for invite_anyone_activate_user() in /home/xadmin/public_html/wp-content/plugins/invite-anyone/by-email/by-email.php on line 192

    Warning: Missing argument 3 for invite_anyone_activate_user() in /home/xadmin/public_html/wp-content/plugins/invite-anyone/by-email/by-email.php on line 192

    Warning: Cannot modify header information - headers already sent by (output started at /home/xadmin/public_html/wp-content/plugins/invite-anyone/by-email/by-email.php:192) in /home/xadmin/public_html/wp-includes/pluggable.php on line 896

    I tried changing the action hook like this:
    add_action('bp_complete_signup', 'invite_anyone_activate_user', 10, 1);, but the error persisted. I ended up having to duplicate the invite_anyone_activate_user function's contents to create my own function with only the $user_id argument. Do you think that the absence of these 2 arguments could be causing the auto-friend to fail?

Reply

You must log in to post.

About this Plugin

About this Topic