• 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)
  • Thread Starter Chris

    (@crisbrand)

    PS.

    After updating the issue, I also found the error here

    /public_html/wp-includes/functions.php on line 6022 -> /public_html/wp-includes/class-wpdb.php on line 1478 ->

      global $wpdb;

          $tablename = esc_sql($wpdb->prefix . 'ee_product_feed');

          $sql = $wpdb->prepare("select * from
    $tablename ORDER BY id ASC LIMIT 1", array());

          $result = $wpdb->get_results($sql);

          if ((isset($tvc_add_data_admin_notice['google_merchant_id']) && $tvc_add_data_admin_notice['google_merchant_id'] != '')

            && is_array($result) && isset(end($result)->feed_name) && end($result)->feed_name != 'Default Feed'

            && isset(end($result)->is_mapping_update) && end($result)->is_mapping_update == '0'

          ) {

            $link_title = "Click here to create.";

            $content = "Attention: Your GMC (Google Merchant Center) account is successfully connected, but it appears that you have not processed your product feed yet.";

            $status = "1";

            $link = "admin.php?page=conversios-google-shopping-feed&tab=feed_list";

            $this->tvc_add_admin_notice("no_product_sync", $content, $status, $link_title, $link, "", "", "9", "no_product_sync");

          } else {

            $link_title = "Click here to create.";

            $content = "Attention: Your GMC (Google Merchant Center) account is successfully connected, but it appears that you have not processed your product feed yet.";

            $status = "0";

            $link = "admin.php?page=conversios-google-shopping-feed&tab=feed_list";

            $this->tvc_dismiss_admin_notice("no_product_sync", $content, $status, $link_title, $link);

          }
    correct code


         //if user has linked google merchant center account and not synced any product.

          global $wpdb;

          $tablename = esc_sql($wpdb->prefix . 'ee_product_feed');

          $sql = "SELECT * FROM
    $tablename ORDER BY id ASC LIMIT 1";

          $result = $wpdb->get_results($sql);

          if ((isset($tvc_add_data_admin_notice['google_merchant_id']) && $tvc_add_data_admin_notice['google_merchant_id'] != '')

              && is_array($result) && isset(end($result)->feed_name) && end($result)->feed_name != 'Default Feed'

              && isset(end($result)->is_mapping_update) && end($result)->is_mapping_update == '0'

          ) {

              $link_title = "Click here to create.";

              $content = "Attention: Your GMC (Google Merchant Center) account is successfully connected, but it appears that you have not processed your product feed yet.";

              $status = "1";

              $link = "admin.php?page=conversios-google-shopping-feed&tab=feed_list";

              $this->tvc_add_admin_notice("no_product_sync", $content, $status, $link_title, $link, "", "", "9", "no_product_sync");

          } else {

              $link_title = "Click here to create.";

              $content = "Attention: Your GMC (Google Merchant Center) account is successfully connected, but it appears that you have not processed your product feed yet.";

              $status = "0";

              $link = "admin.php?page=conversios-google-shopping-feed&tab=feed_list";

              $this->tvc_dismiss_admin_notice("no_product_sync", $content, $status, $link_title, $link);

          }



    • This reply was modified 8 months ago by Chris.
Viewing 1 replies (of 1 total)
  • The topic ‘Plugin causes error The wpdb::prepare function was called incorrectly’ is closed to new replies.