valendesigns / option-tree

Theme Options UI Builder for WordPress. A simple way to create & save Theme Options and Meta Boxes for free or premium themes.
GNU General Public License v2.0
598 stars 180 forks source link

FIX syntax error on plugin activation : You have an error in your SQL… #699

Closed ryanlabelle closed 5 years ago

ryanlabelle commented 5 years ago

Fixed syntax error on plugin activation : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''wp_option_tree' ORDER BY item_sort ASC' at line 1

This was from ot-functions-admin.php - $wpdb->prepare was wrapping the table name in single quotes and MySQL didn’t like that. I took out the parepare because $wpdb->prefix it not meant to operate on user supplied data. I don’t think $wpdb->prefix should be considered user supplied but I suppose you could wrap some escaping code around $wpdb->prefix if you wanted to.

Example from Codex that does this: https://codex.wordpress.org/Class_Reference/wpdb

Some other articles: https://wordpress.stackexchange.com/questions/191729/quotes-in-table-name https://wordpress.stackexchange.com/questions/93830/really-simple-query-giving-error-in-sql-syntax/93861#93861

valendesigns commented 5 years ago

@ryanlabelle Thank you for the PR, I've made some modifications to cache the SQL queries and correct the logic so that if the table doesn't exist it doesn't try to query it. Pushing the updates to the develop branch now.