Skip to content
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

Use URL as location when a location isn't provided - develop #65

Open
wants to merge 2 commits into
base: develop-2024-07-01
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions themes/osi/inc/sugar-calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ function osi_is_past_event( int $post_id ) {
* @return void
*/
function osi_add_location_details( int $post_id = 0 ) {
$location = sugar_calendar_get_event_by_object( $post_id, 'post' )->location;
$event = sugar_calendar_get_event_by_object( $post_id, 'post' );

// Maybe add location
if ( ! empty( $location ) ) :
if ( ! empty( $event->location ) && $event->url !== $event->location ) :
?>

<div class="sc_event_location">

<?php echo esc_html( $location ); ?>
<?php echo esc_html( $event->location ); ?>

</div>

Expand Down Expand Up @@ -349,3 +349,31 @@ function osi_default_event_metadata( mixed $value, int $object_id, string $meta_
}

add_filter( 'default_sc_event_metadata', 'osi_default_event_metadata', 20, 3 );

/**
* Add Event Location in presence of Event URL.
*
* @param mixed $event The event to construct.
*
* @return mixed
*/
function osi_event_construct( mixed $event ) {
// Get post types
$pts = sugar_calendar_allowed_post_types();

// Only for Single and Archive Pages.
if ( ! is_single() && ! is_post_type_archive( $pts ) && ! empty( $event ) && $event->exists() ) {
return $event;
}

$event_url = get_event_meta( $event->id, 'url', true );
$event_location = get_event_meta( $event->id, 'location', true );

if ( empty( $event_location ) && ! empty( $event_url ) ) {
$event->location = $event_url;
}

return $event;
}

add_filter( 'sugar_calendar_event_construct', 'osi_event_construct', 9 );
Loading