Redirect_404_Vehicles::extract_make( mixed $wp_obj )

extract_make


Description Description

Finds the vehicle make from the request whether it was a search or a request for a specific vehicle that no longer exists.


Top ↑

Parameters Parameters

$wp_obj

(mixed) (Required)


Top ↑

Return Return

(string) A vehicle manufacturer name


Top ↑

Source Source

File: includes/class-redirect-404-vehicles.php

		function extract_make( $wp_obj ) {

			if ( ! $this->is_request_for_vehicle( $wp_obj ) ) {
				return '';
			}

			// if this is a search, the make might be in its own query variable
			if ( isset( $wp_obj->query_vars['make'] ) ) {
				return $wp_obj->query_vars['make'];
			}

			// if this is a request for a single vehicle, parse the make out of the slug
			if ( isset( $wp_obj->query_vars[ INVP::POST_TYPE ] ) ) {
				$slug_pieces = explode( '-', $wp_obj->query_vars[ INVP::POST_TYPE ] );
				if ( 2 <= sizeof( $slug_pieces )
					// is the first piece a number of no more than 4 digits?
					&& 4 >= strlen( $slug_pieces[0] )
					&& is_numeric( $slug_pieces[0] )
				) {
					return $slug_pieces[1];
				}
			}

			return '';
		}