Hi all,
I’m developing a plugin using AI tools, and I’m struggling with WordPress.org’s review process. They recommend that I follow this pattern for defining table names in the database:
$table_name = "{$wpdb->prefix}myTable";
$myID = 12;
$wpdb->query( $wpdb->prepare( "UPDATE $table_name SET your_column_1 = 1 WHERE $table_name.your_column_id = %d", $myID ) );
The problem arises with the current code generated by my AI tools, which fails repeatedly:
$table_name = "{$wpdb->prefix}" . MYTOOL_PREFIX . 'temp_data';
// Check if the table exists
$table_exists = $wpdb->get_var(
$wpdb->prepare(
"SHOW TABLES LIKE %s",
$table_name
)
);
if (empty($tableexists)) {
echo '<p>' . esc_html_('Required database table does not exist. Please deactivate and reactivate the plugin.', 'mytool') . '</p>';
return;
}
// Fetch results from the custom table
$results = $wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM " . $wpdb->prefix . MYTOOL_PREFIX . "temp_data LIMIT %d",
1000
),
ARRAY_A
);
WordPress.org insists on following the prefix rule to ensure compatibility with installations that use a different prefix than the default. I get that – but even though I’ve made changes, the WordPress Checker tool or their review team still rejects it. I keep getting stuck in a loop where either the tool or the dev team (working with AI tools) flags the changes.
I’ve tried following the guideline:
$table_name = "{$wpdb->prefix}myTable";
But my development AI tools don’t seem to like it and keep making automatic adjustments to the code, leading to more issues.
Has anyone else experienced something similar or can offer some insights on how to resolve this? What’s the best approach to ensure the plugin is compliant with WordPress standards while using AI-generated code?
Thanks in advance!
