\WP_Stager_Integration\Event::redirect_default_event_url(): void
\WP_Stager_Integration\Event::redirect_default_event_url(): voidDescription
Redirects default event URL to chosen permalink structure.
Returns:
void
Information
| File | class-event.php line 210 |
|---|
Full Code
/**
* Redirects default event URL to chosen permalink structure.
*
* @return void
*/
public static function redirect_default_event_url() {
// Bail if event pages are disabled
if ( ! Options::is_enabled_event_pages() ) {
return;
}
// Bail if not on a single event page
if ( ! self::is_single_event() ) {
return;
}
// Get data
$permalink_base = (string) (Options::get_event_permalink_base() ?: '');
$permalink_structure = (string) Options::get_event_permalink_structure();
// Bail if no permalink base or if already using default structure
if ( ! $permalink_base || Options::PERMALINK_STRUCTURE_EVENT_ID === $permalink_structure ) {
return;
}
// Get current event ID
$event_id = self::get_single_event_id();
// Bail if no event ID
if ( ! $event_id ) {
return;
}
// Get the correct permalink for this event
$correct_permalink = self::get_permalink( $event_id );
// Bail if no correct permalink
if ( ! $correct_permalink ) {
return;
}
// Get current URL
$current_url = (string) (home_url( $_SERVER[ 'REQUEST_URI' ] ?? '' ));
// Parse URLs to compare paths
$current_parsed = parse_url( $current_url );
$correct_parsed = parse_url( $correct_permalink );
$current_path = (string) ($current_parsed[ 'path' ] ?? '');
$correct_path = (string) ($correct_parsed[ 'path' ] ?? '');
// Redirect if paths don't match (meaning we're on the default URL)
if ( $current_path !== $correct_path ) {
wp_safe_redirect( $correct_permalink, 301 );
exit;
}
}💡 If you ever get stuck or have a question, please check our FAQs, our Free Integration Service, our paid Full Integration Service, or reach out to us!

Get WP Stager Integration
🎁 Limited offer: Use code WELCOME26 to get your first month for free!

