Hi guys,
I've created a simple plugin for Wordpress that interacts with an API in the backend.
The problem is that everything is inserted twice in the database, and I cannot figure out why.
The form is submiting only once, not twice.
What could it be ?
Redirects from my .htaccess ?
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
My function from the plugin, this is the logs table and after that i'm calling get_curl_data()
function.
function verifica_disponibilitate_curl($post) {
$sdstr = '';
global $wpdb;
$tblname=$wpdb->prefix."disponibilitate_log";
$insert = "INSERT IGNORE INTO ".$tblname." (data_verificata) VALUES('".$wbdb->escape($post['data_verificata'])."');";
$rows_affected = $wpdb->query($insert);
$curl = get_curl_data($post['data_verificata']);
if(count($curl) == 0) {
$sdstr = 'Datele de configurare API nu sunt corecte!';
} else {
$sdstr = $curl['mesaj'];
}
return $sdstr;
}#function verifica_disponibilitatea
The get_curl_data()
function looks like this.
function get_curl_data($data_verificata = '') {
global $wpdb;
$tblname=$wpdb->prefix."disponibilitate_config";
$select = "SELECT * FROM ".$tblname."";
$query = $wpdb->get_results($select);
foreach($query as $data) {
// Datele de conectare pentru API
$username = $data->username;
$password = $data->password;
}
// Data Cautata
$data = $data_verificata;
// Apelarea host-ului pentru rezultate impreuna cu data cautata
$host = "http://bysobi.com/api/disponibilitate/data/api/".$data;
// Initializare curl pentru a extrage rezultatele
$process = curl_init($host);
curl_setopt($process, CURLOPT_HEADER, FALSE);
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($process);
return json_decode($response,true);
}