Created
April 23, 2015 09:04
-
-
Save CristianGiordano/274ddfbf4b6d6e7261ca to your computer and use it in GitHub Desktop.
WordPress Rewrite - Endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace Sneek; | |
class Rewrite | |
{ | |
public function __construct() | |
{ | |
add_filter( 'init', array($this, 'addProductSupportEndPoint')); | |
add_filter( 'template_include', array($this, 'maybeLoadProductSupportTemplate')); | |
} | |
public function addProductSupportEndPoint() | |
{ | |
add_rewrite_endpoint( 'support', EP_PERMALINK ); | |
} | |
public function maybeLoadProductSupportTemplate( $template ) | |
{ | |
global $wp_query; | |
if ( ! isset( $wp_query->query_vars['support'] ) or ! is_singular( 'product' ) ) | |
{ | |
return $template; | |
} | |
if ( ! empty( $wp_query->query_vars['support'] ) ) { | |
$wp_query->set_404(); | |
status_header( 404 ); | |
return locate_template( '404.php' ); | |
} | |
return locate_template( 'single-product-support.php' ); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment