Background of the issue:
I am using WPML in a multisite environment and encountering issues with the switch_to_blog() function. My setup includes the latest WordPress version, a multisite installation, and WPML active only on Blog 1. I have a simple plugin that inserts a post after switch_to_blog is called: function wpml_switch_poc_init(): void { $post_arr = [ 'post_title' => 'My very first post', 'post_content' => 'My very first post content', 'post_type' => 'post', ]; $blog_1_post_id = wp_insert_post( $post_arr ); var_dump($blog_1_post_id); switch_to_blog(2); $blog_2_post_id = wp_insert_post( $post_arr ); var_dump($blog_2_post_id); restore_current_blog(); } add_action('plugins_loaded', 'wpml_switch_poc_init'); WPML is not active on Blog 2, and I do not intend to activate it there.
Symptoms:
I expected no usage of WPML filters after switch_to_blog is made and WPML is not active in the target blog, with no error messages. Instead, I received a WordPress database error: Table 'db.wp_2_icl_translations' doesn't exist for query SELECT tra.term_taxonomy_id AS translated_id, IFNULL(corr.term_id, 0) AS correct_parent FROM wp_2_term_taxonomy org JOIN wp_2_icl_translations iclo ON org.term_taxonomy_id = iclo.element_id AND iclo.element_type = CONCAT('tax_', org.taxonomy) JOIN wp_2_icl_translations iclt ON iclt.trid = iclo.trid AND iclt.source_language_code = iclo.language_code JOIN wp_2_term_taxonomy tra ON tra.term_taxonomy_id = iclt.element_id LEFT JOIN wp_2_term_taxonomy parents ON parents.term_id = org.parent LEFT JOIN wp_2_icl_translations parent_lang ON parents.term_taxonomy_id = parent_lang.element_id AND parent_lang.element_type = CONCAT('tax_', parents.taxonomy) LEFT JOIN wp_2_icl_translations iclc ON iclc.language_code = iclt.language_code AND parent_lang.trid = iclc.trid LEFT JOIN wp_2_term_taxonomy corr ON corr.term_taxonomy_id = iclc.element_id WHERE org.taxonomy IN ('category') AND IFNULL(corr.term_id, 0) != tra.parent AND iclt.source_language_code IS NOT NULL made by require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), do_action('plugins_loaded'), WP_Hook->do_action, WP_Hook->apply_filters, wpml_switch_poc_init, wp_insert_post, do_action('save_post'), WP_Hook->do_action, WP_Hook->apply_filters, display_tax_sync_message, do_action('wpml_new_duplicated_terms'), WP_Hook->do_action, WP_Hook->apply_filters, new_duplicated_terms_filter, WPML_Term_Hierarchy_Duplication->duplicates_require_sync, WPML_Term_Hierarchy_Duplication->get_need_sync_all_terms, WPML_Hierarchy_Sync->get_unsynced_elements. WPML filters remain active after using switch_to_blog() despite the plugin not being active on Blog 2.
Questions:
Why are WPML filters still active after using switch_to_blog() when WPML is not active on Blog 2?
How can I prevent WPML filters from affecting Blog 2?
thanks for your help. I tried replicating my issue but unfortunately your provided setup is already different from my setup:
* WPML is not enabled network wide but only on blog 1.
* WPML is not active on Blog
Since you activated WPML network wide the corresponding tables like "wp_2_icl_translations" exist whereas it doesn't trigger the error message.
I altered your test installation to my plugin activation setup (without my test plugin). If you could remove the icl-tables from blog 2 and blog 3 we could test this issue again and verify the problem.
I've uploaded the testplugin though.
Best regards,
Justin
The topic ‘[Closed] Using WPML in a multisite environment causes several issues using switch_to_blog()’ is closed to new replies.
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.