Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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;
}
share|improve this question
    
make sure you flush the rewrite rules WPAdmin->Settings->Permalink->Save. Sometimes only flushing fix the 404 errors. –  M-R Dec 12 '12 at 9:28
1  
@M-R Thanks mate, you are my sunshine for the day :P –  Sankalp Shekhar Dec 12 '12 at 9:43
add comment

1 Answer

up vote 0 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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