Support

Home Forums Event Espresso Premium Hide Expired Events Redux

Hide Expired Events Redux

Posted: January 16, 2019 at 3:24 pm


mdeyerinkc

January 16, 2019 at 3:24 pm

Last spring I was able to achieve my need of hiding expired events via the ESPRESSO_MY_EVENTS shortcode and some custom code in two php template files. At some point since then however, an update somewhere broke the solution. I’m trying to recreate what I did the first time, but experiencing some errors I can’t get past.

Here’s what I currently have…

On the user’s profile page is the shortcode:

[ESPRESSO_MY_EVENTS template=simple_list_table your_events_title=’Upcoming Live Training Events For Which You Are Currently Registered’]

The content-espresso_my_events-simple_list_table.template.php code looks like this:

<?php
if ( $event->get_active_status() == 'DTE' ) { return; }
/**
 * Template for the "simple_list_table" content template for the [ESPRESSO_MY_EVENTS] shortcode
 *
 * Available template args:
 * @type    $registration EE_Registration registration object
 */
?>
<tr>
	<td class="ee-status-strip reg-status-<?php echo $registration->status_ID(); ?>"></td>
	<td>
		<a aria-labelledby="<?php printf( __( 'Link to %s', 'event_espresso' ), $registration->event_name() ); ?>" href="<?php echo get_permalink( $registration->event_ID() ); ?>"><?php echo $registration->event_name(); ?></a>
	</td>
	   <td>
        <?php 
            $datetime = $registration->get_earliest_related_datetime();

            if( $datetime instanceof EE_Datetime ) {
                $datetime->e_start_date_and_time();
            }
        ?>
    </td>
	<td>	
	<?php
			$event = $registration->event();
			if ( $event instanceof EE_Event ) {
				$venues = $event->venues();
				foreach ( $venues as $venue ) {
					if ( $venue instanceof EE_Venue) {
						echo $venue->name() . '<br>';
					}
				}
			} else {
				echo '';
			}
		?>
	</td>
	<td>
		<?php
		$actions = array();
        $link_to_edit_registration_text = esc_html__('Link to edit registration.', 'event_espresso');
        $link_to_resend_registration_message_text = esc_html__('Link to resend registration message', 'event_espresso');
        $link_to_make_payment_text = esc_html__('Link to make payment', 'event_espresso');
        $link_to_view_receipt_text = esc_html__('Link to view receipt', 'event_espresso');
        $link_to_view_invoice_text = esc_html__('Link to view invoice', 'event_espresso');
		//only show the edit registration link if the registration has question groups
		$actions['edit_registration'] = $registration->count_question_groups()
			? '<a aria-label="' . $link_to_edit_registration_text
              . '" title="' . $link_to_edit_registration_text
              . '" href="' . $registration->edit_attendee_information_url() . '">'
			. '<span class="ee-icon ee-icon-user-edit ee-icon-size-16"></span></a>'
			: '';
		//resend confirmation email.
		$resend_registration_link = add_query_arg(
			array( 'token' => $registration->reg_url_link(), 'resend' => true ),
			get_permalink( EE_Registry::instance()->REQ->get_post_id_from_request() )
		);
		if ( $registration->is_primary_registrant() ||
		     ( ! $registration->is_primary_registrant()
		       && $registration->status_ID() === EEM_Registration::status_id_approved ) ) {

			$actions['resend_registration'] = '<a aria-label="' . $link_to_resend_registration_message_text
                                              . '" title="' . $link_to_resend_registration_message_text
                                              . '" href="' . $resend_registration_link . '">'
				. '<span class="dashicons dashicons-email-alt"></span></a>';
		}

		//make payment?
		if ( $registration->is_primary_registrant()
		     && $registration->transaction() instanceof EE_Transaction
			 && $registration->transaction()->remaining() ) {
			$actions['make_payment'] = '<a aria-label="' . $link_to_make_payment_text
                                       . '" title="' . $link_to_make_payment_text
                                       . '" href="' . $registration->payment_overview_url() . '">'
				. '<span class="dashicons dashicons-cart"></span></a>';
		}

		//receipt link?
		if ( $registration->is_primary_registrant() && $registration->receipt_url() ) {
			$actions['receipt'] = '<a aria-label="' . $link_to_view_receipt_text
                                  . '" title="' . $link_to_view_receipt_text
                                  . '" href="' . $registration->receipt_url() . '">'
				. '<span class="dashicons dashicons-media-default ee-icon-size-18"></span></a>';
		}

		//invoice link?
		if ( $registration->is_primary_registrant() && $registration->invoice_url() ) {
			$actions['invoice'] = '<a aria-label="' . $link_to_view_invoice_text
                                  . '" title="' . $link_to_view_invoice_text
                                  . '" href="' . $registration->invoice_url() . '">'
			                      . '<span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span></a>';
		}

		//filter actions
		$actions = apply_filters( 'FHEE__EES_Espresso_My_Events__actions',
			$actions,
			$registration
		);

		//...and echo the actions!
		echo implode( '&nbsp;', $actions );
		?>
	</td>
</tr>

The loop-espresso_my_events-simple_list_table.template.php code looks like this;

<?php
/**
 * Template for the "simple_list_table" loop template for the [ESPRESSO_MY_EVENTS] shortcode
 *
 * Available template args:
 * @type    string  $object_type  The type of object for objects in the 'object' array. It's expected for this template
 *                                that the type is 'Registration'
 * @type    EE_Registration[] $objects
 * @type    int     $object_count       Total count of all objects
 * @type    string  $your_events_title  The default label for the Events section
 * @type    string  $your_tickets_title The default label for the Tickets section
 * @type    string  $template_slug      The slug for the template.  For this template it will be 'simple_list_table'
 * @type    int     $per_page           What items are shown per page
 * @type    string  $path_to_template   The full path to this template
 * @type    int     $page               What the current page is (for the paging html).
 * @type    string  $with_wrapper       Whether to include the wrapper containers or not.
 * @type    int     $att_id             Attendee ID all the displayed data belongs to.
 */
$url = EEH_URL::current_url();
$pagination_html = EEH_Template::get_paging_html(
	$object_count,
	$page,
	$per_page,
	$url,
	false,
	'ee_mye_page',
	array(
		'single' => __( 'event', 'event_espresso' ),
		'plural' => __( 'events', 'event_espresso' )
	));
?>
<?php if ( $with_wrapper ) : ?>
<div class="espresso-my-events <?php echo $template_slug;?>_container">
	<?php do_action( 'AHEE__loop-espresso_my_events__before', $object_type, $objects, $template_slug, $att_id ); ?>
	<h3><?php echo $your_events_title; ?></h3>
	<div class="espresso-my-events-inner-content">
<?php endif; //$with_wrapper check ?>
		<?php if ( $objects && reset( $objects ) instanceof EE_Registration ) : ?>
		
		<table class="espresso-my-events-table <?php echo $template_slug;?>_table">
			<thead>
				<tr>
					<th scope="col" class="espresso-my-events-reg-status ee-status-strip">
					</th>
					<th scope="col" class="espresso-my-events-event-th">
						<?php echo apply_filters(
							'FHEE__loop-espresso_my_events__table_header_event',
							esc_html__( 'Title', 'event_espresso' ),
							$object_type,
							$objects,
							$template_slug,
							$att_id
						); ?>
					</th>
					<th scope="col" class="espresso-my-events-ticket-th">
						<?php echo apply_filters(
							'FHEE__loop-espresso_my_events__table_header_ticket',
							esc_html__( 'Start Date & Time', 'event_espresso' ),
							$object_type,
							$objects,
							$template_slug,
							$att_id
						); ?>
					</th>
					<th scope="col" class="espresso-my-events-location-th">
						<?php echo apply_filters(
							'FHEE__loop-espresso_my_events__location_table_header',
							esc_html__( 'Location', 'event_espresso' ),
							$object_type,
							$objects,
							$template_slug,
							$att_id
						); ?>
					</th>
					<th scope="col" class="espresso-my-events-actions-th">
						<?php echo apply_filters(
							'FHEE__loop-espresso_my_events__actions_table_header',
							esc_html__( 'Actions', 'event_espresso' ),
							$object_type,
							$objects,
							$template_slug,
							$att_id
						); ?>
					</th>
				</tr>
			</thead>
			<tbody>
				<?php foreach ( $objects as $object ) {
					if ( ! $object instanceof EE_Registration ) {
						continue;
					}
					$template_args = array( 'registration' => $object );
					$template      = 'content-espresso_my_events-simple_list_table.template.php';
					EEH_Template::locate_template( $template, $template_args, true, false );
				} ?>
			</tbody>
		</table>
		<div class="espresso-my-events-footer">
			<div class="espresso-my-events-pagination-container <?php echo $template_slug;?>-pagination">
				<span class="spinner"></span>
				<?php echo $pagination_html; ?>
				<div style="clear:both"></div>
			</div>
			<div style="clear:both"></div>
			<?php EEH_Template::locate_template( 'status-legend-espresso_my_events.template.php', array( 'template_slug' => $template_slug ), true, false ); ?>
		</div>
		<?php else : ?>
			<div class="no-events-container">
				<p><?php echo apply_filters(
					         'FHEE__loop-espresso_my_events__no_events_message',
							 esc_html__( 'You have no registrations yet', 'event_espresso' ),
				             $object_type,
				             $objects,
				             $template_slug,
					         $att_id
				         ); ?>
		         </p>
			</div>
		<?php endif; ?>
<?php if ( $with_wrapper ) : ?>
	</div>
	<?php do_action( 'AHEE__loop-espresso_my_events__after', $object_type, $objects, $template_slug, $att_id ); ?>
</div>
<?php endif; //end $wrapper check?>

However, with that shortcode and template file code, I’m still seeing all the events for which a person is registered – not just the future events. What am I missing?


Tony

  • Support Staff

January 17, 2019 at 7:04 am

Hi there,

Are you 100% sure that the code you posted from content-espresso_my_events-simple_list_table.template.php is actually loading?

The reason I ask is at the point where you have this:

if ( $event->get_active_status() == 'DTE' ) { return; }

There is no $event variable and it will throw a fatal error, I checked this by loading your files on one of my test sites and sure enough, fatal error – https://monosnap.com/file/ak3hgHDoyAV8OvdSvPMl3CCggvSu5V

That error is basically saying $event doesn’t exist and calling get_active_status() on $event throws a fatal because $event is NULL and so have no methods to call.

So right now it seems your above templates are actually loading (otherwise you’d be getting the same error), or you have an older version of the WP User integration add-on that does pass the event object over.

Which version number of the WP User integration add-on are you using?

Where are those 2 above template files located on your site?

We can fix the template to stop it loading past events, however, right now it appears your site isn’t actually loading those templates so lets get that working first.


mdeyerinkc

January 17, 2019 at 10:01 am

I have EE-WP Users (EE4.6+) version 2.0.16.p installed, but I don’t know how to tell if the template is loading. But I’m not getting an error on the loaded page.

The two php files are located in public_html/lms/wp-content/plugins/themes/education-zone-child, and I edit them via the WP Menu -> Appearance -> Editor.


Tony

  • Support Staff

January 18, 2019 at 4:58 am

I’ve just tried to view your site but the domain linked to your account redirects to a youtube video, just noting in case that’s not expected.

I have EE-WP Users (EE4.6+) version 2.0.16.p installed, but I don’t know how to tell if the template is loading. But I’m not getting an error on the loaded page.

The easiest way is to just add some additional content to the template and see if that’s output, so above the check I mentioned earlier you could add something like:

echo '<h1>TESTING</h1>';

So it would be like this:

<?php
echo '<h1>TESTING</h1>';
if ( $event->get_active_status() == 'DTE' ) { return; }

Then check the page for the ‘Testing’ output.


mdeyerinkc

January 18, 2019 at 9:52 am

The only reason the site would redirect is if your IP is outside the U.S. If send me your IP (via DM or email) I can whitelist it. I can also send you site login credentials.

Tried the echo test and indeed it does not appear the custom template file is loading. So… what next?


mdeyerinkc

January 18, 2019 at 10:15 am

I take it back – it is loading (I was checking the page under the wrong account).


Tony

  • Support Staff

January 18, 2019 at 12:43 pm

The only reason the site would redirect is if your IP is outside the U.S. If send me your IP (via DM or email) I can whitelist it.

Yeah, that’s why, I’m in the UK.

If send me your IP (via DM or email) I can whitelist it.

I’ll put my IP in a private reply right after this one.

I’m a little stumped as to why/how that’s working tbh, it shouldn’t be.

I can see in one of your other threads HERE that you also have that code in content-espresso_my_events-event_section.template.php which does make sense as the template is passed the event object directly.

Tried the echo test and indeed it does not appear the custom template file is loading. So… what next?

and

I take it back – it is loading (I was checking the page under the wrong account).

What was the difference between the two account? One had no registrations and the other did?


mdeyerinkc

January 18, 2019 at 4:01 pm

Yes – difference was one account had event registrations and the other didn’t.


Tony

  • Support Staff

January 21, 2019 at 5:35 am

This reply has been marked as private.


Tony

  • Support Staff

January 21, 2019 at 5:41 am

So, because I’m not sure how this is actually working at all I can’t be sure on a fix, but in content-espresso_my_events-simple_list_table.template.php

Move if ( $event->get_active_status() == 'DTE' ) { return; }

Just below this line: $event = $registration->event();

You have the event there and it’ll check for the event status.

That should check the event and if all the datetimes have expired, skip it.


mdeyerinkc

January 22, 2019 at 4:02 pm

I tried that, (looks like below), and it didn’t change anything.

<?php
			$event = $registration->event();
		    if ( $event->get_active_status() == 'DTE' ) { return; }
		
			if ( $event instanceof EE_Event ) {
				$venues = $event->venues();
				foreach ( $venues as $venue ) {
					if ( $venue instanceof EE_Venue) {
						echo $venue->name() . '<br>';
					}
				}
			} else {
				echo '';
			}
		?>


mdeyerinkc

January 22, 2019 at 4:06 pm

This reply has been marked as private.


Tony

  • Support Staff

January 23, 2019 at 7:24 am

Unfortunately, I can’t see anything without an account that has registrations on an event (preferably an old event and a new event) and access to the template files to confirm they are loading (with the above it really doesn’t appear as though they are).

However, we don’t add/remove code through the built-in editors and would need FTP access to view what is going on, if you want me to take a look I’m happy to do so but you’ll need to provide all of the requested details on this form:

https://eventespresso.com/send-login-details/


Tony

  • Support Staff

January 29, 2019 at 8:06 am

Hi there,

So I spent some time looking over your template files and as you mentioned, they are correctly loading from your child theme.

In content-espresso_my_events-simple_list_table.template.php I’ve added this:

if ( $registration->event()->get_active_status() == 'DTE' ) { return; }

To the first line of the template and now ‘old’ events no longer display in the table.

In a previous reply we changed the template file (which did actually make a change, it removed the ‘start date’, ‘Location’ and ‘Actions’ columns for that events row as it was after the event name, I missed that earlier) to try and figure out what was happening, so I can’t why the previous code didn’t throw a fatal previously but it now works.

I did try adding if ( $event->get_active_status() == 'DTE' ) { return; } in place of the code in use now and it did throw a fatal error (as expected), because there was no event object at that point, notice the new code pulls the event directly from the registration.

In any case, the account you sent me now only displays a single event in the list or February 26 and the older event has been removed. Can you confirm this now works how you are expecting?


mdeyerinkc

January 29, 2019 at 2:55 pm

It is indeed now filtering expired events, but not “inactive” events. I didn’t even know inactive was a status. One of my event is “inactive” – but I know know what that means. I tried deleting the inactive event, but it’s locked (i.e. it has a padlock icon next to it in the trash folder). Since I suspect there’s a valid reason for having inactive events (even if I don’t understand what that means), what code should I add to also filter those?


Tony

  • Support Staff

January 29, 2019 at 3:26 pm

A status of Inactive would normally be an event that has not been published.

If you check the event in question what is the post status for that event? – https://monosnap.com/file/GnVoILCxziXmNsbEdc1aOdWpHxCrnc

The support post ‘Hide Expired Events Redux’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso