Redirect_404_Vehicles::maybe_redirect( WP $wp_obj )
Checks to see if the request is for a vehicle that no longer exists.
On This Page
Description Description
If it was, it decides where to redirect the user and performs that redirect.
Parameters Parameters
- $wp_obj
-
(WP) (Required) Current WordPress environment instance (passed by reference).
Return Return
(void)
Source Source
File: includes/class-redirect-404-vehicles.php
public function maybe_redirect( $wp_obj ) { if ( is_admin() ) { return; } // is this a 404? // is this a request for a vehicle? if ( ! is_404() || ! $this->is_request_for_vehicle( $wp_obj ) ) { return; } // base link to the inventory page. $url = get_post_type_archive_link( INVP::POST_TYPE ); // get the make out of the slug. $make = $this->extract_make( $wp_obj ); if ( ! is_string( $make ) || '' == $make ) { // no make, redirect to vehicle archive. wp_safe_redirect( $url, 302 ); exit; } // are there cars in this make? $term = get_term_by( 'slug', $make, 'make' ); if ( ! $term || 0 === $term->count ) { // no cars in this make, go to vehicle archive. wp_safe_redirect( $url, 302 ); exit; } // redirect to this make's archive. $url = get_term_link( $make, 'make' ); if ( is_wp_error( $url ) ) { // no link created for this make? go to vehicle archive. wp_safe_redirect( $url, 302 ); exit; } wp_safe_redirect( $url, 302 ); exit; }
Expand full source codeCollapse full source codeView on Github