[wp-hackers] Friendly plugin URL entrypoints?
Owen Winkler
ringmaster at midnightcircus.com
Fri Feb 3 14:34:59 GMT 2006
Would it be worthwhile to have a dedicated friendly-style URL entry
point for plugins? For example...
I have a couple plugins that employ Ajax. I have a couple that generate
javascript based on a request. It would be useful to have a URL that
was an entry point to those features that didn't include three
directories of depth of wp organization.
Instead of requesting:
http://example.com/wp-content/plugins/myplugin/myplugin.php?entrypoint=1
I could request something like:
http://example.com/_plugin/myplugin/1
And I could generate that URL by calling something like:
get_plugin_entrypoint('myplugin', 1);
And just maybe a request of that URL could fire a hook:
do_action('entrypoint_myplugin', 1);
Which I would register by calling:
register_entrypoint('myplugin', 1, 'my_entrypoint_function');
Yes, I can modify the rewrite rules in my plugin to handle this. But
I'll do it in every plugin I write that uses javascript like this, which
would repeat a bunch of code. If some other developer does it, we'll be
cluttering the site's URL landscape with plugin entrypoints, and it
might be nice to put them all in one place. Something like this could
make it much easier to implement Ajax (and other javascript techniques)
via plugin to provide a more rich user experience.
Does this seem worthwhile? Does it seem doable?
I've been writing a couple of new things that use a few complicated
javascript techniques, and it occurs to me that this is simply not poetry:
class AjaxPlugin {
function AjaxPlugin () {
if(defined('ABSPATH')) {
add_action('wp_header',
array(&$this, 'wp_header'));
}
}
function solo() {
// Do things when the plugin file is loaded by
// itself but that also require WP functions/data
}
function include_up() {
// This function finds a file in
// progressive parent directories
return $file_location;
}
function wp_header() {
// Create a reference to this file in a script tag
echo '<script type="text/javascript" src="'
. $this->pluginuri . '"></script>';
}
function pluginuri() {
// Return the URI of this file in the plugins dir
return get_settings('siteurl')
. '/wp-content/plugins/'
. plugin_basename(__FILE__);
}
}
$ajaxplugin = new AjaxPlugin();
if(!defined('ABSPATH')) {
// Must include wp-config.php at the global scope.
include($ajaxplugin->include_up('wp-config.php');
$ajaxplugin->solo();
}
Suggestions for prettier alternatives are welcome.
Owen
More information about the wp-hackers
mailing list