I downloaded this plugin today and started tooling around with it. After working through a number of small problems (never did get skins to work), I quickly discovered that I would have to add users to a group manually... and that just wasn't going to happen. Since the plugin is actually really great, I didn't want to scrap it.
I threw together the following plugin (my first one) after a bit of hacking around. I'm going to share the code and some basic implementation, since there ABSOLUTELY going to be changes that you'll need to make if you want to use it.
It's important to mention that EVERY user that logs into WP will be added to a SINGLE group. This isn't a problem for my implementation, but I can understand that this may be an issue for some people. Either way, I'm sure this should be adequate for most people's use.
<?php
/*
Plugin Name: Auto Add Users To Mingle
Plugin URI: http://mikebrum.com/
Description: This plugin automatically joins any user to a defined group ID so they can make forum posts
Version: 0.1
Author: Mike Brum
Author URI: http://mikebrum.com/
License: Freestuffz
*/
/*
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. Please test it in a way that will not
expose you to the loss of data if any problems are encountered.
*/
class forumAdder {
function add2forum() {
global $current_user, $wpdb;
$current_user = wp_get_current_user();
$cuid = $current_user->ID;
# check db to see if they're part of "the group"
$id_query = "SELECT id, user_id FROM wp_mauimtg_forum_usergroup2user WHERE user_id = '$cuid'";
$my_id = $wpdb->get_row($id_query, ARRAY_N);
# if not, then add them
if ( (! $my_id[1] ) && ($cuid != '0') && ($cuid != '') ){
$wpdb->insert( 'wp_mauimtg_forum_usergroup2user',
array( 'user_id' => $cuid, 'group' => 2 ),
array( '%d', '%s' )
);
}
}
}
$myForumAdder = new forumAdder();
add_action('shutdown', array($myForumAdder, 'add2forum'));
?>
So the first thing that you'll need to do is copy the code above to a file and put it in your plugins dir for WP. I called it "auto_add_users_to_mingle.php". Seemed appropriate.
There's two things that you need to change:
wp_mauimtg_forum_usergroup2user -- this is the Mingle 'forum_usergroup2user' table. Given my WP table prefix is "wp_mauimtg_", this is how we get this full table. If you look in your wp-config.php file and look at your table_prefix variable, it should be obvious what this should be changed to. It'll basically be: $table_prefix + 'forum_usergroup2user'
For reference, my exact line from wp-config.php is:
$table_prefix = 'wp_mauimtg_';
The other important thing that needs to change is the line:
array( 'user_id' => $cuid, 'group' => 2 ),
Specifically, the number "2" (the rest of the line needs to stay exactly the same).
Now, there's no "easy" way to figure out what this number is supposed to be. You're going to have to log into your database and figure out what that number is.
Here's a straight forward way to figure it out (using the table names that I'm looking at as defined by my $table_prefix):
1) look at all entries in the table wp_mauimtg_forum_usergroups and find the group that you want everyone to be added to. There's a column called "name" that will actually display the group name, so there's no real guessing involved once you spit out the contents of wp_mauimtg_forum_usergroups.
2) the value in the "id" column is the number that you're going to want to specify in the above line.
For example, if you have a group called "Family" that you wanted everyone added to and you looked that row up in your wp_mauimtg_forum_usergroups table and found that it had an id of "15", then the line would need to be changed to:
array( 'user_id' => $cuid, 'group' => 15 ),
Once you've made the 2x table name changes and the 1x number change, you should be ready to activate the plugin.
If you get an error, you've probably screwed up the PHP syntax and should fine-tooth-comb the changes you made.
As I mentioned, this is my first plugin, so I'm sure there's a number of things I could do to improve it. For instance, I'd imagine there's a way to pull out the value of $table_prefix and do the string concatenation and I could make an admin panel for the plugin that brings up the list of groups in wp_mauimtg_forum_usergroups and lets you select one from a pull-down instead of having to hack at it by hand.
But both of these enhancements are for another day.
I just wanted to contribute the code if it can help others. Hope you have luck implementing it.
|