Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to with Gabey D: Adding invitations to Event Manager (Basic)


  • godavid33
    Participant

    @godavid33

    During my adventures in buddypress I occasionally find something that there are answers for out there, but that take a little while to conglomerate into one feasible solution. I hope to alleviate that problem for those afflicted with a pittance of perseverance. In layman’s terms, I’m here to make your job easier 🙂

    So here is how I solved adding invites to Events Manager plugin:

    In functions.php:

    
    function invite_friend_to_event(){
    	
    	$msg_args = array(
    	'sender_id' => 1, // 1 = admin
    	'recipients' => $_POST["user_id"],
    	'subject' => 'Event invitation!',
    	'content' => 'You\'ve been invited to an event of immense proportions.'
    	);
    	$thread_id = messages_new_message($msg_args);   
      
    	echo "Success - invitation sent to user id: ".$_POST["user_id"];
    	die();
    }
    
    add_action('wp_ajax_invite_friend', 'invite_friend_to_event');
    add_action( 'wp_ajax_nopriv_invite_friend', 'invite_friend_to_event' );
    

    On the single.php page:

    
    				<script>
    				
    					function invite_friends(userid){
    						jQuery.ajax({
    							url:"<?php echo admin_url('admin-ajax.php'); ?>",
    							type:'POST',
    							data: { action : 'invite_friend', user_id : userid },	
    							dataType : 'html',								
    							success:function(results)
    							{
    								//  alert(results);
    								alert("Data sent to"+userid+" Results:"+results);
    								//alert(results);
    							}
    						});	
    					}
    				</script>
    				<?php if(get_post_type($post) == "event"): ?>
    					<h1 class="small">Invite Friends</h1>
    					<div id="invite-friends" style="background-color:rgb(220,220,220);">
    						<?php 
    						
    							$uid = get_current_user_id();
    							$friends_list = friends_get_friend_user_ids( $uid, false, true ); 
    
    							foreach($friends_list as $friend):
    								$friend_obj = get_userdata($friend['user_id']);
    							?>
    								<div class="invitee" style="width:150px;height: 180px;display:inline-block;margin:10px;text-align:center;background-color:white;padding:5px;">
    									<h2 class="small"><?php echo $friend_obj->first_name." ".$friend_obj->last_name; ?></h2>
    									<?php echo get_avatar( $friend['user_id'], 64 ); ?>
    									<button class='btn-success btn' onclick="invite_friends('<?php echo $friend['user_id']; ?>');" style="margin-top:5px;"><h3 class='small white'>Invite</h3></button>
    								</div>
    							<?php
    							endforeach;
    						?>
    					</div>
    				<?php endif; ?>
    

    I may come back and explain this a bit more later, but basically what you’re doing is setting up an ajax function, and calling that function on button click w/ javascript AJAX function. There is likely a better way to do this, and if you have your own custom solution to this problem or have any feedback, I’d love to hear about it! It can, should, and will be extended to include keeping track of who you’ve already sent invites to. As of now, this is just the core functionality of sending an invite by levying the messaging system and ajax.

    Hope this helps someone,
    Gabe

    **EDIT: Apologies for excess indentation, I copied it directly from my editor**

  • The topic ‘How to with Gabey D: Adding invitations to Event Manager (Basic)’ is closed to new replies.
Skip to toolbar