Skip to content

Fix: uninstall.php's announcement-delete query never actually runs - #94

Open
smtturkan-droid wants to merge 1 commit into
EvanHerman:masterfrom
smtturkan-droid:fix/uninstall-delete-query-broken-table-name
Open

smtturkan-droid wants to merge 1 commit into
EvanHerman:masterfrom
smtturkan-droid:fix/uninstall-delete-query-broken-table-name

Conversation

@smtturkan-droid

Copy link
Copy Markdown

Hi Evan,

Small, scoped fix in uninstall.php.

What

$sql = $wpdb->get_results( $wpdb->prepare( 'DELETE FROM %s WHERE post_type = "te_announcements"', $wpdb->posts ), ARRAY_A );

%s in $wpdb->prepare() quotes its value as a string literal, so the query that actually runs is:

DELETE FROM 'wp_posts' WHERE post_type = "te_announcements"

A single-quoted table name isn't a valid identifier under default MySQL sql_mode, so this fails silently - when a user enables "delete announcement posts on uninstall," nothing actually gets deleted.

Fix

Interpolate $wpdb->posts directly instead of going through prepare()'s %s (it's an internal WP value, not user input, so no escaping is needed here) - the same pattern this file already uses correctly a few lines down for {$wpdb->prefix}options.

What I did NOT touch

Nothing else in the file or the rest of the plugin.

Verification

php -l uninstall.php - no syntax errors. This only runs on uninstall so I couldn't easily exercise it end-to-end without a disposable WP install; happy to do that if you'd like before merging.

🤖 Generated with Claude Code

$wpdb->prepare( 'DELETE FROM %s WHERE post_type = "te_announcements"', $wpdb->posts )
uses the %s placeholder for a table name. prepare() escapes and quotes
%s as a string literal, so the query wpdb actually runs is:

  DELETE FROM 'wp_posts' WHERE post_type = "te_announcements"

A single-quoted table name isn't a valid identifier under default
MySQL sql_mode, so this fails silently - the "delete announcement
posts on uninstall" option never actually deletes anything.

Fixed by interpolating the table name directly (it comes from $wpdb,
not user input, so no escaping is needed) - the same pattern already
used correctly elsewhere in this same file for $wpdb->prefix . 'options'.

Verified with php -l (no syntax errors).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant