I’m currently working on a WordPress plugin and I need it to stick some pages into the front end. Now what I could do is create the pages manually and then create templates which call to the plugin functions, but this would then mean the plugin is managed in two places.
The pages I need are:
- a calendar page
- a booking page
- a return page (from PayPal)
- a cancel page (from PayPal)
It would be preferred if the plugin could just add these pages automatically rather than having to create them as actual posts or pages in the db, as otherwise the site owners may mess them up. Plus it keeps them contained within the plugin directory.
I assume I’m looking for some form of listener so that when a particular URL is hit, it goes to the plugin, rather than trying to load a normal page from the wordpress db.
Can anyone give any insight into how I achieve this?
you can use wp_insert_post( $post, $wp_error ); {http://codex.wordpress.org/Function_Reference/wp_insert_post} to create your pages from plugin.
It will return id and you can store that id as plugin option in database for future use.
What you are looking for is
add_rewrite_rule
– http://codex.wordpress.org/Rewrite_API/add_rewrite_ruleYou will still need page templates that match a pagename in your rewrite.
You could also consider Custom Post Types if you have a series of pages (perhaps with shortcodes?) that you want to be able to add in but hide from the editor.