I am having a hard time articulating exactly what it is that I am needing/doing wrong.
I am writing a plugin for WordPress that has multiple PHP files that are called via AJAX.
The issue I am having is how do you tell wordpress that a URL is relative to a plugin?
I have following code in the pluginname.php
file:
function build_form() {
// hacky way of providing the url to the front end.
echo ("<script> var submit_url = \"" . plugin_dir_url( __FILE__ ) . "submit.php \" </script>");
$asubHTML = file_get_contents(plugins_url('/estimate-form.php',__FILE__ ));
echo $asubHTML;
}
//used on a page like a widget
add_shortcode( 'estimate-form', 'build_form' );
Then on the front-end we post to the echo'd URL.
$.ajax({
url: submit_url,
data: {},
type: 'POST'
});
It works fine as far as telling the plugin what the submitted URL is, but seems a little hacky.
But when you get to the actual PHP script that is called, you are no longer within the scope of the WordPress framework and as such, the WordPress functions will not work. e.g.
wp_mail(),plugin_dir_url()
I feel like I am missing something very fundemental to do with registering URL's or something similar in the plugin file.
If I can be more clear, please do let me know how.