Create rewriterules for different domains in htaccess file with WP multisite

If you wanted to target a specific domain then you need a condition (RewriteCond directive), preceding the RewriteRule that checks for the specific domain (Host: header). For example: RewriteCond %{HTTP_HOST} ^domainb\.com [NC] RewriteRule ^i-like-([a-zA-Z0-9-]+)/$ wp-content/themes/customtheme/custom-pages/ilike.php?like=$1 [L] The HTTP_HOST server variable contains just the Host: header sent in the request. Reference: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond

Custom taxonomy query not working with switch_to_blog

I find the solution: Tax_query not working on multisite (I dont say, that I work with switch_to_blog, because everything is works fine with this function… everything, including postmeta queries, category__not_in, etc., but EXCEPT: tax_query) So, “you have to register that custom taxonomy in both blogs”. <– so the problem originate from the different themes, when … Read more

Assign role to user on first login, if they are first (after admin)

To set is the connected user belongs to the blog, you need to do that on hook wp_login that means the user is connected : const ROLE_ADMINISTRATOR = “administrator”; const ROLE_CONTRIBUTOR = “contributor”; add_action(“wp_login”, function ($user_login, \WP_User $user) { if ( !is_multisite() || is_user_member_of_blog() ) { return; } $usersAdministrator = get_users([ “role” => ROLE_ADMINISTRATOR, ]); … Read more

Rest API Multisite Site List?

There is no built-in endpoint for sites on a multisite network. As can be seen in the documentation, the built-in endpoints are: +—————-+——————-+ | Posts | /wp/v2/posts | +—————-+——————-+ | Post Revisions | /wp/v2/revisions | +—————-+——————-+ | Categories | /wp/v2/categories | +—————-+——————-+ | Tags | /wp/v2/tags | +—————-+——————-+ | Pages | /wp/v2/pages | +—————-+——————-+ | … Read more

Multisite installation but do plugins always have to be multisite compatible?

They shouldn’t have to be multisite compatible. Also remember that, there are two kinds of Passive compatibility: doing nothing multisite specific, just works without breaking anything. Active compatibility: changing or extending multisite specific behavior. In case the plugin you want to use doesn’t say anything about its compatibility on multisites, you just have to try … Read more

restore_current_blog required after switch_to_blog, if I use that in a function?

switch_to_blog changes values of global variables (as you can see here: https://core.trac.wordpress.org/browser/tags/5.0.3/src/wp-includes/ms-blogs.php#L801). It doesn’t matter if you call it in function or not – these variables will get changed. So yes – you always have to call restore_current_blog when you’ve done all you wanted with the switched blog. Otherwise these variables will stay changed (so … Read more