BuddyPress

[sticky] 26 posts, 12 voices - Latest reply from r-a-y

FAQ: How To, Code Snippets and Solutions RSS feed for this topic

Started 11 months ago by Burt Adsit

  • This topic is sticky
  • This topic is not a support question

Avatar Image
Member

Burt Adsit

active 4 days, 6 hours ago

This topic is intended to be a forum resource to collect all the frequently asked questions and their answers. There are a lot of code snippets and how to answers floating around the forums. If you solve what you find is a common problem. Answer a question that seems to be asked frequently or have a small plugin or code snippet to contribute, then post it in this thread. I'll include it in this post. This thread isn't for conversations about such things. It's for contributing what you find or create.

Tools for developers:

Firebug - http://getfirebug.com/ can't live without it.
Hooks and filters in wp utility - http://planetozh.com/blog/my-projects/wordpress-hooks-filter-flow/ this allows you to see all the functions that hook actions and filters in your bp site.

Read this please and leave comments
Buddypress.org needs a common place to share code snippets

Posted 11 months ago #
Avatar Image
Member

Burt Adsit

active 4 days, 6 hours ago

How to modify the buddypress admin bar:
http://codex.buddypress.org/developer-docs/modifying-the-buddypress-admin-bar/
http://buddypress.org/forums/topic.php?id=2186 >> forum topic for discussion

Posted 11 months ago #
Avatar Image
Member

Burt Adsit

active 4 days, 6 hours ago

How to restrict users to one blog per user:
http://buddypress.org/forums/topic.php?id=1328

Posted 11 months ago #
Avatar Image
Member

Burt Adsit

active 4 days, 6 hours ago

Securing components from non logged in users:
http://buddypress.org/forums/topic.php?id=1651

Posted 11 months ago #
Avatar Image
Member

Burt Adsit

active 4 days, 6 hours ago

How to upgrade to the trunk version of buddypress
http://buddypress.org/forums/topic.php?id=2145

You don't have to use SVN if you don't want to:
http://buddypress.org/forums/topic.php?id=2171

SVN is definitely the best way but not the only way.

Posted 11 months ago #
Avatar Image
Moderator

Jeff Sayre

active 3 hours, 56 minutes ago

Having problems uploading an avatar? Do they turn black? Do they not show up at all? Does the cropping tool malfunction?

http://buddypress.org/forums/topic.php?id=302#post-1212

http://buddypress.org/forums/topic.php?id=1960#post-10404

Some good advice on how to change blogs.dir directory permissions: http://buddypress.org/forums/topic.php?id=1153

Here is a rule of thumb. You do not want to try uploading too big or too small of an avatar file. By default, BuddyPress sets the small avatar at 50 by 50 and the large avatar at 150 by 150. So, if your source image is smaller than 150 on at least one of its dimensions, you could have issues with creating the large avatar. If it is smaller than 50 on at least one of its dimensions, you could have issues with creating the small and large avatar.

Finally, if you are still having issues after following the linked advice, you may have a WPMU plugin conflict--especially if you are using any plugins for image manipulation or display. Here is a list of plugins that can cause conflicts that users have reported to date:

  1. NextGen Gallery
  2. WP-cycle
  3. lightbox
  4. Dynamic Content Gallery

To figure out if you have plugin issues, follow the standard WPMU protocol for determining plugin conflicts.

Posted 11 months ago #
Avatar Image
Member

Burt Adsit

active 4 days, 6 hours ago

Limiting the creation of blogs to certain user roles such as Site Admin

This thread describes how to modify the both the admin bar and the member theme navigation functions using bp-custom.php. No core mods needed. It can give you an idea of how to modify any bp function that responds to an action.

http://buddypress.org/forums/topic.php?id=2283

Posted 10 months ago #
Avatar Image
Member

Vsellis

active 8 months, 2 weeks ago

How to show secondary profile fields while hiding the "Base" profile fields in a user profile:

On line 3 of profile-loop.php add:<?php if (!bp_the_profile_group() == "1") : ?>
(after the <?php while ( bp_profile_groups() ) : bp_the_profile_group(); ?>)
and don't forget to close your "if" before the <? endwhile; ?>

Posted 10 months ago #
Avatar Image
Member

Peterverkooijen

active 4 hours, 39 minutes ago

How to synchronize firstname+lastname between xprofile field_1 and wp_usermeta upon registration:

... and ensure firstname+lastname is consistently available in a WP-standard way.

Add this function to bp-custom.php:

function synchro_wp_usermeta($user_id, $password, $meta) {
	global $bp, $wpdb;

	$fullname = $meta[field_1];
	$space = strpos( $fullname, ' ' );

	if ( false === $space ) {
		$firstname = $fullname;
		$lastname = '';
	} else {
		$firstname = substr( $fullname, 0, $space );
		$lastname = trim( substr( $fullname, $space, strlen($fullname) ) );
	}

	update_usermeta( $user_id, 'nickname', $fullname );
	update_usermeta( $user_id, 'first_name', $firstname );
	update_usermeta( $user_id, 'last_name', $lastname );

	$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET display_name = %s WHERE ID = %d", $fullname, $user_id ) );
	$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_url = %s WHERE ID = %d", bp_core_get_user_domain( $user_id ), $user_id ) );
}
add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3);

A check for a two-part name could optionally be added to field_1 using jQuery validation, I think...

Posted 6 months ago #
Avatar Image
Member

Peterverkooijen

active 4 hours, 39 minutes ago

How to autogenerate blogname (url) from Blog Title

The Javascript:

<script type = "text/javascript">
function copyinput()
{
    var tmp = document.getElementById('blog_title').value;
    tmp = tmp.toLowerCase().replace(/^s+|s+$/g, "").replace(/[_|s]+/g, "");
    tmp = tmp.replace(/[^a-z0-9-]+/g, "").replace(/[-]+/g, "-").replace(/^-+|-+$/g, "");
    document.getElementById('blogname').value = tmp;
}
</script>

The customized function:

function custom_signup_show_blog_form( $blogname = '', $blog_title = '', $errors = '' ) {
	global $current_site;

	?>
	<div id="blog-details-fields">

		<label for="blog_title">Blog title</label>
		<?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
			<p class="error"><?php echo $errmsg ?></p>
		<?php }
		echo '<input name="blog_title" type="text" id="blog_title" value="'.wp_specialchars($blog_title, 1).'" maxlength="24" onkeyup="copyinput()"/></p>';

		// Blog name
		if ( 'no' == constant( "VHOST" ) )
			echo '<label for="blogname">' . __('Blog Name:', 'buddypress') . '</label>';
		else
			echo '<label for="blogname">' . __('Blog Domain:', 'buddypress') . '</label>';

		if ( $errmsg = $errors->get_error_message('blogname') ) { ?>
			<p class="error"><?php echo $errmsg ?></p>
		<?php }

		if ( 'no' == constant( "VHOST" ) ) {
			echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span><input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><br />';
		} else {
			echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />';
		}

		if ( !is_user_logged_in() ) {
			echo '<p class="help-text">';
			print '(<strong>' . __( 'Your address will be ', 'buddypress'  );
			if( 'no' == constant( "VHOST" ) ) {
				print $current_site->domain . $current_site->path . __( 'blogname', 'buddypress'  );
			} else {
				print __( 'domain.', 'buddypress'  ) . $current_site->domain . $current_site->path;
			}
			echo '</strong>. ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)', 'buddypress'  ) . '</p>';
			echo '</p>';
		}
	?>
		<p>
			<label for="blog_public_on"><?php _e( 'I would like my blog to appear in search engines like Google and Technorati, and in public listings around this site.', 'buddypress' ); ?> </label>
			<label class="checkbox" for="blog_public_on">
				<input type="radio" id="blog_public_on" name="blog_public" value="1" <?php if( !isset( $_POST['blog_public'] ) || '1' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
				  <?php _e( 'Yes', 'buddypress' ); ?>
			</label>
			<label class="checkbox" for="blog_public_off">
				<input type="radio" id="blog_public_off" name="blog_public" value="0" <?php if( isset( $_POST['blog_public'] ) && '0' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
				  <?php _e( 'No', 'buddypress' ); ?>
			</label>
		</p>
	</div>
	<?php
	do_action('signup_blogform', $errors);
}

What this does:

When the user starts typing the blog title - limited to 24 chars - the Javascript dynamically fills in the blogname for the URL, lowercased and sanitized.

The user can manually change the blogname if he/she wants. Not sure how that would work out... You could prevent that by making the blogname input field 'readonly'.

You could probably also hide the blogname field, either through type="hidden" or CSS. Haven't tested all these options yet.

This same solution could probably be used to generate the username from the Real Name on the main registration form.

Posted 6 months ago #
Avatar Image
Administrator

John James Jacoby

active 3 days, 18 hours ago

Make your own custom BuddyPress page, slug, and template file
http://buddypress.org/forums/topic/make-your-own-custom-buddypress-page

Posted 6 months ago #
Avatar Image
Administrator

John James Jacoby

active 3 days, 18 hours ago

Group/User Avatar Mix-up (usually after update/upgrade)
http://buddypress.org/forums/topic/surprising-avatar-behavior?view=all#post-24791

Posted 4 months ago #
Avatar Image
Member

Michael Berra

active 3 hours, 33 minutes ago

I once posted a forum article about having profile information in the registration-mail to the admin, when a new member registers. We couldn't accomplish that, but a friend of mine made it possible to have a direct link to the members-profile. That's one click away and helps me very much, so that I don't have to search for them. Here is the code, just put it in a php-file and in the mu-plugins folder:

<?php
/*
Plugin Name: My Register Form
Description: Customisations for the Registration Form
Version: 0.1
Author: Marc Cawood
*/

// Custom Message in Registration Mail
add_filter( 'newuser_notify_siteadmin', 'my_newuser_notify_siteadmin');

function my_newuser_notify_siteadmin($msg) {
 global $current_site;
 // Extract member name
 $member = substring_between($msg, ': ', "n");
 // Link to member profile
 $member_url = clean_url("http://{$current_site->domain}{$current_site->path}members/".$member."/profile");
 return $msg . "nn" . $member_url;
}

function substring_between($haystack,$start,$end) {
 $start_position = strpos($haystack,$start)+strlen($start);
 $end_position = strpos($haystack,$end);
 return substr($haystack,$start_position,$end_position-$start_position);
}

?>
Posted 2 months ago #
Avatar Image
Member

Nick Watson

active 42 minutes ago

Email Login & Randomized User URLs

check out the following link for the solution:
http://buddypress.org/forums/topic/email-login-randomized-user-urls-solution

When a user goes to register, they get to type in an email and a password.
Their 'username' field is hidden.

The code will randomly generate a URL for the person like below:

mem12345abcdefghijklmnopqrst

so their URL would be
http://www.yoursite.com/members/mem12345abcdefghijklmnopqrst

Freeing up the good names like John and Smith to be created manually by an administrator.

Posted 1 month ago #
Avatar Image
Member

Mike Pratt

active 23 hours, 52 minutes ago

It's a great idea but just remember that the member directory, as it works now, alphabetizes by username so you will render that useless...for now

Posted 1 month ago #
Avatar Image
Member

Nick Watson

active 42 minutes ago

The member directory alphabetizes by the ''Name" field, which is a mandatory profile field defaulted by buddypress. So the only place that the username is really displayed and used is in the url.

Posted 1 month ago #
Avatar Image
Member

Mike Pratt

active 23 hours, 52 minutes ago

@nickbwatson Duh. You're right. I head my head somewhere else. What I meant to say was it screws up the new Mention feature which makes use of the @username model.

Posted 1 month ago #
Avatar Image
Member

Nick Watson

active 42 minutes ago

Ahh, okay, I hadn't heard of the feature yet.

Maybe there'll be a better solution somewhere.

Posted 1 month ago #
Avatar Image
Moderator

r-a-y

active 8 minutes ago

BP 1.2 Default Theme - Set the Activity Stream as front page, blog posts on another page:

1) Login to the WP backend, navigate to "Pages > Add New". Create an empty, new page called "News" or "Blog" or whatever you want. This page will contain the blog updates.

2) Under "Settings > Reading", set front page to "Activity Stream" and your posts page to the new page that you just created.

Posted 4 weeks ago #
Avatar Image
Moderator

r-a-y

active 8 minutes ago

BP 1.2 - Disable activity stream comments for blog and forum posts

1) Login to the WP backend, navigate to "Buddypress > General settings".

2) Under "Disable activity stream commenting on blog and forum posts?" Select "Yes".

Posted 3 weeks ago #
Avatar Image
Member

Tim Nicholson

active 6 days, 21 hours ago

r-a-y, is there any way to get comments on blog and forum posts (in the BP activity pages) to actually add the comment to the WP blog post or as a reply to the forum post? This would be SO useful. The way it works now is that your user's comments end up staying only within the BP activity stream and don't get reflected on your actual main website (blog)! Disabling it prevents that, but also removes the convenience of user's being able to comment globally from a single place on their BP activity stream pages.

I have to believe this *should* be a pretty easy plugin to develop (depending on how modular the WP and BP code is around this), but would much rather see this built into BP core. I already have a dozen WP plugins that I feel are essential for any blog and as I look to roll out BP, that's going to add many more. I'm tapping out a dedicated server as it is and all these hooks and plugins and template tags and such require some seriously beefy hardware.

Posted 2 weeks ago #
Avatar Image
Moderator

r-a-y

active 8 minutes ago

@Tim

No, not at the moment. This is something I've brought up before, but it's a little bit more complicated than that.

Feel free to create a plugin for it though ;)

Posted 2 weeks ago #
Avatar Image
Member

spammie

active 1 week, 6 days ago

is there a way to get the member id in a member loop?

<?php while ( bp_members() ) : bp_the_member(); ?>
	<input value="<?php bp_member_id(); ?>" name="ids[]"> ids </input>
<?php endwhile; ?>

bp_member_id() is not working, is there a way to achieve this?
otherwise i would have to match the members with their name when doing the database query, and that can be a long string which takes too long to evaluate when compared to an int.

i guess the answer to this question will be an obvious one, as soon as i read it, but right now i am confused

good bye and thanks for all the fish
spammie

Posted 2 weeks ago #
Avatar Image
Member

Brajesh Singh

active 1 day, 19 hours ago

Yes, there is one :)
Instead of bp_member_id() use

bp_member_user_id()
Inside the loop and It will give you the desired result.

Posted 2 weeks ago #
Avatar Image
Member

spammie

active 1 week, 6 days ago

thanks a lot lot lot

bp_member_user_id();
works flawlessly

greetings
spammie

Posted 2 weeks ago #
Avatar Image
Moderator

r-a-y

active 8 minutes ago

Help! There's no register button on my BuddyPress site!

If you're using standard WP, login to the WP admin area, navigate to "Settings > General", and make sure "Anyone can register" is checked.

If you're using WPMU, login to the WPMU admin area, navigate to "Site Admin > Options", and under "Allow new registrations", select any option but "Disabled".

Posted 6 days ago #

Reply

You must log in to post.