Working on a plugin, which is intended to provide a registration on front-end, to let users register.
I am trying to create a Virtual page, which would display the form.
Trying to create URL like the following http://example.com/plugin_register/register
Have been referring to, How do you create a 'virtual' page in WordPress
But have been unable to make it work with changed query_var, for e.g. if I replace wpse9870_api
with plugin_register
, it redirects to home-page or 404 page.
Also referring to Rewrite API/add rewrite rule
But have been unable to get this work too.
My plugin looks like the following:
add_action( 'init', 'wpse9870_init_internal' );
function wpse9870_init_internal() {
add_rewrite_rule( '^my-api.php$', 'index.php?wpse9870_api=1', 'top' );
//add_rewrite_rule('^nutrition/?','index.php?wpse9870_api=1','top');
}
add_filter( 'query_vars', 'wpse9870_query_vars' );
function wpse9870_query_vars( $query_vars ) {
$query_vars[] = 'wpse9870_api';
return $query_vars;
}
add_action( 'parse_request', 'wpse9870_parse_request' );
function wpse9870_parse_request( &$wp ) {
if ( array_key_exists( 'wpse9870_api', $wp->query_vars ) ) {
include(realpath(plugin_dir_path( __FILE__ ).'index.php'));
//echo plugin_dir_path( __FILE__ );
exit();
}
return;
}