New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Expired Tickets Snippet to work with CPT Changes #19
Open
tn3rb
wants to merge
2
commits into
master
Choose a base branch
from
update-expired-tickets-filter
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
107 changes: 90 additions & 17 deletions
107
templates/de_ee_filter_events_out_with_expired_tickets.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,100 @@ | ||
<?php | ||
|
||
/** | ||
* The purpose of this snippet is to filter the event archive (and event taxonomy archive) pages so that they exclude events | ||
* that have tickets no longer on sale. | ||
* returns true if the current query is for an espresso event | ||
* | ||
* @param WP_Query $wp_query | ||
* @return bool | ||
*/ | ||
function isEspressoEventsArchive(WP_Query $wp_query): bool | ||
{ | ||
return | ||
isset($wp_query->query_vars['post_type']) | ||
&& ( | ||
$wp_query->query_vars['post_type'] == 'espresso_events' | ||
|| ( | ||
is_array($wp_query->query_vars['post_type']) | ||
&& in_array( | ||
'espresso_events', | ||
$wp_query->query_vars['post_type'] | ||
) | ||
) | ||
) | ||
&& ! $wp_query->is_singular; | ||
} | ||
|
||
|
||
/** | ||
* The purpose of this snippet is to filter the event archive (and event taxonomy archive) pages so that they exclude | ||
* events that have tickets no longer on sale. | ||
* | ||
* NOTE: This query is only valid for Event Espresso 4.8+ | ||
* | ||
* To Implement this code, add it to the bottom of your themes functions.php file, or add it to a site specific plugin. | ||
* | ||
* @param string $SQL | ||
* @param WP_Query $wp_query | ||
* @return string | ||
*/ | ||
function de_ee_tweak_event_list_exclude_ticket_expired_events_where( $SQL, WP_Query $wp_query ) { | ||
if ( isset( $wp_query->query_vars['post_type'] ) && ( $wp_query->query_vars['post_type'] == 'espresso_events' || ( is_array( $wp_query->query_vars['post_type'] ) && in_array( 'espresso_events', $wp_query->query_vars['post_type'] ) ) ) && ! $wp_query->is_singular ) { | ||
$SQL .= ' AND Ticket.TKT_end_date > "' . current_time( 'mysql', true ) . '" AND Ticket.TKT_deleted=0'; | ||
} | ||
return $SQL; | ||
function de_ee_tweak_event_list_exclude_ticket_expired_events_where(string $SQL, WP_Query $wp_query): string | ||
{ | ||
if (isEspressoEventsArchive($wp_query)) { | ||
$SQL .= ' AND Ticket.TKT_end_date > "' . current_time('mysql', true) . '" AND Ticket.TKT_deleted=0'; | ||
} | ||
return $SQL; | ||
} | ||
add_filter( 'posts_where', 'de_ee_tweak_event_list_exclude_ticket_expired_events_where', 15, 2 ); | ||
function de_ee_tweak_event_list_exclude_ticket_expired_events_join( $SQL, $wp_query ) { | ||
if ( isset( $wp_query->query_vars['post_type'] ) && ( $wp_query->query_vars['post_type'] == 'espresso_events' || ( is_array( $wp_query->query_vars['post_type'] ) && in_array( 'espresso_events', $wp_query->query_vars['post_type'] ) ) ) && ! $wp_query->is_singular ) { | ||
if ( ! $wp_query->is_espresso_event_archive && ! $wp_query->is_espresso_event_taxonomy ) { | ||
$SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table() . '.ID = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name() . ' ) '; | ||
} | ||
$SQL .= ' INNER JOIN ' . EEM_Datetime_Ticket::instance()->table() . ' AS Datetime_Ticket ON ( Datetime_Ticket.DTT_ID=' . EEM_Datetime::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() . ' ) INNER JOIN ' . EEM_Ticket::instance()->table() . ' AS Ticket ON ( Datetime_Ticket.TKT_ID=Ticket.' . EEM_Ticket::instance()->primary_key_name() . ' ) '; | ||
} | ||
return $SQL; | ||
add_filter( | ||
'posts_where', | ||
'de_ee_tweak_event_list_exclude_ticket_expired_events_where', | ||
15, | ||
2 | ||
); | ||
|
||
|
||
/** | ||
* @param string $SQL | ||
* @param WP_Query $wp_query | ||
* @return string | ||
* @throws EE_Error | ||
* @throws ReflectionException | ||
*/ | ||
function de_ee_tweak_event_list_exclude_ticket_expired_events_join(string $SQL, WP_Query $wp_query): string | ||
{ | ||
|
||
if (isEspressoEventsArchive($wp_query)) { | ||
$dates_table = EEM_Datetime::instance()->table(); | ||
$dates_table_pk = EEM_Datetime::instance()->primary_key_name(); | ||
$events_table = EEM_Event::instance()->table(); | ||
$events_table_pk = EEM_Event::instance()->primary_key_name(); | ||
$date_tickets_table = EEM_Datetime_Ticket::instance()->table(); | ||
$tickets_table = EEM_Ticket::instance()->table(); | ||
$tickets_table_pk = EEM_Ticket::instance()->primary_key_name(); | ||
if ( | ||
strpos($SQL, $dates_table) === false | ||
&& ! $wp_query->is_espresso_event_archive | ||
&& ! $wp_query->is_espresso_event_taxonomy | ||
) { | ||
$SQL .= " INNER JOIN $dates_table"; | ||
$SQL .= " ON ( $events_table.ID = $dates_table.$events_table_pk ) "; | ||
} | ||
if ( | ||
strpos($SQL, $date_tickets_table) === false | ||
) { | ||
$SQL .= " INNER JOIN $date_tickets_table AS Datetime_Ticket"; | ||
$SQL .= " ON ( Datetime_Ticket.DTT_ID = $dates_table.$dates_table_pk )"; | ||
} | ||
if ( | ||
strpos($SQL, $tickets_table) === false | ||
) { | ||
$SQL .= " INNER JOIN $tickets_table AS Ticket"; | ||
$SQL .= " ON ( Datetime_Ticket.TKT_ID=Ticket.$tickets_table_pk )"; | ||
} | ||
} | ||
return $SQL; | ||
} | ||
add_filter( 'posts_join', 'de_ee_tweak_event_list_exclude_ticket_expired_events_join', 3, 2 ); | ||
add_filter( | ||
'posts_join', | ||
'de_ee_tweak_event_list_exclude_ticket_expired_events_join', | ||
3, | ||
2 | ||
); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the primary chnage that was required to fix this snippet,
the rest of the changes are just code cleanup