I am creating a wordpress plugin that takes form inputs and stores them as wordpress options. However, I receive the error Fatal error
: Uncaught Error: Call to undefined function update_option() in C:\xampp\htdocs\wordpress\wp-content\plugins\maxipoo-inventory\form-processing.php:6 Stack trace: #0 {main} thrown in
C:\xampp\htdocs\wordpress\wp-content\plugins\maxipoo-inventory\form-processing.php
on line
**6
**when I hit the submit button of my form.
Here is form-processing.php:
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$consumer_key = $_POST['consumer-key'];
$consumer_secret = $_POST['consumer-secret'];
update_option("mp_consumer_key", $consumer_key);
update_option("mp_consumer_secret", $consumer_secret);
}
Here is my form if it matters:
<form id="api-key-form" method="post" action="<?php echo plugins_url('form-processing.php', dirname(__FILE__)); ?>">
<input type="hidden" name="action" value="api_key_form">
<div class="api-key-form-input">
<label for="consumer-key" class="bold">Consumer Key:</label>
<input type="text" id="consumer-key" name="consumer-key" required><br>
</div>
<div class="api-key-form-input">
<label for="consumer-secret" class="bold">Consumer Secret:</label>
<input class="api-form-text-input" type="text" id="consumer-secret" name="consumer-secret" required>
</div>
<div id="api-key-form-submit-wrap">
<input type="submit" value="Save" id="api-key-form-submit-btn">
</div>
</form>
Interestingly, I originally had the standard if (!defined('ABSPATH')) { exit; }
at the beginning of form-processing.php, but my if
statement wouldn't run unless it was removed (I removed it and replaced the update_option()
with an echo
and my text was indeed echoed). This almost certainly means that ABSPATH
isn't defined in this context. If ABSPATH
isn't defined, then it makes sense why the update_function()
isn't defined either; I'm not in a wordpress environment for some reason. However the url in the error I provided clearly shows that I'm hosting wordpress using XAMPP.