Site icon Hip-Hop Website Design and Development

Routing in WordPress

I’m utilizing this instance to rewrite url to load a given file car-details.php however I stil get error Web page not discovered after I entry area.com/account/account_page/9 How can I get this working.

class Your_Class
{

    public operate init()
    {
        add_filter( 'template_include', array( $this, 'include_template' ) );
        add_filter( 'init', array( $this, 'rewrite_rules' ) );
    }

    public operate include_template( $template )
    {
        //attempt to get the question var we registered in our query_vars() operate
        $account_page = get_query_var( 'account_page' );

        //if the question var has information, we should be on the best web page, load our customized template
        if ( $account_page ) {

            return CUSTOMER_CAR_PLUGIN_DIR.'pages/customer-car-details.php';
        }

        return $template;
    }

    public operate flush_rules()
    {
        $this->rewrite_rules();

        flush_rewrite_rules();
    }

    public operate rewrite_rules()
    {
        add_rewrite_rule( 'account/(.+?)/?$', 'index.php?account_page=$matches[1]', 'prime');
        add_rewrite_tag( '%account_page%', '([^&]+)' );
    }

}

add_action( 'plugins_loaded', array( new Your_Class, 'init' ) );

// One time activation features
register_activation_hook( CUSTOMER_CAR_PLUGIN_DIR, array( new Your_Class, 'flush_rules' ) );
}