PlaceSpeak / wp-placespeak-connect

A Wordpress plugin for code-free integration of PlaceSpeak's "Connect" GeoID API.
https://www.placespeak.com/connect/about/
1 stars 0 forks source link

Don't call core loading files directly #12

Open hughstimson opened 7 years ago

hughstimson commented 7 years ago

From the Wordpress plugin directory reviewers:

Calling core loading files directly

Including wp-config.php, wp-blog-header.php, wp-load.php, or pretty much any other WordPress core file that you have to call directly via an include is not a good idea and we cannot approve a plugin that does so unless it has a very good reason to load the file(s). It is prone to failure since not all WordPress installs have the exact same file structure.

Usually plugins will include wp-config.php or wp-load.php in order to gain access to core WordPress functions, but there are much better ways to do this. It's best if you tie your processing functions (the ones that need but don't have access to core functions) into an action hook, such as "init" or "admin_init".

Please consult the Plugins API reference for more information: http://codex.wordpress.org/Plugin_API

If you're trying to use AJAX, please read this: http://codex.wordpress.org/AJAX_in_Plugins

For other possibilities, or to better understand why we disallow this, read this: http://ottopress.com/2010/dont-include-wp-load-please/

If you're trying to use it because you need to access WordPress functions outside of WordPress, we'd actually much rather you didn't do that at all. Your plugin should be inside WordPress, only accessible to people who are logged in and authorized, if it needs that kind of access. Your plugin's pages should be called via the dashboard like all the other settings panels, and in that way, they'll always have access to WordPress functions.

I think this requirement presents some difficulties in our context. I've tried one possible solution without success. I have described a little in this statck overflow post: http://wordpress.stackexchange.com/questions/246447/accessing-the-database-from-a-plugin-outside-of-action-hooks

Namely:

Because the endpoint is not part of the Wordpress admin interface, there are no hooks to wrap it in (I think?).

I tried requiring the "stripped down" version of wp-load, e.g.

define( 'SHORTINIT', true );
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'wp-load.php');

but that produced a Call to undefined function trailingslashit() error when I perform a database query using wpdb as above, which appears to be [a known limitation][2] of using the SHORTINIT version of wp-load.

I've received a response which jives with comments I've seen on related questions, suggesting we need to create a custom endpoint. I started working on that but got bogged down.

soulseekah commented 7 years ago

Fixed in PR #15 using the simpler $_GET parameter method as explained here: https://wordpress.stackexchange.com/questions/246447/accessing-the-database-from-a-plugin-outside-of-action-hooks