Plugin causes error The wpdb::prepare function was called incorrectly
-
Hi, my client showed an error
[21-Jul-2024 11:57:03 UTC] PHP Notice: The wpdb::prepare function was called incorrectly. The wpdb::prepare() query argument must contain the element to replace. Learn more: Debugging in WordPress. (This message was added in version 3.9.0.) in /…/public_html/wp-includes/functions.php on line 6098
By default, the debug file did not show the problem and what is causing the problem, I wrote a function that checked which plugin causes the problem, it turns out that your plugin has an incorrect SELECT query
Wrong:
$query = $wpdb->prepare("SELECT count(*) as count FROM {$wpdb->prefix}ee_product_sync_data WHERE feedId IS NULL");
Correct code:/*************Check Default feed exists *****************************/
$tablenamesync = $wpdb->prefix . "ee_product_sync_data";
// Zapytanie SELECT bez u?ycia prepare, poniewa? nie ma placeholderów
$query = "SELECT count(*) as count FROM {$wpdb->prefix}ee_product_sync_data WHERE feedId IS NULL";
$result = $wpdb->get_row($query);
if (isset($result->count) && $result->count > 0) {
$last_sync = $this->TVC_Admin_DB_Helper->tvc_get_last_row('ee_product_sync_call', array("last_sync", "create_sync", "next_sync", "status"));
$conv_additional_data = $this->TVC_Admin_Helper->get_ee_additional_data();
$cat = unserialize(get_option("ee_prod_mapped_cats"));
$attr = unserialize(get_option("ee_prod_mapped_attrs"));
$auto_sync_interval = isset($conv_additional_data['product_sync_duration']) ? ($conv_additional_data['product_sync_duration'] == 'Day' ? $conv_additional_data['pro_snyc_time_limit'] : '1') : '25';
$profile_data = array(
'feed_name' => esc_sql('Default Feed'),
'channel_ids' => esc_sql('1'),
'auto_sync_interval' => esc_sql($auto_sync_interval),
'auto_schedule' => esc_sql('1'),
'categories' => wp_json_encode($cat),
'attributes' => wp_json_encode($attr),
'created_date' => esc_sql(gmdate('Y-m-d H:i:s', current_time('timestamp'))),
'last_sync_date' => esc_sql(isset($last_sync['last_sync']) ? $last_sync['last_sync'] : NULL),
'next_schedule_date' => esc_sql(isset($last_sync['next_sync']) ? $last_sync['next_sync'] : NULL),
'total_product' => esc_sql($result->count),
'status' => esc_sql('Synced'),
'is_mapping_update' => esc_sql($conv_additional_data['is_mapping_update']),
'is_default' => esc_sql('1'),
);
$this->TVC_Admin_DB_Helper->tvc_add_row("ee_product_feed", $profile_data, array("%s", "%s", "%s", "%d", "%s", "%s", "%s", "%s", "%s", "%d", "%s", "%d"));
// Poprawione zapytania UPDATE z placeholderami
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}ee_product_sync_data SET feedId = %d WHERE feedId IS NULL", 1));
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}ee_products_sync_list SET feedId = %d WHERE feedId IS NULL", 1));
}
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Plugin causes error The wpdb::prepare function was called incorrectly’ is closed to new replies.