This is not an issue with slashes. The Blocs WP Plugin is simply not Multisite Compatible
The way Blocs WP Plugin is implemented, it uses Rest API.
And Rest API has no inbuilt endpoint for network, see Reference | REST API Handbook | WordPress Developer Resources.
It only works on single sites by default. Note, single sites means also single sub-domains, in a network, but you need to define the “instance” when you are in a network, before you can chat with the Rest endpoint.
The very least needed would be a blog_id to know what Blog (site) of to get contents, because of course it couldn’t get contents of all sites in the network at once, since this is simply plain impossible in WP (Database tables are separated in a network).
It is not that hard, but requires some additional code in the plugin, and thorough testing, specially because Networks are a bit of a monster.
@Norm - in your plugin you add_action
The callback you use there (
get_blocs_preview) is not considering Multisite.
In that callback, you would have to do something like this:
$args = array(
'public' => 1, // I only want the sites marked Public
'archived' => 0,
'mature' => 0,
'spam' => 0,
'deleted' => 0,
$sites = get_sites( $args );//this returns an array of **Site Objects**. Each object contains: https://developer.wordpress.org/reference/classes/wp_site/#comment-3100
Then, in the same method (you do that already) you get data of “the site”.
However, since you now have an array of sites, you have to decide which site’s information to get.
Thus, something similar to this needs to be done:
* Get the Site ID in the network
* You need to find the [domain] and the [path] in the $sites array of blog objects matching the user input in blocs App.
* If user inputs "site.com/subsite", then you need to find the one that matches:
* domain == site.com and path == subsite in the $sites array of objects.
* Then, return the found object->blog_id to populate your $origin_id.
* Since I do not know how to retrieve Blocs App user input I did not code this part.
$origin_id = get_matching_id();//phantasy method to do what is outlined in above comment. Returns Site ID.
//switch to desired site
switch_to_blog( $origin_id );
$previewData = array(
'menu' => blocsapp_get_menu_data(),
'max_posts' => get_option( 'posts_per_page' ),
'widgets' => blocsapp_get_widget_zones()
Something like this should make your plugin multisite compatible.
The question is, is it worth it?
Multisite is a dinosaur from the past, even WP says/asks “Do you really need it?”:
There’s also helpful information here Create A Network | WordPress.org, php - How to adapt my plugin to Multisite? - Stack Overflow
Hope this helps.
About installs in subdirectory (non root) - not a subdomain, but simply a custom install path (sub directory), this is an entirely different issue.
The problem here is that when you call rest in a custom path (sub directory install), then the path changes.
It is not anymore site.com/wp-json but site.com/sub/wp-json
And that part is coded in the BlocsApp, not in the Blocs WP Plugin, it is the JS or else code BlocsApp is built with that GETs the data.
That code needs to consider the subdirectory install, which it likely does not, but I am really not familiar at all with Mac-related scripting, so I have no idea where to look for that bug, but it is not in the Blocs WP Plugin, it is in the App, that much is sure.
In WP you would be localising the script so to pass dynamically the
home_url() as seen here REST route from a plugin not working if WordPress is installed in a subdirectory - WordPress Development Stack Exchange, but that is PHP/WP Related AJAX, thus not applicable to the BlocsAPP core scripts.
However similar is the solution - you need to consider the possible sub-directory instead of assuming the install being in the root folder.
@Dameer you will have to switch to a single site to use BlocsApp and not use custom install.