1. Go to this page and download the library: Download underpin/route-loader library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
underpin / route-loader example snippets
plugin_name()->routes()->add( 'dashboard-home', [
'name' => 'Dashboard',
'description' => "Route for dashboard screen",
'id_callback' => function () { // Callback function to set the route ID. This should be unique.
$pieces = [ 'account' ];
$account_screen = get_query_var( 'account_screen', false );
$account_child_screen = get_query_var( 'account_child_screen', false );
if ( $account_screen ) {
$pieces[] = $account_screen;
}
if ( $account_child_screen ) {
$pieces[] = $account_child_screen;
}
return implode( '_', $pieces );
},
'priority' => 'top', // Optional. sets the priority of add_rewrite_rule. Defaults to bottom. Can be "bottom" or "top"
'route' => '^account/?([A-Za-z0-9-]+)?/?([A-Za-z0-9-]+)?/?$', // Regex for route. See https://developer.wordpress.org/reference/functions/add_rewrite_rule/
'query_vars' => [ 'account_screen' => '$matches[1]', 'account_child_screen' => '$matches[2]' ], // Query vars for route. See https://developer.wordpress.org/reference/functions/add_rewrite_rule/
] );