function to check if an event is expired

Hi there!

I've just tried out this plugin and it sounds amazing!
What I love more is that it's very easy to edit, it doesn't use millions of hooks like other plugins do, there are just a few template files and css files, and the functions as well are pretty easy to find and then customize if needed.

after this said, I am looking for an easy way to check if an event is expired and, if yes, display an icon which says "expired" next to the title.

is there any quick function I can use to do it in the loop? like
if (is_expired())

and talking about this, I've seen you use some function like
get_event_details($event)

is there a place where I can see a list of the available functions?

Thank you!
Andrea

  • DavidM

    Hi Andrea,

    Glad you're enjoying the plugin! Let's see if we can sort something out here.

    There's not a specific list of functions the plugin provides, but you can look through the plugin code to find them.

    In this case, I believe something like the following might help to illustrate:

    global $post;
    $event = new Eab_EventModel($post);
    if ( $event->is_expired() ) {
    the_content();
    }

    That little snippet is creating an instance of the Eab_EventModel class and then using the is_expired() method, or function, to check it the event is expired.

    I used the_content() in the example, purely for example purpose, but you'll want to customize that to display it all how you like.

    Does that help?

    Cheers,
    David

  • Andrea

    Hi David!

    Thanx for helping!

    Actually I needed to check if the event was archived, because if it's expired it doesn't display the event at all. but I've used is_archived() and it works. I don't even had to call global $post, as it was already global.

    By the way, I had to set the event as archived by manually editing it. Are the events not supposed to be archived as soon as the event date is previous of the current date?

    I thought that the reason was because I've create the event with a date which was already passed (created today, and set date to 02-Jan), and so my setting "Open" in the post option, was overriding.
    but then I've realized that no matter what I set ther, if the date is older than today, under the title it write "Took place on" instead of "take place on" where it says the event date.

    Can you explain me how this archiving works?

    p.s. by the way, I think everyone will be grateful if there was a tidy documentation with a list of available classes and related methods.. :slight_smile:

    Cheers!
    Andrea

  • DavidM

    Hi Andrea,

    I don't believe the plugin uses the archive option internally, but uses it's own is_expired() method.

    Getting it to display content when events are expired should be as simple as including an 'else' clause like so:

    global $post;
    $event = new Eab_EventModel($post);
    if ( $event->is_expired() ) {
    the_content();
    } else {
    echo 'IMAGE LINK HERE';
    the_content();
    }

    Would that work for you?

    Cheers,
    David

  • Andrea

    Hi David!

    Thanx for your help!

    I've understood from another topic of mine, that the default events page is (as it's actually said in the settings..) the main archive page, which displays the archive of the current month, and not the upcoming events of the current month.

    so, in that page it will display all the event which are not set as Expired, nor Closed, but it will display the archived and the open. so if I use is_expired() it will be useless because if an event is expired it will be automatically hidden in that page, so I don't need to display a phrase next to the title which says "is expired".

    rather than this, in the upcoming page set up with the shortcodes, I can display only the events which are not yet passed, nor archived, nor closed. so I actually don't need to use the conditional I was asking initially.

    What I'm still not sure about, is:
    when an event date is passed (so by instance it was yesterday), is the field "event status" automatically changed by the plugin and set to "archived"? and if yes, when this happens?

    Thank you!
    Andrea

  • DavidM

    Hi Andrea,

    Going through some older threads I just noticed you were asking some additional questions. Sorry I didn't catch this sooner, but I'll be happy to explain.

    The plugin uses wp_schedule_event to schedule WordPress cron jobs to handle event expiration.

    When that expiration occurs, the event is set to archived, as indicated in this file:
    \wp-content\plugins\events-and-bookings\lib\class_eab_scheduler.php

    In case you're interested, you can actually have additional code executed upon event expiration using the action hook mentioned there, as follows:
    do_action('eab-scheduler-event_archived', $event);

    Also in case you're interested, you'll see a list of conditional functions the plugin provides in the following file:
    \wp-content\plugins\events-and-bookings\lib\class_eab_event_model.php

    Here are those respective functions for reference as copied from the file:

    /* ----- Status methods ----- */
    
    	/**
    	 * Is event open?
    	 * @return bool
    	 */
    	public function is_open () {
    		return (self::STATUS_OPEN == $this->get_status()) ? true : false;
    	}
    
    	/**
    	 * Is event closed?
    	 * @return bool
    	 */
    	public function is_closed () {
    		return (self::STATUS_CLOSED == $this->get_status()) ? true : false;
    	}
    
    	/**
    	 * Is event archived?
    	 * @return bool
    	 */
    	public function is_archived () {
    		return (self::STATUS_ARCHIVED == $this->get_status()) ? true : false;
    	}

    I hope that helps to explain how things work and how additional actions can be done.

    Cheers,
    David

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.