Skip to content

Commit

Permalink
Add exit early condition on route processing
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Dec 19, 2018
1 parent 9e2964e commit 8482071
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
48 changes: 25 additions & 23 deletions lib/WP_Auth0_Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function setup_rewrites() {
*
* @param WP $wp - WP object for current request.
*
* @return bool|false|string
* @return bool|string
*/
public function custom_requests( $wp ) {
$page = null;
Expand All @@ -72,31 +72,33 @@ public function custom_requests( $wp ) {
$page = $wp->query_vars['pagename'];
}

if ( ! empty( $page ) ) {
switch ( $page ) {
case 'oauth2-config':
$output = wp_json_encode( $this->oauth2_config() );
break;
case 'migration-ws-login':
$output = wp_json_encode( $this->migration_ws_login() );
break;
case 'migration-ws-get-user':
$output = wp_json_encode( $this->migration_ws_get_user() );
break;
case 'coo-fallback':
$output = $this->coo_fallback();
break;
default:
return false;
}
if ( empty( $page ) ) {
return false;
}

if ( $wp->query_vars['custom_requests_return'] ) {
return $output;
}
switch ( $page ) {
case 'oauth2-config':
$output = wp_json_encode( $this->oauth2_config() );
break;
case 'migration-ws-login':
$output = wp_json_encode( $this->migration_ws_login() );
break;
case 'migration-ws-get-user':
$output = wp_json_encode( $this->migration_ws_get_user() );
break;
case 'coo-fallback':
$output = $this->coo_fallback();
break;
default:
return false;
}

echo $output;
exit;
if ( $wp->query_vars['custom_requests_return'] ) {
return $output;
}

echo $output;
exit;
}

protected function coo_fallback() {
Expand Down
2 changes: 1 addition & 1 deletion tests/testRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function tearDown() {
* If we have no query vars, the route should do nothing.
*/
public function testThatEmptyQueryVarsDoesNothing() {
$this->assertNull( self::$routes->custom_requests( self::$wp ) );
$this->assertFalse( self::$routes->custom_requests( self::$wp ) );
}

/**
Expand Down

0 comments on commit 8482071

Please sign in to comment.