Im creating a plugin with the following structure:
plugins (folder) - myplugin (folder) - myplugin_index.php (adminpanel file) - myplugin_ajax.php (loading data when user enters a form on the "start page") themes (folder) - mytheme (folder) - template_my_own.php (this file have the form which calls the myplugin_ajax.php)
The plugin works just fine from the admin panel point of view. I have added data through the plugin from the admin panel.
But when I try to access data through the form in the file template_my_own.php
I get the following error:
PHP Fatal error: Call to undefined function get_option() in /var/www/example.com/wwwroot/wp-content/plugins/myplugin/myplugin_ajax.php on line 14, referer: http://example.com/
I have tried the solutions from both this site.
None of them work though. My code lookes like this:
<?php
/*
Plugin Name: Myplugin
Plugin URI: http://example.com
*/
?>
<?php
$square = $_POST['square'];
//Get arrays and remove empty array values
$arrayFrom = array_filter(get_option('from'), 'strlen');
$arrayTo = array_filter(get_option('to'), 'strlen');
$arrayPrice = array_filter(get_option('price'), 'strlen');
//Sort arrays
asort($arrayFrom);
asort($arrayTo);
asort($arrayPrice);
//Go through values until we find the one
foreach($arrayFrom as $index => $from)
{
if($from < $square && $arrayto[$index] > $square)
{
echo $from;
echo '<br>TESTTESTTEST';
echo $to;
}
}
?>
How should I solve this and what am I doing wrong?