I’m working on a plugin which submits data via a form from a custom admin page. This is a simplified version of my form:
<form action="<?php echo plugin_dir_path(); ?>/process.php" method="post"> <input type="text" name="keyName"> <input type="submit" value="Update"> </form>
The form is inside my main php file for the plugin, so it has access to all the wordpress functions like the plugin_dir_path() I called above.
However when the user clicks the “submit” button, and the $ _POST variable is submitted to the “process.php” script, I lose access to all the wordpress functions in that process script.
I searched how to add wordpress functions into external scripts and I saw this question: How can I call WordPress core functions in external scripts?
The answer provided is that I include this line of code at the top of my processing script:
However when I do the “wp-load.php” is appended to the end of the current url which results in a 404 type error. I can’t use the “get_site_directory()” function to point to the main wordpress install directory because it’s a wordpress function.
How can I make this work? Is there an action hook I should be using to submit the form vs my own custom submit button?