BuddyPress option to limit or remove the possibility to mail out notifications of wire updates

Det här är inte ett inlägg som hör till Luftslottets vanliga agenda, utan är ett stycke kod som lägger till en inställningsmeny till BuddyPress. Om man inte är intresserad av PHP och/eller BuddyPress/WordPress kan man med fördel bortse från det. Det är också därför det är avklippt i RSS-flödet.

<?php
 
/* * * * * * * * * * * * * * * * * * * * * * * *
 * Description:
 * BuddyPress option to limit or remove the
 * possibility to mail out notifications of
 * wire updates.
 *
 * Author: Jobjörn Folkesson
 *
 * License:
 * I, the copyright holder of this work, hereby
 * release it into the public domain. This
 * applies worldwide. In case this is not
 * legally possible: I grant anyone the right
 * to use this work for any purpose, without
 * any conditions, unless such conditions are
 * required by law.
 * (Public Domain)
 *
 * Installation instructions:
 * Put code in a "tweaks.php" or similar in your
 * mu-plugins folder. Et voila!
 * * * * * * * * * * * * * * * * * * * * * * * */
 
function tweaks_add_admin_menu() {
	if ( is_site_admin() ) {
		// Add the administration tab under the "Site Admin" tab for site administrators
		add_submenu_page( 'wpmu-admin.php', __("Additional settings", 'tweaks'), __("Ytterligare inst&auml;llningar", 'bp-tweaks'), 1, "tweaks_admin_settings", "tweaks_admin_settings" );
	}
}
add_action( 'admin_menu', 'tweaks_add_admin_menu' );
 
if(!get_site_option( 'wire-email-notifying' )){
	add_site_option( 'wire-email-notifying', 3 );
}
 
function tweaks_admin_settings() {
 
	if ( isset( $_POST['bp-tweaks-submit'] ) && isset( $_POST['bp-tweaks'] ) ) {
		if ( check_admin_referer('bp-tweaks') ){
			// Settings form submitted, now save the settings.
			foreach ( $_POST['bp-tweaks'] as $key => $value ) {
				update_site_option( $key, $value );
			}
			$message = __( 'Settings were successfully saved.', 'tweaks' );
			$type = "updated";
		}
		else{
			$message = __( 'Something went wrong, please try again.', 'tweaks' );
			$type = "error";			
		}
	}
	if ( isset( $message ) ) { ?>
		<div id="message" class="<?php echo $type ?> fade">
			<p><?php echo $message ?></p>
		</div>
	<?php } ?>
	<div class="wrap">
		<h2><?php _e( 'Additional BuddyPress settings', 'tweaks' ) ?></h2>
		<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" id="bp-admin-form">
			<table class="form-table">
				<tbody>
					<?php if ( function_exists('bp_wire_install') ) { ?>
						<tr>
							<th scope="row"><?php _e('Allow e-mail notifying of wire posts', 'tweaks') ?>:</th>
							<td>
								<input type="radio" name="bp-tweaks[wire-email-notifying]"<?php if ( get_site_option( 'wire-email-notifying' ) == 0) : ?> checked="checked"<?php endif; ?> id="bp-tweaks-wire-email-notifying" value="0" /> <?php _e('Not at all', 'tweaks'); ?> &nbsp;
								<input type="radio" name="bp-tweaks[wire-email-notifying]"<?php if ( get_site_option( 'wire-email-notifying' ) == 1) : ?> checked="checked"<?php endif; ?> id="bp-tweaks-wire-email-notifying" value="1" /> <?php _e('Admins only', 'tweaks'); ?> &nbsp;
								<input type="radio" name="bp-tweaks[wire-email-notifying]"<?php if ( get_site_option( 'wire-email-notifying' ) == 2) : ?> checked="checked"<?php endif; ?> id="bp-tweaks-wire-email-notifying" value="2" /> <?php _e('Admins and mods only', 'tweaks'); ?> &nbsp;
								<input type="radio" name="bp-tweaks[wire-email-notifying]"<?php if ( get_site_option( 'wire-email-notifying' ) == 3) : ?> checked="checked"<?php endif; ?> id="bp-tweaks-wire-email-notifying" value="3" /> <?php _e('Everyone', 'tweaks'); ?> &nbsp;
							</td>			
						</tr>
					<?php } ?>
				</tbody>
			</table>
			<p class="submit">
				<input type="submit" name="bp-tweaks-submit" id="bp-admin-submit" value="<?php _e( 'Save Tweaks', 'tweaks' ) ?>" />
			</p>
			<?php wp_nonce_field( 'bp-tweaks') ?>
		</form>
	</div>
	<?php do_action('additional_bp_settings');
}
 
function limit_wire_email_notifying($var){
	global $bp;
	global $wpdb;
	$setting = get_site_option( 'wire-email-notifying' );
	switch ($setting){
		case 0: // Not at all
			return 0;
			break;
		case 1: // Admins only
			if($bp->is_item_admin){
				return $var;
			}
			else{
				return 0;
			}
			break;
		case 2: // Admins and mods only
			if($bp->is_item_admin || $bp->is_item_mod){
				return $var;
			}
			else{
				return 0;
			}
			break;
		case 3: // Everyone
			return $var;
			break;
	}
}
add_filter( 'bp_wire_show_email_notify', 'limit_wire_email_notifying' );
?>

One Comment

  1. Job skriver:

    Det skulle ha varit avklippt i RSS-flödet, iallafall.