Merge pull request #11173 from woothemes/improve-endpoints

Allow top level endpoints only when using a page on the  front end
This commit is contained in:
Mike Jolley 2016-06-20 11:55:51 +01:00 committed by GitHub
commit c626747cbd
1 changed files with 23 additions and 1 deletions

View File

@ -130,12 +130,34 @@ class WC_Query {
return $title;
}
/**
* Endpoint mask describing the places the endpoint should be added.
*
* @since 2.6.2
* @return int
*/
protected function get_endpoints_mask() {
if ( 'page' === get_option( 'show_on_front' ) ) {
$page_on_front = get_option( 'page_on_front' );
$myaccount_page_id = get_option( 'woocommerce_myaccount_page_id' );
$checkout_page_id = get_option( 'woocommerce_checkout_page_id' );
if ( in_array( $page_on_front, array( $myaccount_page_id, $checkout_page_id ) ) ) {
return EP_ROOT | EP_PAGES;
}
}
return EP_PAGES;
}
/**
* Add endpoints for query vars.
*/
public function add_endpoints() {
$mask = $this->get_endpoints_mask();
foreach ( $this->query_vars as $key => $var ) {
add_rewrite_endpoint( $var, EP_ROOT | EP_PAGES );
add_rewrite_endpoint( $var, $mask );
}
}