I’ve created a rewrite do redirect like:
/mylisting/909 ->/wp-content/themes/myplugin/edit.php?id=909
Which seems to make sense as I’m keeping the very specific logic to an individual plugin.
There is a better way: Create an endpoint, use your code in a callback handler for the new URL. You get the whole theme environment for free here: get_header()
, sidebars, menus etc.
Do not forget to call exit;
at the end of your endpoint, othrwise WordPress will use the theme files again. 🙂
The plugin URI is never a good address to edit or create content: It might be on another domain where the cookies are available, and no user is ever logged in.