-
Notifications
You must be signed in to change notification settings - Fork 6
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
Plugin database tables not being created for all instances of a WP network installation? #4
Comments
We had the same issue and your workaround did work for us, too. Maybe anyone else finds a reason why the CMRF plugin itself fails here? Anyway: Thanks for finding that out and also for sharing your workaround as an add-on at https://codeberg.org/winnewoerp/wpcmrf-lda |
I found the error but unfortunately I don't have the time to fork this plugin and integrate the solution. The is_multisite() part of the following code needs to be adapted and added to the respective function where the databases tables are being created
Source: How to run an activation function when plugin is network activated on multisite? PLEASE NOTE: Both this plugin and my add-on (Link in the previous comment) should work correctly in a WordPress network when not activated network-wide but for single sites only. If you want this plugin to be activated network-wide, then you have to use my add-on and activate it for single sites. But: Now that I found the error I don't see any reason for using my add-on anymore. Just use this plugin and activate it per site (where needed) and not network-wide—until the solution has been implemented here. But please be aware that this plugin adds custom database tables to all of the sites in your network (once the fix is implemented) when activated network-wide. So you should consider to only activate it for sites where connections to a CiviCRM instance are actually needed! |
An alternative solution regarding my previous comment: Maybe the better solution is then (after all) to prevent network-wide activation of the plugin. Like this:
|
Thanks again @winnewoerp – we decided to fund a fix and will give feedback. |
Thank you! Here's my approach to the solution (just prevent network-wide plugin activation) for my plugin, that should be adaptable for the main plugin: |
I have updated the code and added code to create the database table on all active sites. |
@jaapjansma Just a word of warning... I know the code you've added is easy to find on the interwebs, but it has its issues - particularly for large Multisite installs. Your code will time out on larger Multisite installs and potentially cause problems. I would recommend (at minimum) adding a check for Better still, I would recommend providing an admin page for this plugin with an AJAX-driven UI that adds the tables to sub-sites in batches so that timeouts do not happen. See CiviCRM Profile Sync, see CiviCRM Event Organiser or the CiviCRM-WordPress plugin itself for implementations of AJAX in WordPress admin pages. Just sayin' :) |
@christianwach thanks for pointing out. How would I create such an AJAX driven UI? I am still not familiar with word press although I have developed a couple of plugins. |
@jaapjansma All I can really suggest is digging through some of the repos that I pointed to. I'm ridiculously over-zealous about commenting my code, so you should be able to get an idea of how things work fairly quickly. CiviCRM Member Sync, for example, uses a combination of an admin page declared here (though you'd want to do this in response to the Network Admin action), this JS file enqueued here, an AJAX callback method declared here and implemented here. Those links should give you a fair idea of how to use the built-in jQuery progress bar script to achieve this kind of UI. Your use case is way simpler than what I'm pointing to so you'd be able to strip a whole lot of code out for your use case. Of course most Multisite installs are not large networks - so I doubt there's a great hurry. I just wanted to leave this here for reference :) |
Thanks @christianwach I had a short look into whether I could implement this quickly but it requires a bit of work from my side as I have to learn/understand wordpress and multi site. And also a test setup with a fair amount of multi sites. So I will leave it here till I have funding for this issue. |
Installing the plugin with a WP network installation worked, but errors where logged when trying to save connection data, saying that the respective database tables are not existing. As a workaround, we now temporarily added the 'CREATE TABLE...' part of the plugin into our theme functions.
The text was updated successfully, but these errors were encountered: