I am currently writing a chatbox plugin for Wordpress.
This plugin uses a jQuery.post() method to send data to a php file in order to write the output to an html file, which in turn will be loaded to the chat window using jQuery.
Inside the php file I use to write the chat log to an html file I need to use Wordpress API functions, but this php file is not included by Wordpress, and therefore has no access to the Wordpress API.
Is there a way to send this chat data to a php file that is included by Wordpress so I can use the Wordpress API? What would be the best way to tackle this problem?
You can use
wp_localize_script
for sending ajax url in a JavaScript object to the pages:Then you can add an action and handle the request. http://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_%28action%29
And for getting the url using JavaScript you can code:
Instead of having a separate PHP file, wrap it in WordPress plugin. WordPress Codex will tell you how to write a plugin and how to wire it up to handle your ajax request.
Once you have it working as a plugin you will be able to access all WordPress APIs.