Skip to content

Instantly share code, notes, and snippets.

@aiiddqd
Created May 18, 2017 13:04
Show Gist options
  • Save aiiddqd/2b4069fb50359dd31b1e4cd32dd5bd4f to your computer and use it in GitHub Desktop.
Save aiiddqd/2b4069fb50359dd31b1e4cd32dd5bd4f to your computer and use it in GitHub Desktop.
Check rules for endpoint and reset rewrite rule
<?php
/**
* Add Endpoint for URL Callback OAuth2
*/
class HAWP_Endpoint_Callback {
function __construct() {
add_action( 'init', array($this, 'add_endpoint') );
add_action( 'wp_loaded', array($this, 'flush_rewrite_rules_hack') );
}
function flush_rewrite_rules_hack(){
$rules = get_option( 'rewrite_rules' );
if ( ! isset( $rules['hawp(/(.*))?/?$'] ) ) {
flush_rewrite_rules( $hard = false );
}
}
function add_endpoint() {
add_rewrite_endpoint( 'hawp', EP_ROOT );
}
}
new HAWP_Endpoint_Callback;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment