Blocs Plus and WordPress MU don't work

Hi!
Just downloaded Blocs plus trial and got stuck within 2 minutes…
I have a localhost MAMP setup with the WordPress MU, and Blocs can’t create/generate pages for a new WP theme because it looks like all the forward slashes got stripped from the site URL.
What am I missing here?!

Cheers!

When Blocs generates the initial pages they are all blank by default.

Also make sure the Wordpress json api is reachable at the URL you input.

Bu also remember its not essential to connect with development server, it’s only used for previewing.

WP JSON API should be available throughout all the network sites!
I want to connect with the development server because I need the preview.
What can I do to develop a test WP theme on my WordPress MU?

Thanks for any advice!

Welcome to the Blocs Forum! :smile:
You will find so many people here willing to help you.
Be sure to check out:

BlocsMaster course & templates @Eldar is the brilliant developer. He is always willing to help.
@Malachiman blocsbuilder.com has shared some very cool code tweaking, if you’re in that. He is our code genius.

Also there are many others. Oh and don’t forget the 3rd party extensions that have been an aid to do some great things in Blocs.

I’ve never used Wordpress MU so I’m not able to confirm if this set up is supported.

Any other members use WP MU with the Blocs preview plugin and Blocs?

@KBConcepts - Thanks!
@Norm - I actually don’t think that the problem is WP MU only related. If WordPress is installed inside the folder (ie. one level down the root), forward slashes are stripped too. So I guess if you can figure out why it happens, it’ll become irrelevant whether one uses WP MU or not. Maybe I’m wrong so please excuse my ignorance!

This is not an issue with slashes. The Blocs WP Plugin is simply not Multisite Compatible :slight_smile:

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 rest_api_init.
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()
);
//restore data
restore_current_blog();
return $previewData;

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.

2 Likes

Even though this is way beyond my knowledge, I appreciate you taking the time to put your expert advise to the Blocs forum. :smile: