views:

476

answers:

2

I'm writing a plug-in for WordPress which in fact will be a separate ordering module (it will be placed in an IFRAME on the site I'm developing as well as others) but with its admin tied into WordPress. I wrote the administration part without too much hassle, however I'm having trouble with the front-end.

First of all I'd like my script to be accessible via www.mysite.com/order/ and, as per the WordPress codex, I found I need to place the following code into my main plugin file:

add_action('init', 'ta_flush_rewrite_rules');

function ta_flush_rewrite_rules() 
{
  global $wp_rewrite;
  $wp_rewrite->flush_rules();
}

add_action('generate_rewrite_rules', 'ta_add_rewrite_rules');

function ta_add_rewrite_rules( $wp_rewrite ) {
  $new_rules = array("order/(.+)" => "/wp-content/plugins/my-plugin/order.php");
  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}

But it doesn't work and I don't really want to get dirty with .htaccess hacking.

Furthermore even if this would work, the order.php file is a separate file from my plugin. This means that I'll have to include some WordPress files in order to have access to the database and other helper classes and functions. That brings us to question number 2: is there a way for the URL to call a function of my plugin to render the order page?

+1  A: 

checkout http://stackoverflow.com/questions/2210826/need-help-with-wp-rewrite-in-a-wordpress-plugin you might find information you need.

Brad
+1  A: 

don't flush rules on INIT as it will make lots of mysql queries on every page and interfere with other plugins using custom rewrite rules (such as ones creating custom post types)

banesto