Skip to content

Fixing WordPress Multisite Compatibility Issues in Tutor LMS#2750

Open
commercial-hippie wants to merge 1 commit into
themeum:4.0.0-devfrom
commercial-hippie:4.0.0-dev
Open

Fixing WordPress Multisite Compatibility Issues in Tutor LMS#2750
commercial-hippie wants to merge 1 commit into
themeum:4.0.0-devfrom
commercial-hippie:4.0.0-dev

Conversation

@commercial-hippie
Copy link
Copy Markdown

This PR resolves multiple database, schema installation, and page-rendering bugs when running Tutor LMS on a WordPress Multisite network (specifically where subsites use a custom table prefix like wp_2_).

1. Bypassing Subsite Prefixes for Shared Global Tables

  • Problem: In a WordPress Multisite, global tables like wp_users, wp_usermeta, wp_blogs, etc., are shared network-wide and do not receive subsite prefixes. Tutor LMS's QueryHelper::prepare_table_name() automatically prepends the subsite table prefix (wp_2_) to all incoming tables, causing SQL execution failures like Table 'wp_2_wp_users' doesn't exist.
  • Fix: Updated QueryHelper::prepare_table_name() to recognize all standard global WordPress tables (e.g. $wpdb->users, $wpdb->usermeta, $wpdb->blogs, etc.) and return them unmodified without prepending the prefix.

2. Resolving Hardcoded Foreign Key Constraint Name Conflicts

  • Problem: MySQL/InnoDB requires foreign key constraint names to be globally unique within the database schema. Tutor LMS hardcoded constraint names (such as fk_tutor_itemmeta, fk_tutor_ordermeta_order_id, etc.) in its table creation SQL statements. Activating or upgrading the plugin on a second subsite would fail with errno: 150 (Foreign key constraint is incorrectly formed) because the constraint name was already registered by the primary site.
  • Fix: Modified Tutor.php and Upgrader.php to dynamically prefix all database constraints with {$wpdb->prefix} (e.g., fk_{$wpdb->prefix}tutor_itemmeta), preventing schema conflicts across multiple sites.

3. Resolving Instructor Dashboard Render Crash

  • Problem: The main /dashboard/ page crashed (showing only the header and failing to render the content/footer) because WithdrawModel::get_withdraw_summary hardcoded the query source as FROM {$wpdb->prefix}users u. Since there is no site-specific users table (wp_2_users), the query threw a fatal SQL exception.
  • Fix: Corrected the query in WithdrawModel.php to reference the global $wpdb->users table instead.

@commercial-hippie
Copy link
Copy Markdown
Author

Related #2169

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