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.

i developed a plugin (the backend at least) and now i want to add a frontpage to my blog. the url should look something like this

http://www.mywordpressblogalsoroot.com/mypluginname/param1/param2
http://www.mywordpressblogalsoroot.com/mypluginname/param1/
http://www.mywordpressblogalsoroot.com/mypluginname/

all this three urls should point to a plugins function or a php site with a loop, i dont know. the params should be readable , i think with get_query_var

i played a bit with the following:

add_filter('rewrite_rules_array','gamecard_insertMyRewriteRules');
// Adding a new rule
function gamecard_insertMyRewriteRules($rules) {
    $newrules = array();
    $newrules['(gamecard)/(\d*)$'] = 'index.php?pagename=$matches[1]&gamecardslug=$matches[2]';
    return $newrules + $rules;
}

// Adding the id var so that WP recognizes it
function gamecard_insertMyRewriteQueryVars($vars)
{
    array_push($vars, 'gamecardslug');
    return $vars;
}

something is happening, but i stuck a bit.

somebody can give me a pointer how to get all this done?

thanks

share|improve this question
add comment

1 Answer

Well this one is tricky.

function my_plugin_query_vars($vars) {
    // add mypluginname to the valid list of variables
    $new_vars = array('mypluginname');
    $vars = $new_vars + $vars;
    return $vars;
}
add_filter('query_vars', 'my_plugin_query_vars');

this will tell WordPress to accepts GET variables with the name mypluginname. so now you can process requests like

http://www.example.com?mypluginname=param1

We add an action on parse_request which gives us first change to parse given request before WordPress does.

function my_plugin_parse_request($wp) {
    // only process requests with "mypluginname=param1"
    if (array_key_exists('mypluginname', $wp->query_vars) 
            && $wp->query_vars['mypluginname'] == 'param1') {
        my_plugin_custom_function($wp);
    }
}
add_action('parse_request', 'my_plugin_parse_request');

Then we need to add a hook in WordPress rewrite system and then create a rule that tell WordPress to forward all requests to

http://example.com/mypluginname/param1

to

http://www.example.com?mypluginname=param1

with this code

add_action('generate_rewrite_rules', 'my_plugin_rewrite_rules');

function my_plugin_rewrite_rules( $wp_rewrite ) {
  $new_rules = array('mypluginname/param1' => 'index.php?mypluginname=param1');
  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}

this should get you going :) so i hope this helps.

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.