• Resolved wpwedding

    (@wpwedding)


    I’m working on a wordpress website for my wedding and have installed the ‘RSVP‘ plugin to handle all the responses for our guests. The plugin allows you to go direct to your invite by visiting http://www.domain.com/rsvp?firstName=Bob&Lastname=Smith&PassCode=xxx (and you can include other variables in too).

    We want to use the same information from our users’ profiles to create the invites, therefore firstname/lastname/id etc will all match. This side is easy and we can handle the creation of the users/invites.

    What I’m struggling with, is that we want the RSVP url in the menu to be automatically generated based on the logged in user. For example, if the following user is logged in:

    UserID: 12345
    FirstName: Dave
    LastName: Jones

    … the url would automatically be http://www.domain.com/rsvp?FirstName=Dave&LastName=Jones&PassCode=12345

    Any ideas?

Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter wpwedding

    (@wpwedding)

    Anyone?

    Are you just adding an RSVP item to the menu?

    Thread Starter wpwedding

    (@wpwedding)

    I’ve added a new page called “rsvp” and then called the plugin from within the page. What I want to do is make that url for the page use specified variables as shown in the original post, so that the individual logged in sees their own rsvp page rather than having to enter any details.

    You could use something like this, but be sure to replace 9999 with you RSVP page id:

    function add_rsvp_page_url_args( $item ) {
    	$rsvp_id = '9999'; // RSVP Page ID
    	$user_id = get_current_user_id();
    	$item_id = !empty($item->object_id) ? intval($item->object_id) : 0;
    
    	if ( !is_admin() && $user_id && $item_id && $item_id === intval($rsvp_id) ) {
    		$first = get_user_meta( $user_id, 'first_name', true );
    		$last = get_user_meta( $user_id, 'last_name', true );
    
    		if ( $first && $last ) {
    			$url_args = array(
    				'firstName' => $first,
    				'lastName' => $last,
    				'passcode' => $user_id
    			);
    
    			$item->url = add_query_arg( $url_args, $item->url );
    		}
    	}
    
    	return $item;
    }
    add_filter( 'wp_setup_nav_menu_item', 'add_rsvp_page_url_args' );

    It could be modified to automatically find your RSVP page so you don’t have to fill in the ID but the way the RSVP plugin is setup would make it a considerably slower function.

    Thread Starter wpwedding

    (@wpwedding)

    I’m assuming this just needs to be popped in the theme’s functions.php file?

    That should work.

    Thread Starter wpwedding

    (@wpwedding)

    I’ve popped it in there, but it doesn’t appear to have worked 🙁

    Any other suggestions?

    Did you plug in your rsvp page id?

    Thread Starter wpwedding

    (@wpwedding)

    Yup – the page number (18) has been added to the code which has been added to the functions.php file on the relevant theme

    How was the page added to the menu? Is it a custom link? For it to work it has to be added to the menu from the pages list.

    Thread Starter wpwedding

    (@wpwedding)

    Yup – added the normal way and you just put rsvp-pluginhere on the page to activate the plugin. The plugin itself then let’s you pass the three (or two dependant on your settings) arguments through when visiting the relevant page (in my case /rsvp.

    Also make sure you are testing with an account that has both name fields filled in.

    Thread Starter wpwedding

    (@wpwedding)

    Yup – doing that.

    The user record is ID number 2 with the name Jane Doe (split between first and last name obviously). The rsvp has the same first and last name (including the same case) and a passcode of 2.

    If you visit the url on its own – “http://www.mydomain.com/rsvp?firstName=Jane&lastName=Doe&passcode=2” – then it works a treat and takes them straight to their rsvp page without asking for a passcode, which is my mission.

    However, if you log in as that user and click the rsvp button, it goes to the /rsvp page but asks you for the passcode to load the rsvp (the bit I’m trying to avoid).

    Thread Starter wpwedding

    (@wpwedding)

    I’ve also tried tweaking the permalinks section in case the trailing / was causing an issue – but that doesn’t appear to have sorted it either.

    Thread Starter wpwedding

    (@wpwedding)

    Finally – I’ve managed to get it to work. I had to add a new menu and re-add the links and then it worked!

    Thanks for your help!

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘Custom URL based on plugin variables’ is closed to new replies.