Skip to content

Feature Request: Support for limited subsite associations #143

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

Closed
Idealien opened this issue Apr 7, 2020 · 7 comments
Closed

Feature Request: Support for limited subsite associations #143

Idealien opened this issue Apr 7, 2020 · 7 comments
Assignees
Milestone

Comments

@Idealien
Copy link
Contributor

Idealien commented Apr 7, 2020

Description
The plugin is exceptional when a multi-site setup has every sub-site representing a different language of the same content. However, when a multi-site has multiple actual content sub-sites, there are multiple places where the UI presents all sub-sites for selection that are not appropriate for use case such as:

  • Post Edit Screen - Doc Sidebar for MLSwitcher - Separate drop-down per sub-site
  • Post Lists Screen - Separate column per translation/potential translation
  • Front-End Site - When Menu Settings/Theme Location defined

To Reproduce

  • Create a multi-site network with 8 sub-sites (EN1, EN2, EN3, EN4, FR1, FR2, FR3, FR4)

Expected behaviour

  • Provide an option under Multisite Language Switcher Options / Main Settings that lets each site be (optionally) associated to N number of sites. (multi-select field type)
  • When this has been defined, anywhere that currently displays ALL sub-sites would only display the associated sub-sites.
  • In reproduced example, EN1/FR1 would see each other, EN2/FR2, etc.

There is a code-based temporary solution possible through the msls_blog_collection_construct filter

add_filter( 'msls_blog_collection_construct', 'msls_sites_collection_restrictions' );
function msls_sites_collection_restrictions( $sites ) {

	$restrict = true;

	//Ensure front-end only are restricted.
	if ( is_admin() && isset( $_GET['page'] ) ) {
		$admin_path = strtolower( sanitize_text_field( $_GET['page'] ) );
		if ( $admin_path === 'mslsadmin' ) {
			$restruct = false;
		}
	}

	if ( ! $restrict ) {
		return $sites;
	}

	//Find out the current blog and let it's language counterpart be displayed.
	//@TODO - Refactor this so the en/fr association is stored in site options.
	$current_blog_id = get_current_blog_id();

	switch ( $current_blog_id ) {

		case 1:
			$keep_blog_id = 2;
			break;
		case 2:
			$keep_blog_id = 1;
			break;
		case 3:
			$keep_blog_id = 4;
			break;
		case 4:
			$keep_blog_id = 3;
			break;
	}

	foreach ( $sites as $key => $site ) {
		if ( $key !== $keep_blog_id && $key !== $current_blog_id ) {
			unset( $sites[ $key ] );
		}
	}

	return $sites;
}

Screenshots
image
image

Environment (please complete the following information):

  • OS: Linux
  • Browser: All
  • PHP Version 7.2
  • Plugin Version: 2.3 and 2.4.3
@Idealien
Copy link
Contributor Author

Idealien commented Sep 6, 2020

Hoping this could be flagged as an enhancement item for 2.5?

I have updated the temporary workaround code mentioned above to read from a separate option defined through an ACF meta form. It means that code does not have to update with every new subsite added, but does introduce small issue when migrating subsites between dev/stg/prod environments if the subsite ID changes. Generally, accessing the settings panel (both ACF data and WPMSLS) to re-save settings post migration addresses it.

add_filter( 'msls_blog_collection_construct', 'msls_sites_collection_restrictions' );
function msls_sites_collection_restrictions( $sites ) {
	$restrict = true;

	//Ensure front-end only are restricted.
	if ( is_admin() && isset( $_GET['page'] ) ) {
		$admin_path = strtolower( sanitize_text_field( $_GET['page'] ) );
		if ( $admin_path === 'mslsadmin' ) {
			$restruct = false;
		}
	}

	if ( ! $restrict ) {
		return $sites;
	}

	$current_blog_id = get_current_blog_id();
	$bilingual_id = false;

	//Retrieve bilingual site associated in ACF option stored under 'CPC Settings'
	if ( function_exists( 'get_field' ) ) {
		$bilingual_id = get_field( 'bilingual_subsite', 'option' );
	}

	//Only present the associated language subsite
	if ( $bilingual_id ) {
		$new_sites = array();
		foreach ( $sites as $key => $site ) {
			if ( $site->blog_id == $bilingual_id  || $site->blog_id == $current_blog_id ) {
				$new_sites[ $key ] = $sites[ $key ];
			}
		}
		if ( ! empty( $new_sites ) ) {
			return $new_sites;
		}
	}
	return $sites;
}

@lloc lloc added this to the 3.0.0 milestone Feb 24, 2025
@lloc
Copy link
Owner

lloc commented Feb 24, 2025

Related to #180

@lloc lloc self-assigned this Feb 24, 2025
@Idealien
Copy link
Contributor Author

Idealien commented Mar 3, 2025

While the feature may still have value to others, I am no longer using this plugin or developing solutions that relate to it for multisite based multilingual purposes. Please remove me as an assignee / participant as it seems without closing the issue GH currently doesn't provide me a way to :/

@michakrapp
Copy link

michakrapp commented Mar 19, 2025

WordPress has the "hidden" Multisite feature of creating multiple networks of sites in one multisite installation.
I think this should be the right usage for this issue.

Unfortunately WP currently has no admin screen setting to do this, so either it have to be activated through a plugin or the db.
Maybe a settings screen for that could be added here or in a sub plugin.

With this feature it is possible to use the correct wp functions to handle networks and blogs

@lloc
Copy link
Owner

lloc commented Mar 20, 2025

Hi @michakrapp, are you referring to WP Multi Network? I use that plugin in my own projects and have recently contributed a few PRs there.

As for MSLS, it can already handle this feature request either by using the reference user or through a hook in the blog collection. I’ve left this issue open for discussion, but I believe it could be closed at this point.

I also plan to translate this post soon: https://ploetner.io/de/von-multisites-zu-multi-networks/ — it should provide enough information for this specific use case.

@michakrapp
Copy link

michakrapp commented Mar 20, 2025

Could not remember the plugin name and have not used it yet myself. But on a short look it seems fine.

Just wanted to comment the network feature because I saw this issue.

So far I have not been using the feature myself and it's not planned.

Update: Yes, it was that plugin.

@lloc
Copy link
Owner

lloc commented Mar 21, 2025

Feature request closed because it can be done with WP Multi Network.

@lloc lloc closed this as completed Mar 21, 2025
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

No branches or pull requests

3 participants