[wp-hackers] "deprecating" direct calls to wp-config.php
wp at xentek.net
Tue Nov 17 15:49:16 UTC 2009
> Isn't there any way to make everybody happy (ie finding a way to
> properly locate the wp-config.php whatever the installation path is?).
Doing it the right way will make everybody happy. :)
You DO NOT need to include wp-config.php for ajax in the admin nor the
front-end, nor for just about anything else you might want to do in
Your processing function should look like this:
// do stuff and echo results
Your ajax js should pass action=myhook somewhere in its request
payload, and post to wp-admin/admin-ajax.php... <?php echo
admin_url("admin-ajax.php"); ?> is your friend here.
More Info: http://codex.wordpress.org/AJAX_in_Plugins
Add your script using a function that calls wp_enqueue_script:
This function should hook in on admin_print_scripts. If you want to
limit it to a certain page you can use the "admin_print_scripts-*"
hook, where * is the page hook.
Briefly explained here: http://codex.wordpress.org/Plugin_API/Action_Reference#Administrative_Actions
and here: http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head-%28plugin_page%29
Bottom line is that if your functionality is encapsulated properly in
a plugin, you'll have full access to all of WordPress's API and there
is almost nothing that you won't be able to accomplish. Plugin
Development can be a departure from what you're used to doing as PHP
Developer. I spent many years as a developer and never even considered
using a callback (http://en.wikipedia.org/wiki/Callback_%28computer_science%29
), but WordPress makes extensive use of them, because as a language
construct they are incredibly powerful ways to let plugins do their
thing during various stages of the WP execution life cycle.
- Eric Marden
More information about the wp-hackers