[wp-hackers] Request new function: get_plugininfo()

Sean Hickey seanhickey at gmail.com
Tue Aug 15 18:55:31 GMT 2006


Howdy all,
  I'd like to request that a new function be added to WordPress.  Like
many plugin developers, at some point or another I need to find out
the path to my plugin's directory, and many times the URL to my
plugins directory.

  I see this being done in a lot of plugins.  Personally I use
define() right at the start of my plugins to define that info.  I just
cracked open the Sidebar Widgets plugin, and it does it a little
different, but for the same end purpose.

  So I'd like to see a function added to WordPress, possibly named
get_plugininfo() (similar to get_bloginfo()).  With this function a
plugin can get that info without needing to define it itself.  So a
plugin could call the function like this:

get_plugininfo('url')

  To get the URL to it's directory, or:

get_plugininfo('path')

  To get the full path to it's directory.

I've already written the functions and tested them.  Here is the
source code: http://www.headzoo.com/get_plugininfo.phps

  It uses two functions to set and get from the $pluginInfos global
array.  A change will have to be made to the wp-settings.php file,
adding add_plugininfo() calls as the plugins are being loaded.

  The get_plugininfo() function uses PHP's debug_backtrace() to find
out which plugin called the function.  I did some profiling which
called the get_plugininfo() 1,000 times, and it only added 0.137
seconds to WordPress's total execution time.  That's pretty good
itself, even though the function would likely only be called a few
dozen times total.

  Thoughts?

- Sean
-- 
http://www.headzoo.com


More information about the wp-hackers mailing list