Support non-standard directory structures

Sometimes the theme and/or plugin directories will no be in ABSPATH. So first, we should check if the script is in WP_CONTENT_DIR, then WP_PLUGIN_DIR, then the theme root. Finally, fall back to using ABSPATH. Whichever first matches, replace the path values and use the URL accordingly.
Fix strange redirect

Using the built-in 'p' query variable would redirect to an actual post if it was set to a real post's ID.  This was not intentional.  Switching instead to 'pid' to prevent redirects.