Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for WordPress Multisite #101

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

rafaucau
Copy link
Contributor

@rafaucau rafaucau commented Dec 18, 2024

Resolves #100

@rafaucau rafaucau changed the title fix(multisite): update table prefix after blog switch Add support for WordPress Multisite Dec 18, 2024
@rafaucau
Copy link
Contributor Author

rafaucau commented Dec 18, 2024

When I use:

add_action('switch_blog', function () {
    $this->setTablePrefix($this->db->prefix);
});

This only works partially. It works correctly in the model's getTable() method, but then there's an error when executing the query:

Fatal error: Uncaught Exception: Table 'wordpress.wp_2_wp_2_posts' doesn't exist in wp-orm/src/Orm/Database.php:395

I can't find the place that could be causing generation of a double prefix after executing the setTablePrefix() method. It's not the table method or other similar ones in the Database class.

I'll reset the entire instance:

add_action('switch_blog', function () {
    self::$instance = null;
});

This works correctly.

Copy link
Owner

@dimitriBouteille dimitriBouteille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rafaucau

Thank you for your contribution!

I made 2 small feedbacks. Before validating the PR, I want to take the time to test and write some tests.

I hope to validate this RP in February for the 4.2.0.

src/Orm/Database.php Outdated Show resolved Hide resolved
src/Models/Multisite/Blog.php Outdated Show resolved Hide resolved
@dimitriBouteille dimitriBouteille changed the base branch from main to develop January 25, 2025 21:32
@dimitriBouteille dimitriBouteille added enhancement New feature or request v4 labels Jan 25, 2025
@dimitriBouteille dimitriBouteille added this to the 4.2.0 milestone Jan 25, 2025
rafaucau and others added 2 commits January 26, 2025 09:31
Co-authored-by: Dimitri BOUTEILLE <34821762+dimitriBouteille@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development enhancement New feature or request v4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: Incorrect table prefixes in WordPress Multisite environment
2 participants