Access WordPress database outside of WordPress

MAIN QUESTION:

I am writing a wp plugin. Within it, I have a page located here:

Read More
http://example.com/wordpress/wp-content/plugins/myplugin/page.php

How do I access WP database from this page? Is there any official, proper way that won’t break with updates? Or any reliable way at all?


As a second possibility (not preferred) – I was thinking maybe my plugin could create a wordpress page, which then would be somewhere like:

http://example.com/myplugin/index.php

Is this possible? And how would it react to user’s changes of permalinks settings?

Related posts

Leave a Reply

1 comment

  1. In a nutshell there is no generic reliable way to load WordPress core from arbitrary file. Since core and extensions directories are independent from each other (they are co-located by default, not by necessity) only core configuration “knows” where extensions are, but not other way around.

    In private code things like this just get hardcoded. In public code this is pretty much undoable properly.

    If it’s not critical for you to modify core load process then custom URL is definitely way to go. Implemented via Rewrite API from scratch or as endpoint it will be reasonably reliable.