campusboy87
5/18/2017 - 1:04 PM

Check rules for endpoint and reset rewrite rule

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;

?>