Missing learnpress database tables after fresh installation
-
After a fresh installation and activation of learnpress plugin (latest version 4.1.3.1) not all database tables will be created in database! Because of that I got an error (error 402) while ordering a course, because the database tables learnpress_order_itemmeta and learnpress_order_items (among others) were missing.
After a couple of hours code research I found the mistake in
wp-content/plugins/learnpress/inc/class-lp-install.phpwhere theCREATE TABLE IF NOT EXISTSstatements are defined in function_get_schema(). They will be passed to the functiondbDelta()inwp-admin/includes/upgrade.phpfor creating the db tables. The functiondbDelta()is very sensitive to the givenCREATE TABLEstatements and can not processCREATE TABLE IF NOT EXISTSstatements as they are defined! Because of that the function extracts the table name “IF” (the word after CREATE TABLE) but not the real table name for every CREATE sql statement which is used as a hash key for storing the sql statement for the table. This leads to create only one more table every time the functiondbDelta()is called with database tables not created yet.Another issue with the function
dbDelta()is that PRIMARY KEY must be followed by two spaces (as I found in some forums) and you can not use FOREIGN KEYS. Oh my god what a bad function provided by wordpress! After deleting “IF NOT EXISTS” in the CREATE TABLE statements the tables will be created flawless.I hope the developer of learnpress will fix this soon and will test the code for installing a fresh learnpress plugin in future?
Please tell me if I am right with the description above?
Thanx!
The topic ‘Missing learnpress database tables after fresh installation’ is closed to new replies.