Skip to content

Posts from the ‘PHP’ Category

1
Oct

Get just the logged in user url for BuddyPress

There are two functions here,

the first one will return the user url for a specified ID

function bp_core_get_justuserlink( $user_id, $no_anchor = false, $just_link = true, $deprecated = false, $with_s = false ) {
 global $userdata;
 $ud = get_userdata($user_id);
 if ( !$ud )
 return false;
 if ( function_exists('bp_fetch_user_fullname') ) {
 $display_name = bp_core_get_user_displayname( $user_id );
 if ( $with_s )
 $display_name = sprintf( __( "%s's", 'buddypress' ), $display_name );
 } else {
 $display_name = $ud->display_name;
 }
 if ( $no_anchor )
 return $display_name;
 if ( !$url = bp_core_get_userurl($user_id) )
 return false;

 if ( $just_link )
 return $url;
 return $url;
}

The second function will use the first, but get the url of the currently logged in user.

function bp_get_loggedinuser_link() {
 global $bp;

 if ( $link = bp_core_get_justuserlink( $bp->loggedin_user->id ) ) {
 return $link;
 }
 }
1
Oct

Disable all caching on specific pages

Copy and paste this code into the template you want to disable caching on, usually used on activation pages
if( is_object( $wp_object_cache ) )
	   $wp_object_cache->cache_enabled = false;
1
Oct

Get just the link for the current logged in user

Any one who need to the the link for the current user. eg /member/admin or /member/warwick
Paste this code into the function.php for the theme and call it.


function bp_get_loggedinuser_link() {
 global $bp;
 if ( $link = bp_core_get_userlink( $bp->loggedin_user->id ) ) {
 return apply_filters( 'bp_loggedinuser_link', $link );
 }
 }
1
Oct

Easily add conversion code to the registration process

Use this to add Google Adwords conversion script to your BuddyPress Install

google_adwords is the name on the function printing the code.

add_action(’signup_finished’,'google_adwords’);
1
Oct

Ever wondered how to query the url of the page you are on?

Get The current page url you are on

In a php tag

echo ‘http://’.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];