Skip to content

Instantly share code, notes, and snippets.

@darrenmeehan
Created June 6, 2012 14:01
Show Gist options
  • Save darrenmeehan/2882028 to your computer and use it in GitHub Desktop.
Save darrenmeehan/2882028 to your computer and use it in GitHub Desktop.
Code for homepage, displays 6 random members
<?php
/*
* Function Name: buat_shortcode_grabber()
* Description: This function reads shortcodes from page and call template function according to user type
*/
function buat_shortcode_grabber( $atts ) {
$buat_default_type=get_option('buat_default_type');
extract( shortcode_atts( array(
'type' => "$buat_default_type",
), $atts ) );
if(!is_plugin_active('buddypress/bp-loader.php'))
{
echo 'You must need to install and active <a href="http://buddypress.org">Buddypress</a>
to use Buddypress User Account Type plugin';
}
else
{
buat_get_user_template($type);
}
if(is_front_page())
{
$dm_number = 6;
}
else
{
$dm_number = 20;
}
echo "$dm_number";
}
add_shortcode( 'bp_user_account_type', 'buat_shortcode_grabber' );
function buat_get_user_template($type)
{
$filtered_users=buat_gather_user_ids($type);
$the_members_you_want = "include=" . $filtered_users . "&max=" . $dm_number . "&type=random";
if ( bp_has_members( $the_members_you_want ) ) : ?>
<div style="margin-top: 20px; margin-bottom: 20px;">
<div class="pagination">
<div class="pag-count" id="member-dir-count">
<?php bp_members_pagination_count() ?>
</div>
<div class="pagination-links" id="member-dir-pag">
<?php bp_members_pagination_links() ?>
</div>
</div>
<?php do_action( 'bp_before_directory_members_list' ) ?>
<ul id="members-list" class="item-list" style="list-style-type:none; margin: 0; width: auto">
<?php while ( bp_members() ) : bp_the_member(); ?>
<li>
<div class="item-avatar">
<a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
</div>
<div class="item">
<div class="item-title">
<a href="<?php bp_member_permalink() ?>"><?php bp_member_name() ?></a>
<?php if ( bp_get_member_latest_update() ) : ?>
<span class="update"> - <?php bp_member_latest_update( 'length=10' ) ?></span>
<?php endif; ?>
</div>
<?php do_action( 'bp_directory_members_item' ) ?>
<?php
/***
* If you want to show specific profile fields here you can,
* but it'll add an extra query for each member in the loop
* (only one regadless of the number of fields you show):
*
* bp_member_profile_data( 'field=the field name' );
*/
?>
</div>
<div class="action">
<?php do_action( 'bp_directory_members_actions' ) ?>
</div>
<div class="clear"></div>
</li>
<?php endwhile; ?>
</ul>
<?php do_action( 'bp_after_directory_members_list' ) ?>
<?php bp_member_hidden_fields() ?>
<?php else: ?>
<div id="message" class="info">
<p><?php _e( "Sorry, no members were found.", 'buddypress' ) ?></p>
</div>
<?php endif; ?>
</div>
<?php
}
function buat_get_user_id_by_type($type)
{
global $wpdb;
$fid=get_option('buat_type_field');
$query= "SELECT user_id FROM ".$wpdb->base_prefix."bp_xprofile_data WHERE field_id='$fid' AND value='$type'";
$xpro_data=$wpdb->get_results($query,ARRAY_A);
foreach($xpro_data as $ids)
{
$u_ids[$i++] = $ids['user_id'];
}
return $u_ids;
}
function buat_gather_user_ids($type)
{
$ids = buat_get_user_id_by_type($type);
return implode(',', (array) $ids);
}
function buat_update_role_at_registration($user_id, $user_login, $user_password, $user_email, $usermeta) {
$type_filed_id = get_option('buat_type_field');
$current_role_setting = get_option('buat_user_roles');
$type_value = $usermeta["field_$type_filed_id"];
$type_id = xprofile_get_field_id_from_name($type_value);
$role = $current_role_setting[$type_id];
buat_update_user_role($user_id,$role);
}
add_action('bp_core_signup_user','buat_update_role_at_registration',10,5);
function buat_rimon_habib_donate()
{
?>
<div class="update-nag" style="margin-top: 10px">
<form id="rimon_habib_donate" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="2TXZUHA8DEEWC">
<input type="hidden" name="on0" value="Donation">
<p style="margin-top: 10px; font-size: 14px; color: green;" >You are using Buddypress User Account Type Plugin
Make a donation to support us if you liked this.</p>
<div style="margin-top: 10px">
<select name="os0" style="margin-left:0px">
<option value="Donate5">Donate $5.00 USD</option>
<option selected="selected" value="Donate10">Donate $10.00 USD</option>
<option value="Donate15">Donate $15.00 USD</option>
<option value="Donate20">Donate $20.00 USD</option>
</select>
<br>
<input type="hidden" name="currency_code" value="USD">
<input type="image" style="margin-top:5px; margin-left: 0px" src="http://rimonhabib.com/wp-content/uploads/2012/04/donate.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"
onclick="getElementById('rimon_habib_donate').submit()">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</div>
</div>
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment