Skip to content

Instantly share code, notes, and snippets.

View sbrajesh's full-sized avatar

Brajesh Singh sbrajesh

View GitHub Profile
@sbrajesh
sbrajesh / Community activity as Default
Created June 15, 2011 19:36
It will make the community activity sub tab as default activity tab on profile
//fix the nav default
function bpcom_fix_nav(){
global $bp;
if(!bp_is_my_profile())
return;
if ( $bp->current_component == BP_ACTIVITY_SLUG && $bp->current_action=="just-me" ) {
$action=bpcom_get_current_actual_action();
@sbrajesh
sbrajesh / Allow Developers to Use their own custom css for background positioning etc
Created June 19, 2011 22:37
Allow Developers to Use their own custom css for background positioning etc
<?php
add_filter("bppg_iwilldo_it_myself","__return_true");//stop the plugin to inject css
//now we can write our own css
add_action("wp_head","my_css_for_profile_bg");
function my_css_for_profile_bg(){
$image_url=bppg_get_image();
if(!$image_url)
@sbrajesh
sbrajesh / Allow to change the background of profile container div
Created June 19, 2011 22:59
Allow to change the background of profile container div
<?php
add_filter("bppg_iwilldo_it_myself","__return_true");//stop the plugin to inject css
//now we can write our own css
add_action("wp_head","my_css_for_profile_bg");
function my_css_for_profile_bg(){
$image_url=bppg_get_image();
if(!$image_url)
@sbrajesh
sbrajesh / css mod for Jeremy
Created June 28, 2011 16:11
modification of Background css for Jeremy
<?php
add_filter("bppg_iwilldo_it_myself","__return_true");//stop the plugin to inject css
//now we can write our own css
add_action("wp_head","my_css_for_profile_bg");
function my_css_for_profile_bg(){
$image_url=bppg_get_image();
if(!$image_url)
@sbrajesh
sbrajesh / redirect to Profile
Created July 3, 2011 18:37
Redirect to Profile for admin
<?php
/*
Plugin Name: BP Redirect to Profile for Buddypress
Description:Redirect user to their profile when they login
Version: 1.1.1
Requires at least: BuddyPress 1.1
Tested up to: BuddyPress 1.2.8+WordPress 3.1
License: GNU General Public License 2.0 (GPL) http://www.gnu.org/licenses/gpl.html
Author: Brajesh Singh
Author URI: http://buddydev.com
@sbrajesh
sbrajesh / Create activity entry on profile background upload
Created July 6, 2011 08:55
Create activity entry on profile background upload
add_action("bppg_background_uploaded","bppg_record_activity");
function bppg_record_activity( $bg_image ) {
global $bp;
if ( !function_exists( 'bp_activity_add' ) )
return false;
$r = array(
'user_id' => $bp->loggedin_user->id,
'content' =>false ,
'action'=>sprintf("%s changed their profile background",bp_core_get_userlink( $bp->loggedin_user->id )),
//redirect non logged in users to homepage
function bp_guest_redirect() {
global $bp;
if(!is_user_logged_in()&&!(bp_is_page(BP_REGISTER_SLUG)||bp_is_page(BP_ACTIVATION_SLUG)||is_front_page())) { // not logged in user
wp_safe_redirect( bp_get_root_domain());//make sure page exists exist slug welcome
exit(0);//no further execution
}
}
@sbrajesh
sbrajesh / recent-visitor-show-to-every-one
Created August 3, 2011 01:05
Show recent Visitor to everyone
remove_action("bp_after_member_header","visitors_show_my_recent_visitor");//remove hook
add_action("bp_after_member_header","visitors_show_everyone_recent_visitor");//add custom view
function visitors_show_everyone_recent_visitor(){
global $bp;
$recent_visitors=visitors_get_recent_visitors();
if(empty($recent_visitors))
return;//if no visists yest, do not show at all
@sbrajesh
sbrajesh / xprofile-enhance
Created September 4, 2011 20:55
functions to show the field data or ask to fill it
//pass the field name as string
function show_or_ask_to_fill($field_name){
$data= xprofile_get_field_data($field_name, bp_loggedin_user_id());
if(empty($data)){
$field_id=xprofile_get_field_id_from_name($field_name);
$group_id=custom_get_group_from_field($field_id);
echo sprintf("Please click <a href='%s'>%s</a> to fill the data", bp_get_loggedin_user_link()."profile/edit/group/".$group_id."/#field_".$field_id,$field_name);
}
@sbrajesh
sbrajesh / bpdev_get_age_from_dob
Created October 2, 2011 13:55
Get Age from BuddyPress datebox field data
/**
* Get Age from BuddyPress date of Birth
* @param string $dob_field_name :name of the DOB field in xprofile, like Dob or Date of Birth
* @param int $user_id : the user for which you want to retrieve the age
* @param string $format: the way you want to print the difference, look t <http://php.net/manual/en/dateinterval.format.php> for the acceptable agrs
* @return string :the formatted age in year/month
*/
function bpdev_get_age_from_dob($dob_field_name,$user_id=false,$format="%y Years, %m Month(s), %d days"){
if(!$user_id)