Permalink
Browse files

seeding

  • Loading branch information...
etivite committed Jan 7, 2012
0 parents commit 1c022bae8ca977b5c387d08b86aa81060b1c7026
Showing with 366 additions and 0 deletions.
  1. +190 −0 admin/bp-group-adminmod-admin.php
  2. +63 −0 bp-group-adminmod-loader.php
  3. +65 −0 bp-group-adminmod.php
  4. +48 −0 readme.txt
@@ -0,0 +1,190 @@
<?php
function etivite_bp_group_adminmod_admin_seed() {
global $bp, $wpdb;
$data = get_option( 'etivite_bp_group_adminmod' );
if ( !$data || empty( $data ) || !$data['group']['id'] )
return 0;
//loop all groups and seed admin group
$groupids = $wpdb->get_results( "SELECT id FROM {$bp->groups->table_name}" );
if ( !$groupids )
return 0;
//holy infinity and beyond...
remove_action( 'groups_member_before_save', 'etivite_bp_group_adminmod_member_before_save' );
$i = 0;
foreach( $groupids as $gid ) {
$modids = groups_get_group_mods( $gid->id );
if ( $modids ) {
foreach($modids as $id) {
if ( !groups_is_user_member( $id->user_id, $data['group']['id'] ) ) {
$member = new BP_Groups_Member( $id->user_id, $data['group']['id'] );
$member->is_confirmed = 1;
$member->inviter_id = 0;
$member->invite_sent = 0;
$member->is_admin = 0;
$member->user_title = '';
$member->date_modified = bp_core_current_time();
$member->save();
groups_update_groupmeta( $data['group']['id'], 'total_member_count', (int) groups_get_groupmeta( $data['group']['id'], 'total_member_count') + 1 );
}
}
}
$adminids = groups_get_group_admins( $gid->id );
if ( $adminids ) {
foreach($adminids as $id) {
if ( !groups_is_user_member( $id->user_id, $data['group']['id'] ) ) {
$member = new BP_Groups_Member( $id->user_id, $data['group']['id'] );
$member->is_confirmed = 1;
$member->inviter_id = 0;
$member->invite_sent = 0;
$member->is_admin = 0;
$member->user_title = '';
$member->date_modified = bp_core_current_time();
$member->save();
groups_update_groupmeta( $data['group']['id'], 'total_member_count', (int) groups_get_groupmeta( $data['group']['id'], 'total_member_count') + 1 );
}
}
}
}
add_action( 'groups_member_before_save', 'etivite_bp_group_adminmod_member_before_save' );
return $i;
}
function etivite_bp_group_adminmod_admin() {
global $bp;
if ( isset( $_POST['creategroup'] ) && check_admin_referer('etivite_bp_group_adminmod_admin_create') ) {
$new = Array();
$groupname = $_POST['group-name'];
if ( empty( $groupname ) || !$groupname )
$groupname = 'Admins and Mods';
$groupdesc = $_POST['group-desc'];
if ( empty( $groupdesc ) || !$groupdesc )
$groupdesc = 'A group for community Adminstrators and Moderators';
remove_action( 'groups_created_group', 'etivite_bp_autojoin_admins_created_group', 1, 1);
if ( $newgid = groups_create_group( array( 'name' => $groupname, 'description' => $groupdesc, 'slug' => groups_check_slug( sanitize_title( esc_attr( $groupname ) ) ), 'date_created' => bp_core_current_time(), 'status' => 'private' ) ) ) {
groups_update_groupmeta( $newgid, 'total_member_count', 1 );
groups_update_groupmeta( $newgid, 'invite_status', 'admins' );
if ( bp_is_active( 'forums' ) && '' == groups_get_groupmeta( $newgid, 'forum_id' ) && bp_forums_is_installed_correctly() )
groups_new_group_forum( $newgid, $groupname, $groupdesc );
$new['group']['id'] = $newgid;
update_option( 'etivite_bp_group_adminmod', $new );
$imported = etivite_bp_group_adminmod_admin_seed();
$updatedcreate = true;
} else {
$updatedcreate = false;
}
}
if ( isset( $_POST['deletegroup'] ) && check_admin_referer('etivite_bp_group_adminmod_admin_delete') ) {
$ddata = maybe_unserialize( get_option( 'etivite_bp_group_adminmod' ) );
groups_delete_group( $ddata['group']['id'] );
delete_option( 'etivite_bp_group_adminmod' );
$ddate = null;
}
// Get the proper URL for submitting the settings form. (Settings API workaround) - boone
$url_base = function_exists( 'is_network_admin' ) && is_network_admin() ? network_admin_url( 'admin.php?page=bp-groupadminmod-settings' ) : admin_url( 'admin.php?page=bp-groupadminmod-settings' );
$data = maybe_unserialize( get_option( 'etivite_bp_group_adminmod' ) );
?>
<div class="wrap">
<h2><?php _e( 'Group for Community Admins and Mods', 'bp-groupforadminmod' ); ?></h2>
<?php
if ( isset($updated) ) : echo "<div id='message' class='updated fade'><p>" . __( 'Settings updated.', 'bp-groupforadminmod' ) . "</p></div>"; endif;
if ( isset($updatedcreate) ) : echo "<div id='message' class='updated fade'><p>" . __( 'New group created.', 'bp-groupforadminmod' ) . "</p></div>"; endif;
?>
<?php if ( !$data || !$data['group']['id'] || empty( $data['group']['id'] ) ) { ?>
<form action="<?php echo $url_base ?>" name="group-adminmod-form" id="group-adminmod-form" method="post">
<h4><?php _e( 'Create Admin/Mod Group', 'bp-groupforadminmod' ); ?></h4>
<p class="description">Please create a group for all community group adminstrators and moderators. This process will also seed the group with existing members. All future members will be automatically added/removed depending on group admin/mod status.</p>
<table>
<tr>
<td><label for="group-name"><?php _e( 'Group Name (required)', 'buddypress' ); ?></label></td>
<td><input type="text" name="group-name" id="group-name" aria-required="true" value="" /></td>
</tr>
<tr>
<td><label for="group-desc"><?php _e( 'Group Description (required)', 'buddypress' ) ?></label></td>
<td><textarea name="group-desc" id="group-desc" aria-required="true"></textarea></td>
</tr>
</table>
<?php wp_nonce_field( 'etivite_bp_group_adminmod_admin_create' ); ?>
<p class="submit"><input type="submit" name="creategroup" value="Create Group"/></p>
</form>
<?php } else { ?>
<form action="<?php echo $url_base ?>" name="group-adminmod-form" id="group-adminmod-form" method="post">
<h4><?php _e( 'Admin/Mod Group Details', 'bp-groupforadminmod' ); ?></h4>
<?php
$adminmodgroup = groups_get_group( array( 'group_id' => $data['group']['id'] ) );
echo 'Admin Mod Group: <a href="'. bp_get_group_permalink( $adminmodgroup ) .'">'. bp_get_group_name( $adminmodgroup ) .'</a>';
?>
<?php wp_nonce_field( 'etivite_bp_group_adminmod_admin_delete' ); ?>
<p class="submit"><input style="color:red" id="delete_group" type="submit" name="deletegroup" value="Delete Group"/></p>
</form>
<?php } ?>
<h3>About:</h3>
<div id="plugin-about" style="margin-left:15px;">
<p>
<a href="http://etivite.com/wordpress-plugins/buddypress-group-for-community-admins-and-mods/">BuddyPress Group for Adminstrators and Moderators - About Page</a>
</p>
<div class="plugin-author">
<strong>Author:</strong> <a href="http://profiles.wordpress.org/users/etivite/"><img style="height: 24px; width: 24px;" class="photo avatar avatar-24" src="http://www.gravatar.com/avatar/9411db5fee0d772ddb8c5d16a92e44e0?s=24&amp;d=monsterid&amp;r=g" alt=""> rich @etivite</a><br/>
<a href="http://twitter.com/etivite">@etivite</a>
</div>
<p>
<a href="http://etivite.com">Author's site</a><br/>
<a href="http://etivite.com/api-hooks/">Developer Hook and Filter API Reference</a><br/>
<a href="http://etivite.com/wordpress-plugins/">WordPress Plugins</a><br/>
</p>
</div>
<script type="text/javascript"> jQuery(document).ready( function() { jQuery("#delete_group").click( function() { if ( confirm( '<?php _e( 'Are you sure?', 'buddypress' ) ?>' ) ) return true; else return false; }); });</script>
</div>
<?php
}
?>
@@ -0,0 +1,63 @@
<?php
/*
Plugin Name: BuddyPress Group for Community Admins and Mods
Plugin URI: http://wordpress.org/extend/plugins/buddypress-group-for-community-admins-and-mods/
Description: Auto manage a private group for all community group adminstrators and moderators
Author: rich @etivite
Author URI: http://etivite.com
License: GNU GENERAL PUBLIC LICENSE 3.0 http://www.gnu.org/licenses/gpl.txt
Version: 0.1.1
Text Domain: bp-groupforadminmod
Network: true
*/
//TODO - disable atme email notifications of nonmembers from within group
//TODO - disable request membership button on groups-loop
function etivite_bp_group_adminmod_init() {
if ( file_exists( dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' ) )
load_textdomain( 'bp-groupforadminmod', dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' );
require( dirname( __FILE__ ) . '/bp-group-adminmod.php' );
add_action( bp_core_admin_hook(), 'etivite_bp_group_adminmod_add_admin_menu' );
}
add_action( 'bp_include', 'etivite_bp_group_adminmod_init', 88 );
//add_action( 'bp_init', 'etivite_bp_group_adminmod_init', 88 );
//add admin_menu page
function etivite_bp_group_adminmod_add_admin_menu() {
global $bp;
if ( !is_super_admin() )
return false;
//Add the component's administration tab under the "BuddyPress" menu for site administrators
require ( dirname( __FILE__ ) . '/admin/bp-group-adminmod-admin.php' );
add_submenu_page( 'bp-general-settings', __( 'Admin Mod Group', 'bp-groupforadminmod' ), __( 'Admin Mod Group', 'bp-groupforadminmod' ), 'manage_options', 'bp-groupadminmod-settings', 'etivite_bp_group_adminmod_admin' );
}
/* Stolen from Welcome Pack - thanks, Paul! then stolen from boone*/
function etivite_bp_group_adminmod_admin_add_action_link( $links, $file ) {
if ( 'buddypress-group-for-community-admins-and-mods/bp-group-adminmod-loader.php' != $file )
return $links;
if ( function_exists( 'bp_core_do_network_admin' ) ) {
$settings_url = add_query_arg( 'page', 'bp-groupadminmod-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
} else {
$settings_url = add_query_arg( 'page', 'bp-groupadminmod-settings', is_multisite() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
}
$settings_link = '<a href="' . $settings_url . '">' . __( 'Settings', 'bp-groupforadminmod' ) . '</a>';
array_unshift( $links, $settings_link );
return $links;
}
add_filter( 'plugin_action_links', 'etivite_bp_group_adminmod_admin_add_action_link', 10, 2 );
?>
@@ -0,0 +1,65 @@
<?php
if ( !defined( 'ABSPATH' ) ) exit;
//for each member save - check if member is_mod/admin flag status changed
function etivite_bp_group_adminmod_member_before_save( $member ) {
global $wpdb, $bp;
//no data - no bother
$data = get_option( 'etivite_bp_group_adminmod' );
if ( !$data || empty( $data ) || !$data['group']['id'] )
return;
$is_member = groups_is_user_member( $member->user_id, $data['group']['id'] );
//holy infinity and beyond...
remove_action( 'groups_member_before_save', 'etivite_bp_group_adminmod_member_before_save' );
//check if member is_mod/admin and add to group if not a member
if ( ( $member->is_mod || $member->is_admin ) && !$is_member ) {
$new_member = new BP_Groups_Member( $member->user_id, $data['group']['id'] );
$new_member->is_confirmed = 1;
$new_member->inviter_id = 0;
$new_member->invite_sent = 0;
$new_member->is_admin = 0;
$new_member->user_title = '';
$new_member->date_modified = bp_core_current_time();
$new_member->save();
groups_update_groupmeta( $data['group']['id'], 'total_member_count', (int) groups_get_groupmeta( $data['group']['id'], 'total_member_count') + 1 );
}
//check if member is admin/mod of any groups. If not, remove from adminmod group - boone!
$is_admin_or_mod_anywhere_else = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$bp->groups->table_name_members} WHERE user_id = %d AND ( is_admin = 1 OR is_mod = 1 ) AND group_id != %d", $member->user_id, $member->group_id ) );
if ( !$is_admin_or_mod_anywhere_else && !$member->is_admin && !$member->is_mod ) {
$member = new BP_Groups_Member( $member->user_id, $data['group']['id'] );
$member->remove();
groups_update_groupmeta( $data['group']['id'], 'total_member_count', (int) groups_get_groupmeta( $data['group']['id'], 'total_member_count') - 1 );
}
add_action( 'groups_member_before_save', 'etivite_bp_group_adminmod_member_before_save' );
}
add_action( 'groups_member_before_save', 'etivite_bp_group_adminmod_member_before_save' );
function etivite_bp_group_adminmod_remove_member( $user_id, $group_id ) {
global $bp;
//admins can't remove self - so check if mod of a group
if ( !groups_is_user_mod( $user_id, $group_id ) )
return;
$data = get_option( 'etivite_bp_group_adminmod' );
if ( !$data || empty( $data ) || !$data['group']['id'] )
return;
//make sure a member of adminmod group
if ( !groups_is_user_member( $user_id, $data['group']['id'] ) )
return;
$member = new BP_Groups_Member( $user_id, $data['group']['id'] );
$member->remove();
}
add_action( 'groups_remove_member', 'etivite_bp_group_adminmod_remove_member' );
?>
@@ -0,0 +1,48 @@
=== Plugin Name ===
Contributors: nuprn1, etivite
Donate link: http://etivite.com/wordpress-plugins/donate/
Tags: buddypress, groups
Requires at least: PHP 5.2, WordPress 3.2.1, BuddyPress 1.5.1
Tested up to: PHP 5.3.x, WordPress 3.2.1, BuddyPress 1.5.1
Stable tag: 0.1.1
This plugin will create a private group and maintain a member list of all current group administrators and moderators.
== Description ==
This plugin will create a private group and maintain a member list of all current group administrators and moderators from your site.
= Related Links: =
* <a href="http://etivite.com" title="Plugin Demo Site">Author's Site</a>
* <a href="http://etivite.com/wordpress-plugins/buddypress-group-for-community-admins-and-mods/">BuddyPress Group for Adminstrators and Moderators - About Page</a>
* <a href="http://etivite.com/api-hooks/">BuddyPress and bbPress Developer Hook and Filter API Reference</a>
* <a href="http://twitter.com/etivite">@etivite</a> <a href="https://plus.google.com/114440793706284941584?rel=author">etivite+</a>
== Installation ==
1. Upload the full directory into your wp-content/plugins directory
2. Activate the plugin at the plugin administration page
== Frequently Asked Questions ==
= My question isn't answered here =
Please contact me on http://etivite.com
== Changelog ==
= 0.1.0 =
* Boone's patch -> check if members of other groups prior to removal
= 0.1.0 =
* first release
== Upgrade Notice ==
== Extra Configuration ==

0 comments on commit 1c022ba

Please sign in to comment.