0

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;
}
2
  • make sure you flush the rewrite rules WPAdmin->Settings->Permalink->Save. Sometimes only flushing fix the 404 errors.
    – M-R
    Commented Dec 12, 2012 at 9:28
  • 1
    @M-R Thanks mate, you are my sunshine for the day :P
    – s_s_
    Commented Dec 12, 2012 at 9:43

1 Answer 1

0

Make sure you flush the rewrite rules WPAdmin->Settings->Permalink->Save. Sometimes only flushing fix the 404 errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.