Untitled

 avatar
unknown
plain_text
6 months ago
3.7 kB
16
Indexable
<?php
/**
 * Template Name: User Events Basic
 */

get_header();

// Check if EME is active
if (!function_exists('eme_get_events')) {
	?>
	<div class="container">
		<p>Events Made Easy plugin is not active.</p>
	</div>
	<?php
	get_footer();
	return;
}

// Check if user is logged in
if (!is_user_logged_in()) {
	?>
	<div class="container">
		<p>Please log in to view your events.</p>
	</div>
	<?php
	get_footer();
	return;
}

// Get current user ID
$current_user_id = get_current_user_id();

// Get all events and filter by current user
$events = eme_get_events();
$user_events = array();

// Debug information
echo '<div style="background: #f5f5f5; padding: 10px; margin: 10px; border: 1px solid #ddd;">';
echo '<h3>Debug Information:</h3>';
echo '<p>Current User ID: ' . $current_user_id . '</p>';
echo '<p>Total Events Found: ' . count($events) . '</p>';

foreach ($events as $event) {
	// Try to get the event owner
	$event_author = isset($event->event_author) ? $event->event_author : 0;
	echo '<p>Event ID: ' . $event->event_id . ' | Owner ID: ' . (isset($event_author['person_id']) ? $event_author['person_id'] : 'None') . '</p>';
	
	// Check if this event belongs to current user
	if (isset($event_author['person_id']) && $event_author['person_id'] == $current_user_id) {
		$user_events[] = $event;
	}
}
echo '</div>';
?>

<div class="container">
	<h1>My Events</h1>

	<?php if (empty($user_events)) : ?>
		<p>No events found. 
		<?php if (current_user_can('edit_posts')) : ?>
			You can create events from the WordPress admin panel.
		<?php endif; ?>
		</p>
	<?php else : ?>
		<div class="events-list">
			<?php foreach ($user_events as $event) : ?>
				<div class="event-item">
					<h2><?php echo esc_html($event->event_name); ?></h2>
					
					<div class="event-date">
						<?php 
						$event_date = eme_get_event_datetime($event);
						echo esc_html($event_date);
						?>
					</div>

					<?php 
					// Get event description using EME function
					$description = eme_get_event_description($event);
					if (!empty($description)) : ?>
						<div class="event-description">
							<?php echo wp_kses_post(wp_trim_words($description, 20)); ?>
						</div>
					<?php endif; ?>

					<div class="event-links">
						<?php
						// Get event URL using EME function
						$event_url = eme_event_url($event);
						?>
						<a href="<?php echo esc_url($event_url); ?>" class="event-link">View Details</a>
						
						<?php if (current_user_can('edit_posts')) : ?>
							<a href="<?php echo esc_url(admin_url('admin.php?page=events-manager&eme_admin_action=edit_event&event_id=' . $event->event_id)); ?>" 
							   class="event-edit-link">Edit Event</a>
						<?php endif; ?>
					</div>
				</div>
			<?php endforeach; ?>
		</div>
	<?php endif; ?>
</div>

<style>
	.events-list {
		max-width: 800px;
		margin: 0 auto;
		padding: 20px;
	}

	.event-item {
		margin-bottom: 30px;
		padding: 20px;
		border: 1px solid #ddd;
		border-radius: 4px;
		background: #fff;
	}

	.event-item h2 {
		margin: 0 0 10px;
		color: #333;
	}

	.event-date {
		color: #666;
		margin-bottom: 10px;
		font-size: 0.9em;
	}

	.event-description {
		margin: 10px 0;
		line-height: 1.6;
	}

	.event-links {
		margin-top: 15px;
	}

	.event-link, .event-edit-link {
		display: inline-block;
		padding: 5px 15px;
		text-decoration: none;
		border-radius: 3px;
		margin-right: 10px;
	}

	.event-link {
		background-color: #0073aa;
		color: #fff;
	}

	.event-edit-link {
		background-color: #f0f0f0;
		color: #333;
	}

	.event-link:hover {
		background-color: #005177;
		color: #fff;
	}

	.event-edit-link:hover {
		background-color: #e0e0e0;
	}
</style>

<?php
get_footer();
?>
Editor is loading...
Leave a Comment