WordPress f**** with its best featureFiled Under: Plugin-Practices, plugins
In WordPress 2.6 a lot of plugins could fail if they are not updated. The changes are explained by Ozh in What plugin coders know about WordPress 2.6.
The change allows WordPress users to move their config file and the contents of the wp-content folder to a different directory, which seems like a good move for security purposes but can make it difficult to code for since you often need to know where these files are before you can access any WordPress variables.
I need to update all my plugins, that’s a given, but I also need to update the plugin generator. I think I have a handy solution but I want to open it up to feedback before I make any changes.
My solution is to use the following function which will check each directory for the presence of either of the critical files, wp-load.php or wp-config.php; for example:
function get_config(){ $root = dirname(__FILE__); while(!file_exists($root.'/wp-load.php') && !file_exists($root.'/wp-config.php')){ $root = dirname($root) } return $root; }
I think it is also worth checking the plugin directory, i.e. the directory that is wp-content/plugins/ by default for a specifically named text file, perhaps plugin-paths.txt or similar so that the information can be provided manually by the blog owner.
I would appreciate any thoughts you might have on this.
- Permalink
- Andrew Rickmann
- 3 Jul 2008 7:03 AM
- Comments (3)
July 3rd, 2008 at 10:15 am
I recently found some helpful code examples here.
It`s German but it may help you to change your configuration so that you can simply change the plugin path for all the plugins you are currently making use of.
July 3rd, 2008 at 10:54 am
I think that your loop would need an emergency break in case in fails to find either one of the two files up the tree like so:
while ($root && $root != '.' && !file_exists($root.'/wp-load.php' ...)
July 3rd, 2008 at 12:41 pm
Oliver, thanks for the link, but those examples don’t address the situation where you need to find include the config file manually, e.g. if you are responding to ajax requests.
Chris, thanks for that. You are right, that’s what I get for rushing my posts.