Permalink
Browse files

seeding

  • Loading branch information...
etivite committed Jan 7, 2012
0 parents commit eaa5aec0da071a02a2142ab526440c3c4232a508
Showing with 348 additions and 0 deletions.
  1. +181 −0 admin/bp-groups-autojoin-admins-admin.php
  2. +58 −0 bp-groups-autojoin-admins-loader.php
  3. +60 −0 bp-groups-autojoin-admins.php
  4. +49 −0 readme.txt
@@ -0,0 +1,181 @@
<?php
function etivite_bp_autojoin_admins_admin() {
global $bp;
if ( isset( $_POST['submit'] ) && check_admin_referer('etivite_bp_groups_autojoin_admin') ) {
$new = Array();
//check for valid demote
if( isset( $_POST['gaj_demote_mod'] ) && !empty( $_POST['gaj_demote_mod'] ) ) {
switch ( $_POST['gaj_demote_mod'] ) {
//fall down - sanity check for valid values
case 'member':
case 'mod':
$new['demote_creator'] = $_POST['gaj_demote_mod'];
break;
case 'same':
$new['demote_creator'] = false;
break;
default:
$new['demote_creator'] = false;
}
} else {
$new['demote_creator'] = false;
}
if( isset($_POST['gaj_admin_users'] ) && !empty($_POST['gaj_admin_users']) ) {
$unfiltered_types = explode( ',', $_POST['gaj_admin_users'] );
foreach( (array) $unfiltered_types as $type ) {
if ( !empty( $type ) ) {
$suser = get_userdatabylogin( trim($type) );
if( $suser ) {
if ( !$new['wp_cap']['admin'] || ( $new['wp_cap']['admin'] && !user_can( $suser->ID, $new['wp_cap']['admin'] ) ) )
$types[] = $suser->ID;
}
}
}
if ($types) {
$new['users']['admin'] = $types;
} else {
$new['users']['admin'] = false;
}
} else {
$new['users']['admin'] = false;
}
if( isset($_POST['gaj_mod_users'] ) && !empty($_POST['gaj_mod_users']) ) {
$unfiltered_modusers = explode( ',', $_POST['gaj_mod_users'] );
foreach( (array) $unfiltered_modusers as $moduser ) {
if ( !empty( $moduser ) ) {
$suser = get_userdatabylogin( trim($moduser) );
if( $suser ) {
$modusers[] = $suser->ID;
}
}
}
if ( $modusers ) {
//check if mod user is part of admin users
if ( $types ) {
$modusers = array_diff($modusers, $types);
$modusers = array_values( $modusers );
}
$new['users']['mod'] = $modusers;
} else {
$new['users']['mod'] = false;
}
} else {
$new['users']['mod'] = false;
}
update_option( 'etivite_bp_groups_autojoin_admins', $new );
$updated = true;
}
?>
<div class="wrap">
<h2><?php _e( 'Auto Join Group Admins', 'bp-groupsautojoinadmins' ); ?></h2>
<?php if ( isset($updated) ) : echo "<div id='message' class='updated fade'><p>" . __( 'Settings updated.', 'bp-groupsautojoinadmins' ) . "</p></div>"; endif;
$data = maybe_unserialize( get_option( 'etivite_bp_groups_autojoin_admins' ) );
?>
<form action="<?php echo network_admin_url('/admin.php?page=bp-autojoinadmins-settings') ?>" name="groups-autojoin-form" id="groups-autojoin-form" method="post">
<h4><?php _e( 'Select Default Administrator', 'bp-groupsautojoinadmins' ); ?></h4>
<table class="form-table">
<tr>
<th><label for="gaj_admin_users"><?php _e('Enter Users (by username)','bp-groupsautojoinadmins') ?></label></th>
<td><textarea rows="5" cols="50" name="gaj_admin_users" id="gaj_admin_users"><?php if ( $data['users']['admin'] ) {
foreach ( $data['users']['admin'] as $key => $luser ) {
$user_info = get_userdata( $luser );
if ($user_info) {
$data['users']['admin'][$key] = $user_info->user_login;
} else {
unset( $data['users']['admin'][$key] );
}
} echo esc_attr( implode( ', ', $data['users']['admin'] ) ); } ?></textarea><br/><?php _e( "Seperate usernames with commas.", 'bp-groupsautojoinadmins' ) ?></td>
</tr>
</table>
<h4><?php _e( 'Select Default Moderator', 'bp-groupsautojoinadmins' ); ?></h4>
<table class="form-table">
<tr>
<th><label for="gaj_admin_users"><?php _e('Enter Users (by username)','bp-groupsautojoinadmins') ?></label></th>
<td><textarea rows="5" cols="50" name="gaj_mod_users" id="gaj_mod_users"><?php if ( $data['users']['mod'] ) {
foreach ( $data['users']['mod'] as $key => $luser ) {
$user_info = get_userdata( $luser );
if ($user_info) {
$data['users']['mod'][$key] = $user_info->user_login;
} else {
unset( $data['users']['mod'][$key] );
}
} echo esc_attr( implode( ', ', $data['users']['mod'] ) ); } ?></textarea><br/><?php _e( "Seperate usernames with commas.", 'bp-groupsautojoinadmins' ) ?></td>
</tr>
</table>
<h4><?php _e( 'Demote Creator', 'bp-groupsautojoinadmins' ); ?></h4>
<table class="form-table">
<tr>
<th><label for="gaj_demote_mod"><?php _e('Keep as Admin','bp-groupsautojoinadmins') ?></label></th>
<td><input type="radio" <?php if ( $data['demote_creator'] == false ) { echo 'checked="checked"'; } ?> name="gaj_demote_mod" id="gaj_demote_mod" value="same" /></td>
</tr>
<tr>
<th><label for="gaj_demote_mod_1"><?php _e('Demote to Moderator','bp-groupsautojoinadmins') ?></label></th>
<td><input type="radio" <?php if ( $data['demote_creator'] == 'mod' ) { echo 'checked="checked"'; } ?> name="gaj_demote_mod" id="gaj_demote_mod_1" value="mod" /></td>
</tr>
<tr>
<th><label for="gaj_demote_mod_2"><?php _e('Demote to Member','bp-groupsautojoinadmins') ?></label></th>
<td><input type="radio" <?php if ( $data['demote_creator'] == 'member' ) { echo 'checked="checked"'; } ?> name="gaj_demote_mod" id="gaj_demote_mod_2" value="member" /></td>
</tr>
</table>
<div class="description">
<p>*If demoting the group creator - please auto assign an adminstrator otherwise unpredictable results may occur.</p>
</div>
<?php wp_nonce_field( 'etivite_bp_groups_autojoin_admin' ); ?>
<p class="submit"><input type="submit" name="submit" value="Save Settings"/></p>
</form>
<h3>About:</h3>
<div id="plugin-about" style="margin-left:15px;">
<p>
<a href="http://etivite.com/wordpress-plugins/buddypress-groups-autojoin-admins/">Groups Auto Join Admins - About Page</a><br/>
</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>
</div>
<?php
}
?>
@@ -0,0 +1,58 @@
<?php
/*
Plugin Name: BuddyPress Groups Auto Join Admins and Mods
Plugin URI: http://wordpress.org/extend/plugins/buddypress-groups-autojoin-admins/
Description: Auto-Join users as Adminstrator or Moderator to every group created and demote creator
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-groupsautojoinadmins
Network: true
*/
function etivite_bp_autojoin_admins_init() {
if ( file_exists( dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' ) )
load_textdomain( 'bp-groupsautojoinadmins', dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' );
require( dirname( __FILE__ ) . '/bp-groups-autojoin-admins.php' );
add_action( bp_core_admin_hook(), 'etivite_bp_autojoin_admins_add_admin_menu' );
}
add_action( 'bp_include', 'etivite_bp_autojoin_admins_init', 88 );
//add_action( 'bp_init', 'etivite_bp_autojoin_admins_init', 88 );
//add admin_menu page
function etivite_bp_autojoin_admins_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-groups-autojoin-admins-admin.php' );
add_submenu_page( 'bp-general-settings', __( 'Auto Join Admins Admin', 'bp-groupsautojoinadmins' ), __( 'Auto Join Admins', 'bp-groupsautojoinadmins' ), 'manage_options', 'bp-autojoinadmins-settings', 'etivite_bp_autojoin_admins_admin' );
}
/* Stolen from Welcome Pack - thanks, Paul! then stolen from boone*/
function etivite_bp_autojoin_admin_add_action_link( $links, $file ) {
if ( 'buddypress-groups-autojoin-admins/bp-groups-autojoin-admins-loader.php' != $file )
return $links;
if ( function_exists( 'bp_core_do_network_admin' ) ) {
$settings_url = add_query_arg( 'page', 'bp-autojoinadmins-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
} else {
$settings_url = add_query_arg( 'page', 'bp-autojoinadmins-settings', is_multisite() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
}
$settings_link = '<a href="' . $settings_url . '">' . __( 'Settings', 'bp-groupsautojoinadmins' ) . '</a>';
array_unshift( $links, $settings_link );
return $links;
}
add_filter( 'plugin_action_links', 'etivite_bp_autojoin_admin_add_action_link', 10, 2 );
?>
@@ -0,0 +1,60 @@
<?php
if ( !defined( 'ABSPATH' ) ) exit;
//if a new group is created - lets always make sure our default admin is attached
function etivite_bp_autojoin_admins_created_group( $args ) {
global $bp;
if ( !$args )
return;
$add = maybe_unserialize( get_option( 'etivite_bp_groups_autojoin_admins' ) );
if ( $add ) {
//if demote creator to mod/member
if ( $add['demote_mod'] && !$bp->loggedin_user->is_super_admin ) {
if ( $add['demote_mod'] == 'mod' ) {
$member = new BP_Groups_Member( $bp->loggedin_user->id, $args );
$member->is_admin = 0;
$member->is_mod = 1;
$member->user_title = __( 'Group Mod', 'buddypress' );
$member->date_modified = bp_core_current_time();
$member->save();
} elseif ( $add['demote_mod'] == 'member' ) {
$member = new BP_Groups_Member( $bp->loggedin_user->id, $args );
$member->is_admin = 0;
$member->is_mod = 0;
$member->user_title = '';
$member->date_modified = bp_core_current_time();
$member->save();
}
}
//loop admin ids
foreach( $add['users']['admin'] as $adminuser ) {
$member = new BP_Groups_Member( $adminuser, $args );
$member->is_admin = 1;
$member->is_mod = 0;
$member->user_title = __( 'Group Admin', 'buddypress' );
$member->is_confirmed = 1;
$member->date_modified = bp_core_current_time();
$member->save();
}
//loop mod ids
foreach( $add['users']['mod'] as $moduser ) {
$member = new BP_Groups_Member( $moduser, $args );
$member->is_admin = 0;
$member->is_mod = 1;
$member->user_title = __( 'Group Mod', 'buddypress' );
$member->is_confirmed = 1;
$member->date_modified = bp_core_current_time();
$member->save();
}
}
}
add_action( 'groups_created_group', 'etivite_bp_autojoin_admins_created_group', 1, 1);
?>
@@ -0,0 +1,49 @@
=== Plugin Name ===
Contributors: nuprn1, etivite
Donate link: http://etivite.com/donate/
Tags: buddypress, groups
Requires at least: PHP 5.2, WordPress 3.2.1, BuddyPress 1.5.1
Tested up to: PHP 5.2.x, WordPress 3.2.1, BuddyPress 1.5.1
Stable tag: 0.1.1
This plugin will auto join group admins and moderators to all new groups. You may auto demote the creator to a moderator or member.
== Description ==
This plugin will auto join group admins and moderators to all new groups. You may auto demote the creator to a moderator or member.
= Related Links: =
* <a href="http://etivite.com" title="Plugin Demo Site">Author's Site</a>
* <a href="http://etivite.com/wordpress-plugins/buddypress-groups-autojoin-admins/">BuddyPress Groups Auto Join Admins - About Page</a>
* <a href="http://etivite.com/api-hooks/">BuddyPress and bbPress Developer Hook and Filter API Reference</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.1 =
* BUG: fix network admin settings page on multisite
* FEATURE: support for locale mo files
= 0.1.0 =
*first release
== Upgrade Notice ==
== Extra Configuration ==

0 comments on commit eaa5aec

Please sign in to comment.