We can use add_rewrite_rule function to register new custom routes with WordPress. This function can be implemented within many actions in WordPress. However, we usually use init action to handle the rewrite rules. Let's add a custom rewrite rule to handle the scenario of user login and registration:
add_action('init','wqraf_manage_user_routes');function wqraf_manage_user_routes() { add_rewrite_rule( '^user/([^/]+)/?', 'index.php?wpquick_action=$matches[1]', 'top' );}
You can find the code for this section inside the wpquick-rewrite-api plugin in the source codes directory. The add_rewrite_rule function accepts two required and one optional parameters. Let’s take a look at the parameters and their role:
- regex