Ajax endpoint should always be relative

This commit is contained in:
Mike Jolley 2015-06-19 13:30:57 +01:00
parent 928b1cca2f
commit 7e2ba5e05a
1 changed files with 4 additions and 14 deletions

View File

@ -38,26 +38,16 @@ class WC_AJAX {
/**
* Get WC Ajax Endpoint
* @param string $request Optional
* @param string $ssl Optional
* @return string
*/
public static function get_endpoint( $request = '', $ssl = null ) {
if ( is_null( $ssl ) ) {
$scheme = parse_url( home_url(), PHP_URL_SCHEME );
} elseif ( $ssl ) {
$scheme = 'https';
} else {
$scheme = 'http';
}
public static function get_endpoint( $request = '' ) {
if ( strstr( get_option( 'permalink_structure' ), '/index.php/' ) ) {
$endpoint = trailingslashit( home_url( '/index.php/wc-ajax/' . $request, $scheme ) );
$endpoint = trailingslashit( home_url( '/index.php/wc-ajax/' . $request, 'relative' ) );
} elseif ( get_option( 'permalink_structure' ) ) {
$endpoint = trailingslashit( home_url( '/wc-ajax/' . $request, $scheme ) );
$endpoint = trailingslashit( home_url( '/wc-ajax/' . $request, 'relative' ) );
} else {
$endpoint = add_query_arg( 'wc-ajax=', $request, trailingslashit( home_url( '', $scheme ) ) );
$endpoint = add_query_arg( 'wc-ajax=', $request, trailingslashit( home_url( '', 'relative' ) ) );
}
return esc_url_raw( $endpoint );
}