WordPress Multisite 3.1 and fixing the problems with BuddyPress dependent plugins
Since the release of WordPress 3.1 and BuddyPress 1.2.8, I have seen a lot of complaints that the plugin menu is not appearing or the plugin is not saving data or so and so. So, I decided to write this post which could help plugin developers and if the developer is not updating the plugin, as a user, you can do it yourself.
I will categorize the plugins having troubles in 2 categories:-
- Plugins which uses WordPress settings API to save data/options
- Plugin which does not uses WordPress settings API
All the issues I am discussing is related to the plugins which add a menu/sub menu in WordPress multisite network admin panel. For example, since BuddyPress menu is available in WordPress 3.1 network admin panel, any plugin which adds a sub menu in BuddyPress menu falls in this category.
Now, let us discuss the problems and the solutions step by step.
Issue 1:- The plugin menu is not appearing in the BuddyPress/Network Admin panel.
There is an easy fix for this. It applies to both types of plugin.
Find all the instances which says
[sourcecode language="php"]
add_action("admin_menu","some_plugin_hook","may_be_some_priority_here");//last argument is optional and may not be present in some plugins
[/sourcecode]
Change that to
[sourcecode language="php"]
add_action( is_multisite()?"network_admin_menu":"admin_menu","some_plugin_hook","may_be_some_priority_here" );//look at first argument
[/sourcecode]
Here simply we are testing if this is a multisite install, hook that to network_admin_menu otherwise hook it to admin_menu(for single wp).
Once you are done, you should really check by going to the network admin. The menu item will be present.
All sounds good. Well, may be you are done or may not be. Try saving the data from your plugin option. If it is working, you re good to stop reading here. If it does not work, please keep reading.
Issue 2: Well, the menu is appearing but I am getting redirected to http://mysite.com/wp-admin/?c=1 or it is giving page not found error ?
Not that bad. After all, we have completed step one, so just a few more seconds and we are going to fix it too.
This section discusses the issue for plugins which does not use WorPress settings API(look for a function register_setting, If it is present, or the form you see in plugin options page has an action set to "options.php" you should better skip to next section).
Trouble shooting tips:-
- look for the form action, is it empty? If yes, then it is good, let us move(btw, leaving form action empty is not a good thing).
- If the action is not empty, check if it is set to "options.php", if yes, you should really skip this section and go to next section.
- If the form action is not set to "options.php" which all the major BuddyPress component have(mostly), then we will need to change the url as discussed below.
The action URL may be anything like this
[sourcecode language="html"]
<form action="wp-admin/some-hardcoded-file.php?page=someaction" ..some attributes here ….>
[/sourcecode]
or
[sourcecode language="php"]
<form action="<?php echo admin_url('some-plugin-file.php?page=someaction');?>" ..some attributes here ….>
[/sourcecode]
In both of the cases, you should change it. We will change
[sourcecode language="html"]
<form action="wp-admin/some-hardcoded-file.php?page=someaction" ..some attributes here ….>
[/sourcecode]
to
[sourcecode language="php"]
<form action="<?php echo network_admin_url('some-hardcoded-file.php?page=someaction');?>" ..some attributes here ….>
[/sourcecode]
and if the action is set using admin_url(), change admin_url to network_admin_url().
That will fix the plugin options page form. And you will be able to submit the data(or click Save etc) , It should not give any error/redirect.
Also, a basic advice, look for the urls which should be available in network admin panel for your plugin. If they are not using network_admin_url, change them to network_admin_url.
Issue 3:- It was good to read, My form is visible, I can submit the data but the data/option is not saved?
Most probably your plugin is using WordPress settings api.
Look for the form action, if it is set to something like this
[sourcecode language="php"]
<form action="options.php" ..some attributes here ….>
[/sourcecode]
change that to
[sourcecode language="php"]
<form action="<?php echo admin_url('options.php');?>" ..some attributes here ….>
[/sourcecode]
Yes, you are reading it correctly. We are changing it to admin_url("options.php") , so it points to yoursite.com/wp-admin/options.php
Try saving data, is it working ? yes, it is. Ok enjoy. If it is not, then we will have to wait a couple more minutes:-
Now, we will look for the section where the function register_setting is called. Check if the wrapper function is hooked to admin_menu or network_admin_menu. If it is hooked to network _admin_menu, change that to admin_menu.
Case study: BP Profile Privacy:-
There is a catch though. For example, I was updating the bp profile privacy plugin by Jeff Farthing to test it with the BP Mag Framework(as reported by Dr. Joseph Pisano, the layout was breaking for my theme), I found this plugin non functional for WP Multisite 3.1. I updated as I have discussed above and the admin menu came back, but I got the error that the option page can not be found. If you see this error, it simply means, your setting was not registered.
So, I changed the hook to admin_menu, and then, as not expected, the submenu vanished. A close look revealed the profile privacy plugin was hooking the submenu and registering the settings from the same function. I refracted it into 2 functions. then I hooked the register_setting to admin_menu while left the submenu registering code hooked as mentioned in the step1. Well, That made it work. So, please beware of such catches.
I am putting the updated version for Bp Profile privacy here for anyone who needs it updated. If you have any contact with Jeff, Please download the plugin and send him a copy, so he can update it on wp.org repo. I saw his profile on buddypress.org, but there was no mean to contact or send file. So, I will leave it to you all who are using this plugin to contact him and ask him for committing the update. Or if you know his email, please drop me a line using the contact form on this site and I will be glad to send the file myself.
Download Bp profile Privacy: https://buddydev.com/http//buddydev.com/public-download/bp-profile-privacy.zip
hope it helps a few of you. Please do let me know if you know other ways to fix it, or anything you want 🙂
This plugin is useless.Its not working.
Hi there,
Thank you for the comment. I am not sure if that plugin works as expected or not. In my post above and changes, I was concerned about making it save the data on Admin pages correctly and the same applies on edit profile pages. I did not make any changes in other code, so If the plugin worked with Bp 1.2.7, It will work with bp 1.2.8 too, If it did not work(I mean applied privacy), It won't work for 1.2.8.
If you have used it in bp 1.2.7/8 and can tell me the issues, may be I can put some fixes(Though I am not the developer of profile privacy plugin).
Hi Brajesh,
This plugin does work, and this tutorial was extremely helpful in fixing some other plugins that needed to be updated. I'll post them here for download as well in a bit!
Thank for the comment Bowe 🙂
Glad it helped. looking forward to see your updates 🙂
Thank you very, very much. I ended up here looking for help with BP Privacy plugin & WP 3.1 multisite. My programming skills are not good enough to track down all the modifications that were needed – your download just saved my day! 🙂 It worked like a charm on WP 3.1 & BP 1.2.8.
I'll definitely try the fix you posted on the couple of other plugins that are misbehaving…
Hi Nunsuch,
Highly appreciate the comment. I am glad it helped you and I hope it helps in fixing other plugins too 🙂
Hi Brajesh,
I made Japanese Translation based on your fixed version of BP Profile Privacy.
Though I mentioned to the author of the plugin at buddypress.org site at the very time that BP 1.2.8 was released, no response was returned so far.
I altered your fixed scripts a little in order to make the plugin ready for translation, making "languages" directory that includes Japanese Translation files, and I compressed the whole package to a zip file.
I will be glad if you accept this and update your version, so that more people can use the plugin in their own language.
Please let me know by email, and I will send the zip file right away.
Thanks in advance,
Chestnut
Hi Chestnut,
sorry for getting back. If you get this notification, please leave a comment and I will get back into touch soon. Sorry, I could not reply earlier.
Hi Brajesh,
Thank you for your reply.
As mentioned before, please email me and I will send the zip via email to you.
Hi Brajesh,
Thank you sooo much for this!
Question: when form action is empty what should one do?
"look for the form action, is it empty? If yes, then it is good, let us move…"
Clarissa
Hi Clarissa,
sorry for delayed reply. If the form action is empty, just leave that as it is and move to next step.
The plugin I am trying to update still will not save the details and it uses the WP Settings API. I get the "options page cannot be found" error. I found the register_setting() function, and its wrapper function hooks to 'admin_init'. Is this the cause of the problem and if so, what should this wrapper hook to?
Thanks Brajesh!
Clarissa
Hey there, thanks for sharing. Do you know of anyone (maybe yourself) planning on updating this for BP 1.5, since Jeff's dropped it?
Hi Katie,
Thank you for the comment.
Jeff does not seem to be active recently. I will certainly update this plugin if it helps the community 🙂
Hi Brajesh,
I took a quick look at this plugin to see if I could manage to get it working on BP 1.5, but alas, no success. If you could have go at it I'm sure it would be appreciated by more than myself!