<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GeneralThreat.com &#187; buddypress</title>
	<atom:link href="http://www.generalthreat.com/tag/buddypress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.generalthreat.com</link>
	<description>Dangerously different projects and code</description>
	<lastBuildDate>Sun, 19 Jan 2014 20:00:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>Grappling with BP theme compatibility</title>
		<link>http://www.generalthreat.com/2013/08/grappling-with-bp-theme-compatibility/</link>
		<comments>http://www.generalthreat.com/2013/08/grappling-with-bp-theme-compatibility/#comments</comments>
		<pubDate>Wed, 28 Aug 2013 18:16:26 +0000</pubDate>
		<dc:creator><![CDATA[David]]></dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[buddypress]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.generalthreat.com/?p=104</guid>
		<description><![CDATA[Theme compatibility was introduced in BuddyPress 1.7 and allows site operators to use BP with any available WordPress theme. I have been way behind at updating BP Group Hierarchy to support theme compatibility, and&#46;&#46;&#46;]]></description>
				<content:encoded><![CDATA[<p><a href="http://codex.buddypress.org/theme-compatibility/">Theme compatibility</a> was introduced in BuddyPress 1.7 and allows site operators to use BP with any available WordPress theme. I have been way behind at updating <a href="http://wordpress.org/plugins/bp-group-hierarchy/">BP Group Hierarchy</a> to support theme compatibility, and as a result the Group Tree page looks like garbage when not using a theme that was written for BuddyPress. This post is about the effort to fix that.</p>
<p>If you are writing a normal BuddyPress plugin &#8212; one that adds pages rather than replacing them &#8212; see <a href="http://codex.buddypress.org/theme-compatibility/upgrading-older-plugins-that-bundle-custom-templates-for-bp-1-7/">this excellent article</a> (and <a href="http://codex.buddypress.org/theme-compatibility/how-to-enjoy-bp-theme-compat-in-plugins/">this one too</a>) at the BuddyPress Codex for info on how to implement BP theme compatibility.</p>
<h2>First idea: Replace the content from <code>directory_content</code> with the group tree.</h2>
<p><code>BP_Groups_Theme_Compat::directory_content()</code> is the native BP function that displays the group list page. It&#8217;s called as a hook to a filter called <code>bp_replace_the_content</code>, so the content should be available for further filtering after it runs.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * (BP 1.7+) Filter the theme-compatibility content for a group tree page
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> bp_group_hierarchy_inject_group_tree<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        add_filter<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_replace_the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bp_group_hierarchy_buffer_group_tree'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">100</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> bp_group_hierarchy_buffer_group_tree<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$content</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$loop_template</span> <span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_located_template'</span><span style="color: #339933;">,</span> locate_template<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;tree/index.php&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;tree/index.php&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        load_template<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$loop_template</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ob_get_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// If admin says only show the group tree (and we are in theme compat), do it:</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'groups_directory_groups_setup'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bp_group_hierarchy_inject_group_tree'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Result:</strong> No dice. Directory content is echoed to the screen, not returned to the filter chain. The group tree appears below the flat group list.</p>
<h2>Workaround / second idea: Unhook the <code>directory_content</code> function so it doesn&#8217;t echo.</h2>
<p>Here&#8217;s a snippet that I threw together testing this out (warning: closure => PHP 5.3+ !):</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * (BP 1.7+) Filter the theme-compatibility content for a group tree page
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> bp_group_hierarchy_inject_group_tree<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        add_filter<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_replace_the_content'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #009933; font-style: italic;">/**
                 * Filter is hooked by a method of an anonymous instance...
                 * Search all registered listeners and pick off the BP_Groups_Theme_Compat one.
                 */</span>
&nbsp;
                <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_filter</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wp_filter</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'bp_replace_the_content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$filter</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$filter</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'function'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">is_a</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$filter</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'function'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'BP_Groups_Theme_Compat'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                                <span style="color: #666666; font-style: italic;">// Found and removing the native content</span>
                                <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wp_filter</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'bp_replace_the_content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        add_filter<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_replace_the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bp_group_hierarchy_buffer_group_tree'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">100</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> bp_group_hierarchy_buffer_group_tree<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$content</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">/* Same as before */</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// If admin says only show the group tree (and we are in theme compat), do it:</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'groups_directory_groups_setup'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bp_group_hierarchy_inject_group_tree'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Result:</strong> Works well but is pretty awkward and brittle. It looks like the kind of solution I&#8217;d really like to avoid.</p>
<p>Let&#8217;s try something completely different. <img src="http://www.generalthreat.com/wordpress/wp-includes/images/smilies/simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h2>Third idea: Use BP Theme Compat functions to replace the loop template file.</h2>
<p>BuddyPress theme compatibility adds a lot of flexibility in how content is gathered for the site. I actually find the theme compatibility process much more intuitive to work with than the traditional template loading process.</p>
<p>Here are some highlights:</p>
<ol>
<li><code>bp_register_template_stack()</code> lets you add a source of template files without filtering <code>bp_located_template</code>. Nice!</li>
<li><code>bp_get_template_part()</code> offers an easy way to switch out template files on the fly that is just not possible with <code>load_template</code>.</li>
</ol>
<p>Is it really this easy?</p>
<p><strong>SPOILER ALERT:</strong> This does not work for BP Group Hierarchy. But for most applications, I think this is the best way to conditionally replace a BP page with content from a plugin.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * (BP 1.7+) Add plugin templates folder to list of available template paths
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> bp_group_hierarchy_register_template_location<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span> <span style="color: #009900; font-weight: bold;">__FILE__</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/templates/'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * (BP 1.7+) Replace groups/groups-loop with tree/tree-loop depending on user settings
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> bp_group_hierarchy_maybe_replace_group_loop_template<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$templates</span><span style="color: #339933;">,</span> <span style="color: #000088;">$slug</span><span style="color: #339933;">,</span> <span style="color: #000088;">$name</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'groups/groups-loop'</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$slug</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$templates</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'tree/tree-loop.php'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_register_template_stack'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
	bp_register_template_stack<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_group_hierarchy_register_template_location'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// If admin says only show the group tree (and we are in theme compat), do it:</span>
add_filter<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_get_template_part'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bp_group_hierarchy_maybe_replace_group_loop_template'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Result:</strong> Works(!)<br />
But when you trigger an AJAX request, the unaltered ID on the &#8220;All Groups&#8221; tab leads BP to load the flat list.<br />
We also still need to hook the <code>bp_located_template</code> filter to find stylesheets, since we are enqueue-ing them instead of loading the contents inline.<br />
It also also removes the ability to customize the &#8220;Group Tree&#8221; label, a feature added by popular demand.</p>
<h2>Fourth idea: Use BP Theme Compat functions to replace the whole Groups list page.</h2>
<p>This is really just a twist on how things are currently handled, and it looks like the current way will be around as long as BP-compatible themes bypass <code>bp_get_template_part</code>.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * (BP 1.7+) Add plugin templates folder to list of available template paths
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> bp_group_hierarchy_register_template_location<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span> <span style="color: #009900; font-weight: bold;">__FILE__</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/templates/'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * (BP 1.7+) Replace groups/index with tree/index-compat depending on user settings
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> bp_group_hierarchy_maybe_replace_group_index_template<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$templates</span><span style="color: #339933;">,</span> <span style="color: #000088;">$slug</span><span style="color: #339933;">,</span> <span style="color: #000088;">$name</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'groups/index'</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$slug</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$templates</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'tree/index-compat.php'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_register_template_stack'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
	bp_register_template_stack<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_group_hierarchy_register_template_location'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// If admin says only show the group tree (and we are in theme compat), do it:</span>
add_filter<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_get_template_part'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bp_group_hierarchy_maybe_replace_group_index_template'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Result:</strong> Works seamlessly. It even allows BP to load templates from the stylesheet and template directories before falling back to those included with the plugin.</p>
<p>The only drawback is that it requires a new template file, the group tree version of the <code>bp-templates/bp-legacy/buddypress/groups/index.php</code> file from BP. Which is to say that it adds another layer of template hijinks and possible theme compatibility issues rather than removing an existing one.</p>
<h2>Wrap up</h2>
<p>I don&#8217;t know if this is the strategy that will ultimately make it into the plugin, but it is straightforward and has performed well in early tests. In the meantime, I hope this post will be useful to anyone else trying to do something crazy and ill-advised with BuddyPress.</p>
<p>If you use any of the techniques on this page, please drop me a line in the comments and let me know how they worked for you. And if you have any suggestions on techniques that work even better than these, please send those along too. <img src="http://s.w.org/images/core/emoji/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.generalthreat.com/2013/08/grappling-with-bp-theme-compatibility/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extending BuddyPress Group Hierarchy &#8211; Adding Breadcrumbs to Your Theme</title>
		<link>http://www.generalthreat.com/2012/04/extending-buddypress-group-hierarchy-adding-breadcrumbs-to-your-theme/</link>
		<comments>http://www.generalthreat.com/2012/04/extending-buddypress-group-hierarchy-adding-breadcrumbs-to-your-theme/#comments</comments>
		<pubDate>Wed, 04 Apr 2012 17:49:34 +0000</pubDate>
		<dc:creator><![CDATA[David]]></dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[buddypress]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.generalthreat.com/?p=87</guid>
		<description><![CDATA[Once you&#8217;ve created a hierarchy of BuddyPress groups, you can help your users navigate and give your site the professional touch by including group breadcrumbs where appropriate. Here&#8217;s how! Step One: Change the link&#46;&#46;&#46;]]></description>
				<content:encoded><![CDATA[<p>Once you&#8217;ve created a hierarchy of BuddyPress groups, you can help your users navigate and give your site the professional touch by including group breadcrumbs where appropriate. Here&#8217;s how!</p>
<h3>Step One: Change the link at the top of every group page to a trail of links to parent groups</h3>
<p>This is the easy part! BuddyPress Group Hierarchy includes a function, <code>bp_group_hierarchy_breadcrumbs()</code>, that will generate a string of links to a group and all its parents. Use it in the Groups loop, and no parameter is required. </p>
<p><strong>Note:</strong> If you need to pass in a different group for some reason, you&#8217;ll need to use <code>bp_group_hierarchy_get_breadcrumbs( $separator = '|', $group = false )</code> function and echo the result yourself. This tutorial won&#8217;t address using that more advanced function.</p>
<p>Just locate your theme&#8217;s <code>groups/single/group-header.php</code> file, and find the current group header which will look something like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">&lt;h2&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bp_group_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bp_group_name<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bp_group_name<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h2&gt;</pre></td></tr></table></div>

<p>Replace it with this simple line:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">&lt;h2&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bp_group_hierarchy_breadcrumbs<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h2&gt;</pre></td></tr></table></div>

<h3>Step Two: Change the page title on group pages to reflect your group structure</h3>
<p>Changing the page title is more complicated. BuddyPress builds its page titles with a function hooked to the <code>wp_title</code> filter. This function in turn presents its own filter, and that&#8217;s the one we have to hook to put breadcrumbs in the title of our Group page. This makes sure our filtering function runs only when BuddyPress is enabled and on as few pages as necessary.</p>
<p>If you zoned out during that bit, don&#8217;t worry! Just place the code below into your theme&#8217;s <code>functions.php</code> file.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_modify_page_title'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_func_group_breadcrumbs'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> my_func_group_breadcrumbs<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$processed_title</span><span style="color: #339933;">,</span> <span style="color: #000088;">$title</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sep</span><span style="color: #339933;">,</span> <span style="color: #000088;">$seplocation</span>  <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$bp</span><span style="color: #339933;">;</span>
&nbsp;
 	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> bp_is_active<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'groups'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$bp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">groups</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current_group</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$processed_title</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$processed_title</span><span style="color: #339933;">,</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$processed_title</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sep</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$processed_title</span> <span style="color: #339933;">=</span> bp_group_hierarchy_get_full_name<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'|'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$bp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">groups</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current_group</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$processed_title</span><span style="color: #339933;">;</span>
 	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$processed_title</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This function strips the group name from the page title, but re-adds the names of the group and all its ancestors. The <code>bp_group_hierarchy_get_full_name</code> function works like the <code>bp_group_hierarchy_get_breadcrumbs</code> function I mentioned earlier, but it builds a plain text list instead of a list of links.</p>
<p>That&#8217;s it!  Check back soon for a reference child theme, implementing this technique. As always, if you have any questions or problems adding this to your site, or if you have a novel implementation you&#8217;d like to share, please post in the comments below!</p>
<p><ins datetime="2012-04-06T15:02:01+00:00"><strong>Update:</strong> As promised, here is the sample child theme! <a href="http://www.generalthreat.com/downloads/GroupBreadcrumbs.zip" title="Download BuddyPress Group Hierarchy Breadcrumbs - Sample Theme">BuddyPress Group Hierarchy Breadcrumbs - Sample Theme</a></ins></p>
]]></content:encoded>
			<wfw:commentRss>http://www.generalthreat.com/2012/04/extending-buddypress-group-hierarchy-adding-breadcrumbs-to-your-theme/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adding Externally-Authenticated Users to BuddyPress</title>
		<link>http://www.generalthreat.com/2012/02/adding-externally-authenticated-users-to-buddypress/</link>
		<comments>http://www.generalthreat.com/2012/02/adding-externally-authenticated-users-to-buddypress/#comments</comments>
		<pubDate>Wed, 29 Feb 2012 01:49:26 +0000</pubDate>
		<dc:creator><![CDATA[David]]></dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[buddypress]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.generalthreat.com/?p=85</guid>
		<description><![CDATA[BuddyPress does a great job integrating new users who register through your WordPress site into the community &#8212; optionally synchronizing profile information between BP and WP, and creating an activity feed item for new&#46;&#46;&#46;]]></description>
				<content:encoded><![CDATA[<p>BuddyPress does a great job integrating new users who register through your WordPress site into the community &mdash; optionally synchronizing profile information between BP and WP, and creating an activity feed item for new user signups.</p>
<p>But what about users who login against an external authentication provider, and whose accounts are created and managed by such a system? Today we&#8217;re going to look at how to bring those users into the community in the same way as those who registered locally. Be warned &mdash; this is a fairly dense piece, especially if you haven&#8217;t worked with an <code>authenticate</code> filter before.</p>
<h3>A crash course on <code>authenticate</code></h3>
<p>If you are using (or writing) an external authentication plugin, you&#8217;ll need a function hooked to the <code>authenticate</code> filter. This function is where your plugin gets a chance to authenticate users against your outside system. It is also where your users will have subordinate WordPress accounts made and managed by the external system.</p>
<p>A very quick example:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> my_func_to_authenticate<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #666666; font-style: italic;">// if $user is a valid WP_User, authenticated by an upstream filter</span>
 <span style="color: #666666; font-style: italic;">// pass these params to the external auth source for verification</span>
 <span style="color: #666666; font-style: italic;">// proceed if user is logged in, otherwise return a WP_Error</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'authenticate'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_func_to_authenticate'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>The first login</h3>
<p>The first time your users log in to your WordPress install using their external credentials, you&#8217;ll probably want to create a WP account for them. You may skip this if you&#8217;re just trying to restrict read access, but this is about BuddyPress, so I&#8217;m assuming you want them to post and contribute to the site. <img src="http://www.generalthreat.com/wordpress/wp-includes/images/smilies/simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>Here&#8217;s a rundown of the process:</p>
<ol>
<li>Suppress the BuddyPress activation email</li>
<li>Create WP user account</li>
<li>Update user meta and, optionally, xprofile data</li>
<li>Activate user and set proper <code>display_name</code></li>
<li>Publish activity stream message about new user, with properly-formatted display name</li>
</ol>
<h4>Suppress the BuddyPress activation email</h4>
<p>These users are already verified by virtue of being in our external auth system, so an activation email would just be confusing.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/** Suppress activation key email for users logging in with external auth */</span>
add_filter<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_core_signup_send_activation_key'</span><span style="color: #339933;">,</span> <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'return false;'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Create WordPress user account</h4>
<p>Normally, you&#8217;d use <code><a href="http://codex.wordpress.org/Function_Reference/wp_create_user">wp_create_user</a></code> (or <code><a href="http://codex.wordpress.org/Function_Reference/wp_insert_user">wp_insert_user</a></code> if you want access to the full set of user properties).<br />
But BuddyPress comes with a wrapper function that can be used to do a lot of the heavy lifting for us.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$new_user</span> <span style="color: #339933;">=</span> bp_core_signup_user<span style="color: #009900;">&#40;</span>
	<span style="color: #000088;">$user_login</span><span style="color: #339933;">,</span>
	<span style="color: #000088;">$user_password</span><span style="color: #339933;">,</span>
	<span style="color: #000088;">$user_email</span><span style="color: #339933;">,</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> is_wp_error<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_user</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$new_user</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>Update user meta and, optionally, xprofile data</h4>
<p>There are actually a few ways to handle this, ranging from bull-in-a-china-shop overwriting to graceful but more complicated filtering. Which one you choose may depend on your comfort with WP or PHP, which BuddyPress features you have enabled, or the structure of your authentication script.</p>
<p><div class='postTabs_divs postTabs_curr_div' id='postTabs_0_85'>
<span class='postTabs_titles'><b>Easiest</b></span></p>
<h5>Easiest</h5>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$display_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$first_name</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$last_name</span><span style="color: #339933;">;</span>
&nbsp;
update_user_meta<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_user</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'nickname'</span><span style="color: #339933;">,</span>   <span style="color: #000088;">$display_name</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
update_user_meta<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_user</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'first_name'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$first_name</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
update_user_meta<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_user</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'last_name'</span><span style="color: #339933;">,</span>  <span style="color: #000088;">$last_name</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> bp_is_active<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'xprofile'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
	xprofile_set_field_data<span style="color: #009900;">&#40;</span> bp_xprofile_fullname_field_name<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$new_user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$display_name</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Even though setting the xprofile value, above, should take care of this, </span>
<span style="color: #666666; font-style: italic;">// testing revealed that we needed to prime the cache with the right value</span>
wp_cache_set<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_user_fullname_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$new_user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$display_name</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bp'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>PROS: </p>
<ul>
<li>Very straightforward and procedural &mdash; no objects or data sharing needed</li>
<li>Complete control over format of display_name and BP fullname field</li>
<li>Control over any other BP xprofile values you want to set</li>
<li>Does not require xprofile or WP-BP profile sync in order to operate</li>
</ul>
<p>CONS:</p>
<ul>
<li>Will ultimately drift out of sync with BP development</li>
<li>Still need to set the display_name property below</li>
<li>Might as well use <code>wp_insert_user</code>, since we&#8217;re manually adding so much</li>
</ul>
<p></div>

<div class='postTabs_divs' id='postTabs_1_85'>
<span class='postTabs_titles'><b>Shortest</b></span></p>
<h5>Shortest</h5>
<p>Replace the <code>bp_core_signup_user</code> call above with this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$new_user</span> <span style="color: #339933;">=</span> bp_core_signup_user<span style="color: #009900;">&#40;</span>
	<span style="color: #000088;">$login_name</span><span style="color: #339933;">,</span>
	<span style="color: #000088;">$password</span><span style="color: #339933;">,</span>
	<span style="color: #000088;">$email</span><span style="color: #339933;">,</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'profile_field_ids'</span> <span style="color: #339933;">=&gt;</span> bp_xprofile_fullname_field_name<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">&quot;field_{bp_xprofile_fullname_field_name()}&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$display_name</span>
	<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>PROS: </p>
<ul>
<li>Uses BP to eliminate the need for additional filters or processing</li>
<li>Least code redundancy of all</li>
<li>Can supply additional xprofile fields to be added to the new user</li>
<li>Most natural method in terms of program flow</li>
</ul>
<p>CONS:</p>
<ul>
<li>Complex meta parameter structure can be difficult to read</li>
<li>Parameter or data structure may change in future BP releases</li>
<li>Requires xprofile and WP-BP profile sync to update WP display_name and usermeta</li>
</ul>
<p></div>

<div class='postTabs_divs' id='postTabs_2_85'>
<span class='postTabs_titles'><b>Fanciest</b></span></p>
<h5>Fanciest</h5>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> my_display_name_filter<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$user_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user_login</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user_password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user_email</span><span style="color: #339933;">,</span> <span style="color: #000088;">$usermeta</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// must get $display_name from another part of the authentication process</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> bp_is_active<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'xprofile'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		xprofile_set_field_data<span style="color: #009900;">&#40;</span> bp_xprofile_fullname_field_name<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$new_user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$display_name</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Change your authenticate function to look like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> my_func_to_authenticate<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// ... authenticate user</span>
	add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_core_signup_user'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_display_name_filter'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$new_user</span> <span style="color: #339933;">=</span> bp_core_signup_user<span style="color: #009900;">&#40;</span>
		<span style="color: #000088;">$login_name</span><span style="color: #339933;">,</span>
		<span style="color: #000088;">$password</span><span style="color: #339933;">,</span>
		<span style="color: #000088;">$email</span><span style="color: #339933;">,</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>PROS: </p>
<ul>
<li>Uses BP filters for forward compatibility</li>
<li>Reduces the amount of repeated code</li>
</ul>
<p>CONS:</p>
<ul>
<li>Requires an object or data-sharing infrastructure to get user details to the filter</li>
<li>Requires xprofile and WP-BP profile sync to  update WP display_name and usermeta</li>
</ul>
<p></div>

</p>
<hr />
Now that the xprofile and usermeta data are set up, it&#8217;s time to activate the user! This is done by simply setting the <code>user_status</code> column to <code>0</code>.</p>
<h4>Activate user (and set proper display_name, if needed)</h4>
<p><ins datetime="2012-08-06T23:43:09+00:00"><strong>Update 08-06-2012:</strong> I used to recommend <code>wp_update_user</code> for this, but that has proven unreliable on a recent project. So to be safe, just use a direct query.</ins></p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// activate user and set display name appropriately</span>
<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;UPDATE <span style="color: #006699; font-weight: bold;">$wpdb-&gt;users</span> SET display_name=<span style="color: #009933; font-weight: bold;">%s</span>, user_status=0 WHERE ID=<span style="color: #009933; font-weight: bold;">%d</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$display_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$new_user</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And if you set <code>$display_name</code> above, use the shortened version:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// activate user</span>
<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;UPDATE <span style="color: #006699; font-weight: bold;">$wpdb-&gt;users</span> SET user_status=0 WHERE ID=<span style="color: #009933; font-weight: bold;">%d</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$new_user</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Publish an activity stream message about the new user and notify the site admin</h4>
<p>Since the display_name property and associated xprofile field are finally set the way we want them, it&#8217;s time to trigger the activity stream message and administrator notification.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">bp_core_new_user_activity<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_user</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
wp_new_user_notification<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_user</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>And you&#8217;re done!</h4>
<p>Return a <code>WP_User</code> object to let other authentication filters know you&#8217;ve handled this user.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> WP_User<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_user</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>A complete example</h3>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> my_func_to_authenticate<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// if $user is a valid WP_User, authenticated by an upstream filter</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">is_a</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'WP_User'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$user</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// pass these params to the external auth source for verification</span>
	<span style="color: #666666; font-style: italic;">// proceed if user is logged in, otherwise return a WP_Error</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$user_details</span> <span style="color: #339933;">=</span> my_external_auth<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// for simplicity's sake, I'm assuming that $user_details is an array with all the right keys</span>
		<span style="color: #666666; font-style: italic;">// in practice, more checks would be required</span>
		<span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$user_details</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// this function returns the new user account ID if successful</span>
		<span style="color: #000088;">$new_user</span> <span style="color: #339933;">=</span> bp_core_signup_user<span style="color: #009900;">&#40;</span>
			<span style="color: #000088;">$username</span><span style="color: #339933;">,</span>
			<span style="color: #000088;">$password</span><span style="color: #339933;">,</span>
			<span style="color: #000088;">$user_email</span><span style="color: #339933;">,</span>
			<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// If signup returned an error, skip the rest</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> is_wp_error<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_user</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$new_user</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$display_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$first_name</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$last_name</span><span style="color: #339933;">;</span>
&nbsp;
		update_user_meta<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_user</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'nickname'</span><span style="color: #339933;">,</span>   <span style="color: #000088;">$display_name</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		update_user_meta<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_user</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'first_name'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$first_name</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		update_user_meta<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_user</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'last_name'</span><span style="color: #339933;">,</span>  <span style="color: #000088;">$last_name</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> bp_is_active<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'xprofile'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
			xprofile_set_field_data<span style="color: #009900;">&#40;</span> bp_xprofile_fullname_field_name<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$new_user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$display_name</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Even though setting the xprofile value, above, should take care of this, </span>
		<span style="color: #666666; font-style: italic;">// testing revealed that we needed to prime the cache with the right value</span>
		wp_cache_set<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_user_fullname_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$new_user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$display_name</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bp'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// activate user and set display name appropriately</span>
		<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">prepare</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;UPDATE <span style="color: #006699; font-weight: bold;">$wpdb-&gt;users</span> SET display_name=<span style="color: #009933; font-weight: bold;">%s</span>, user_status=0 WHERE ID=<span style="color: #009933; font-weight: bold;">%d</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$display_name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$new_user</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		bp_core_new_user_activity<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_user</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		wp_new_user_notification<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_user</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> WP_User<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_user</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">// you can return FALSE, or a WP_Error if you have something specific to say</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> WP_Error<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'login_failed'</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Could not authenticate user'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'authenticate'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_func_to_authenticate'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If you have questions, or if you put this to use in your next project, feel free to drop me a line in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.generalthreat.com/2012/02/adding-externally-authenticated-users-to-buddypress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Extending BuddyPress Group Hierarchy &#8211; Creating a Member Groups list</title>
		<link>http://www.generalthreat.com/2012/01/extending-buddypress-group-hierarchy-list-member-groups/</link>
		<comments>http://www.generalthreat.com/2012/01/extending-buddypress-group-hierarchy-list-member-groups/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 19:44:39 +0000</pubDate>
		<dc:creator><![CDATA[David]]></dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[buddypress]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.generalthreat.com/?p=82</guid>
		<description><![CDATA[In this post, I&#8217;m going to show you how to create a Member Groups page/list/widget, with a little background on how Group Hierarchy extends the BuddyPress Groups loop. BuddyPress Groups loop overview If you&#46;&#46;&#46;]]></description>
				<content:encoded><![CDATA[<p>In this post, I&#8217;m going to show you how to create a Member Groups page/list/widget, with a little background on how Group Hierarchy extends the BuddyPress Groups loop.</p>
<h2>BuddyPress Groups loop overview</h2>
<p>If you aren&#8217;t familiar with <code>bp_has_groups()</code> from looking at the BuddyPress theme files, you should take a look at <a href="http://codex.buddypress.org/developer-docs/custom-buddypress-loops/the-groups-loop/">this overview</a> from the BP Codex before continuing.</p>
<p>In a nutshell, <code>bp_has_groups()</code> accepts a series of parameters which it uses to populate the global <code>$groups_template</code> variable with a set of groups. This, in turn, allows all the cool template functions to work without parameters cluttering up your theme file.</p>
<h2>How Group Hierarchy changes the Loop</h2>
<p>BuddyPress Group Hierarchy changes this in two important ways:</p>
<ol>
<li><code>bp_has_groups()</code> creates a set of <code>BP_Groups_Hierarchy</code> objects instead of <code>BP_Groups_Group</code> objects</li>
<li><code>bp_has_groups_hierarchy()</code> extends the loop with a <code>parent_id</code> parameter for getting only child groups of the passed group ID</li>
</ol>
<p>There are more changes made just for the Group Tree, but that&#8217;s enough to get us started. Onward!</p>
<h2>Creating a Member Groups list</h2>
<p>Before we build our Member Groups page / widget / list, there&#8217;s something you should know about working &#8220;in the loop,&#8221; i.e. in the context of the current group. The only thing telling BuddyPress what group we&#8217;re looking at is the <code>$groups_template</code> variable introduced above. Our member group list is going to change that variable, so we need to save its current state and restore it when we&#8217;re done.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// If you're in a function, bring $groups_template into scope</span>
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$groups_template</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Save the current group context for later</span>
<span style="color: #000088;">$current_group_template</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$groups_template</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Using the Codex article I posted at the top as a reference, you&#8217;ll see how easy it is to create a Member Groups page / widget / whatever.</p>
<p>Just replace:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> bp_has_groups<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>with:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> bp_has_groups_hierarchy<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
	<span style="color: #0000ff;">'type'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'alphabetical'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'parent_id'</span> <span style="color: #339933;">=&gt;</span> bp_get_current_group_id<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>&#8230;and the rest works as is! Since 1.3.0, pagination is handled automatically.</p>
<p>Don&#8217;t forget to restore the original context!</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$groups_template</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$current_group_template</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h2>A complete example</h2>
<p>Here&#8217;s a quick example that adds a list of Member Groups on the Members page, above the list of users. Drop this in your <code>functions.php</code> file, or in a custom plugin, but note that it will only display if the parent group has at least one member!</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_before_group_members_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_func_list_member_groups'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> my_func_list_member_groups<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// If you're in a function, bring $groups_template into scope</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$groups_template</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Save the current group context for later</span>
	<span style="color: #000088;">$current_group_template</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$groups_template</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> bp_has_groups_hierarchy<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
		<span style="color: #0000ff;">'type'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'alphabetical'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'parent_id'</span> <span style="color: #339933;">=&gt;</span> bp_get_current_group_id<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
	&lt;h3&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> _e<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Member Groups'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;br /&gt;&amp;nbsp;&lt;/h3&gt;
&nbsp;
	&lt;div class=&quot;pagination&quot;&gt;
&nbsp;
		&lt;div class=&quot;pag-count&quot; id=&quot;group-dir-count&quot;&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> bp_groups_pagination_count<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;/div&gt;
&nbsp;
		&lt;div class=&quot;pagination-links&quot; id=&quot;group-dir-pag&quot;&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> bp_groups_pagination_links<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;/div&gt;
&nbsp;
	&lt;/div&gt;
&nbsp;
	&lt;ul id=&quot;groups-list&quot; class=&quot;item-list&quot;&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> bp_groups<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> bp_the_group<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
		&lt;li&gt;
			&lt;div class=&quot;item-avatar&quot;&gt;
				&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bp_group_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bp_group_avatar<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'type=thumb&amp;width=50&amp;height=50'</span> <span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;
			&lt;/div&gt;
&nbsp;
			&lt;div class=&quot;item&quot;&gt;
				&lt;div class=&quot;item-title&quot;&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bp_group_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bp_group_name<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/div&gt;
				&lt;div class=&quot;item-meta&quot;&gt;&lt;span class=&quot;activity&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span> __<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'active %s ago'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'buddypress'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> bp_get_group_last_active<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/span&gt;&lt;/div&gt;
&nbsp;
				&lt;div class=&quot;item-desc&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bp_group_description_excerpt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;
&nbsp;
				<span style="color: #000000; font-weight: bold;">&lt;?php</span> do_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_directory_groups_item'</span> <span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
				&lt;/div&gt;
&nbsp;
			&lt;div class=&quot;action&quot;&gt;
				<span style="color: #000000; font-weight: bold;">&lt;?php</span> bp_group_join_button<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
				&lt;div class=&quot;meta&quot;&gt;
					<span style="color: #000000; font-weight: bold;">&lt;?php</span> bp_group_type<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> / <span style="color: #000000; font-weight: bold;">&lt;?php</span> bp_group_member_count<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
				&lt;/div&gt;
&nbsp;
				<span style="color: #000000; font-weight: bold;">&lt;?php</span> do_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_directory_groups_actions'</span> <span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;/div&gt;
&nbsp;
			&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
		&lt;/li&gt;
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/ul&gt;
&nbsp;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> do_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_after_member_groups_loop'</span> <span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
		&lt;div id=&quot;message&quot; class=&quot;info&quot;&gt;
		&lt;p&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> _e<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'There were no member groups found.'</span> <span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/p&gt;
		&lt;/div&gt;
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// restore original group context!</span>
	<span style="color: #000088;">$groups_template</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$current_group_template</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>That&#8217;s it! Drop me a line in the comments if you find a novel use for this technique.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.generalthreat.com/2012/01/extending-buddypress-group-hierarchy-list-member-groups/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Extending BuddyPress Group Hierarchy &#8211; Join to Upstream Groups</title>
		<link>http://www.generalthreat.com/2011/12/extending-groups-hierarchy-join-upstream/</link>
		<comments>http://www.generalthreat.com/2011/12/extending-groups-hierarchy-join-upstream/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 18:23:16 +0000</pubDate>
		<dc:creator><![CDATA[David]]></dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[buddypress]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.generalthreat.com/?p=74</guid>
		<description><![CDATA[Introduction A frequent feature request for BuddyPress Group Hierarchy has been to automatically join members of a subgroup to its parent groups. While pretty straightforward to implement, there are two main reasons this feature&#46;&#46;&#46;]]></description>
				<content:encoded><![CDATA[<h3>Introduction</h3>
<p>A frequent feature request for BuddyPress Group Hierarchy has been to automatically join members of a subgroup to its parent groups.  While pretty straightforward to implement, there are two main reasons this feature won&#8217;t make it into the plugin:</p>
<ol>
<li>This behavior isn&#8217;t appropriate for many or even most setups</li>
<li>Everyone who has requested it has wanted it to work on groups by different criteria &mdash; some want groups of a certain depth, others a specific set of groups, others all the children of a certain group. Building a UI that would let this work the way anyone wants would overwhelm the project.</li>
</ol>
<p>Instead, I decided to post this sample implementation, including a few ways to select groups. Take a look!</p>
<h3>The Code</h3>
<p><ins datetime="2011-12-08T11:55:27+00:00">The code below can be included in your theme&#8217;s <code>functions.php</code> file, or can be part of a new plugin.</ins></p>
<p><strong>Note for the true novice:</strong> you must <strong>choose one</strong> of the <code>if</code> statements in the block below with this code and substitute the placeholders for things you care about. It will not work pasted as is.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* groups_join_group is called whenever someone joins a group in both BP 1.2 and 1.5.x */</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'groups_join_group'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_join_group_action'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> my_join_group_action<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$group_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user_id</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* This part is critical - you must select ONLY the groups you want to START this chain
	 * This function will recurse up to the toplevel on its own, so if you have a parent group
	 * in the list, you will waste resources trying to join the same group multiple times
	 * as this function is called on each step up the tree
	 */</span> 
	<span style="color: #009933; font-style: italic;">/** Pick from a list of groups */</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$group_id</span><span style="color: #339933;">,</span> ARRAY_OF_GROUPS_I_CARE_ABOUT <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">/* -- OR -- */</span>
	<span style="color: #009933; font-style: italic;">/** Select groups by depth */</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span> bp_group_hierarchy_get_parents<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> DEPTH_OF_GROUP_I_CARE_ABOUT_EG_3 <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">/* -- OR ANYTHING ELSE YOU LIKE */</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/* However you choose to select groups, once the group_id matched this part will 
		 * walk up the tree, joining the user to each parent group along the way
		 */</span>
&nbsp;
		<span style="color: #000088;">$parents</span> <span style="color: #339933;">=</span> bp_group_hierarchy_get_parents<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$parents</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$parent_group_id</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			groups_join_group<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$parent_group_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user_id</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If this helps you, or if you have some code to select the groups that matter to YOU, feel free to post in the comments below!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.generalthreat.com/2011/12/extending-groups-hierarchy-join-upstream/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Creating a BuddyPress Group Home Page</title>
		<link>http://www.generalthreat.com/2011/10/creating-a-buddypress-group-home-page/</link>
		<comments>http://www.generalthreat.com/2011/10/creating-a-buddypress-group-home-page/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 03:25:21 +0000</pubDate>
		<dc:creator><![CDATA[David]]></dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[buddypress]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.generalthreat.com/?p=65</guid>
		<description><![CDATA[Do you want to create a &#8220;home page&#8221; for each of your groups, like the one on plugin groups on buddypress.org? Updated (1/07/12): Updated instructions and the sample child theme to fix the activity&#46;&#46;&#46;]]></description>
				<content:encoded><![CDATA[<p>Do you want to create a &#8220;home page&#8221; for each of your groups, like the one on plugin groups on buddypress.org?</p>
<p><ins datetime="2012-01-07T13:42:12+00:00"><strong>Updated (1/07/12)</strong>: Updated instructions and the sample child theme to fix the activity type issue reported by Towfiq.<br />  You can download the updated theme here: <a href="http://www.generalthreat.com/downloads/GroupHomePage-1.1.zip" title="Download BuddyPress Group Home Page - Example Theme">BuddyPress Group Home Page - Example Theme</a></ins></p>
<p><strong>Updated (11/29/11)</strong>: Added a sample child theme implementing these changes.</p>
<p><a href="http://www.generalthreat.com/wordpress/wp-content/uploads/2011/10/BP-Hometab.png"><img src="http://www.generalthreat.com/wordpress/wp-content/uploads/2011/10/BP-Hometab.png" alt="An example of BuddyPress group tabs with Home tab" title="BuddyPress group tabs with Home tab" width="407" height="115" class="size-full aligncenter wp-image-66" /></a><div id="attachment_66" style="width: 417px" class="wp-caption aligncenter"><p class="wp-caption-text">An example of a BuddyPress group with a Home tab</p></div></p>
<p>Here are a few simple steps to make it happen.  Ordinarily, this would just go in a plugin or something.  But this particular change requires edits to the <del datetime="2011-12-02T23:52:18+00:00"><code>group-header.php</code></del> <ins datetime="2011-12-02T23:52:18+00:00"><code>groups/single/home.php</code></ins> file, so it&#8217;s more a theme modification than a plugin.</p>
<p><strong>A note before we get started</strong>: I will assume that you&#8217;re working with a child theme. Child themes are great &mdash; they let you change just the templates or styles you want without wading through a bunch of other files, and they keep your work from being wiped out when a new version of BuddyPress is released. See <a href="http://codex.buddypress.org/theme-development/building-a-buddypress-child-theme/">this BuddyPress Codex page</a> if you want to know more.</p>
<h3>Step One: Create an Activity tab for the activity stream, since we&#8217;re displacing it.</h3>
<p>  To do this, we&#8217;re going to use parts of the Group Extension API to create a new nav item for the group.</p>
<p>In your theme&#8217;s <code>functions.php</code>, add the following:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> add_activity_tab<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$bp</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>bp_is_group<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		bp_core_new_subnav_item<span style="color: #009900;">&#40;</span> 
			<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> 
				<span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Activity'</span><span style="color: #339933;">,</span> 
				<span style="color: #0000ff;">'slug'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'activity'</span><span style="color: #339933;">,</span> 
				<span style="color: #0000ff;">'parent_slug'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$bp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">groups</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current_group</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">slug</span><span style="color: #339933;">,</span> 
				<span style="color: #0000ff;">'parent_url'</span> <span style="color: #339933;">=&gt;</span> bp_get_group_permalink<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$bp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">groups</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current_group</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
				<span style="color: #0000ff;">'position'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">11</span><span style="color: #339933;">,</span> 
				<span style="color: #0000ff;">'item_css_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'nav-activity'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'screen_function'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'user_has_access'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span>
			<span style="color: #009900;">&#41;</span> 
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> bp_is_current_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'activity'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_template_content_header'</span><span style="color: #339933;">,</span> <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'echo &quot;'</span> <span style="color: #339933;">.</span> esc_attr<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Activity'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;;'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_template_title'</span><span style="color: #339933;">,</span> <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'echo &quot;'</span> <span style="color: #339933;">.</span> esc_attr<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Activity'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;;'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_actions'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_activity_tab'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>That adds a tab called &#8216;Activity&#8217; to every group&#8217;s navigation bar, pointing to a page called &#8216;activity&#8217; within the group.  This new activity page is calling the same <code>groups/single/home.php</code> template file as the current home page.  That template actually handles routing for ALL group pages, as we&#8217;ll see in a minute.</p>
<h3>Step Two: Create a template file for your group Home page</h3>
<p>If you&#8217;re going to have a Group home page, you need to control how it&#8217;s displayed.  To do that, you&#8217;ll need a template file in your theme&#8217;s <code>groups/single</code> directory.  It can be called whatever you&#8217;d like, but for this guide, we&#8217;re sticking with <code>front.php</code>.</p>
<p>Create this file and put whatever you want in it.  This template will be in the &#8220;group loop&#8221;, so you can use functions like <code>bp_group_description()</code> to display group info.</p>
<p>Here&#8217;s an example:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;home-page single-group&quot;</span> role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;main&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;?php if<span style="color: #66cc66;">&#40;</span>bp_is_item_admin<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> ?&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;notice info&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Welcome to your group home page!<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
		Click <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?php bp_group_admin_permalink() ?&gt;</span></span>&quot;&gt;Admin<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> above to set the content for this page.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;?php <span style="color: #66cc66;">&#125;</span> ?&gt;</span>
<span style="color: #009900;">&lt;?php bp_group_description<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; ?&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>Up to now, all we&#8217;ve done is create a new Activity tab on the group page that doesn&#8217;t even show the activity stream.  But this last piece will make everything work:</p>
<h3>Step Three: Edit your theme&#8217;s <code>groups/single/home.php</code> template file</h3>
<p>Look for this section in your <code>home.php</code> file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>47
48
49
50
51
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> bp_group_is_visible<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> bp_is_active<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'activity'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span>
		locate_template<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'groups/single/activity.php'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> bp_group_is_visible<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span>
		locate_template<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'groups/single/members.php'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This directs a visitor to either the activity stream or the member list, depending on whether activity has been enabled.  It&#8217;s a catch-all routing section, and it&#8217;s where we&#8217;ll be adding our group home page.</p>
<p>Change the lines above to:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>47
48
49
50
51
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> bp_group_is_visible<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> bp_is_group_activity<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span>
		locate_template<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'groups/single/activity.php'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> bp_group_is_visible<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span>
		locate_template<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'groups/single/front.php'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This enables the Activity tab AND sends requests for the group home page to your new template! Of course, if you used a name other than <code>front.php</code>, you&#8217;ll need to change that line to match the name you chose.</p>
<p><ins datetime="2012-01-07T13:42:12+00:00"></p>
<h3><strong>Update!</strong> Step Four &#8211; Let BuddyPress JS know how to classify your new activity posts</h3>
<p>Now you can make activity updates, but BuddyPress won&#8217;t remember that they came from your group. In order to fix that, we need to relax a check in another file, <code>activity/post-form.php</code>.</p>
<p>Look for this section:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>59
60
61
62
63
64
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> bp_is_group_home<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
		&lt;input type=&quot;hidden&quot; id=&quot;whats-new-post-object&quot; name=&quot;whats-new-post-object&quot; value=&quot;groups&quot; /&gt;
		&lt;input type=&quot;hidden&quot; id=&quot;whats-new-post-in&quot; name=&quot;whats-new-post-in&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bp_group_id<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Without those hidden fields, BuddyPress thinks we&#8217;re just posting a personal status update. So let&#8217;s expand that to cover our new Activity page:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>59
60
61
62
63
64
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> bp_is_group<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
		&lt;input type=&quot;hidden&quot; id=&quot;whats-new-post-object&quot; name=&quot;whats-new-post-object&quot; value=&quot;groups&quot; /&gt;
		&lt;input type=&quot;hidden&quot; id=&quot;whats-new-post-in&quot; name=&quot;whats-new-post-in&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bp_group_id<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Now BuddyPress will tie the update to a group no matter where in the group we post it.</p>
<p></ins></p>
<p>That&#8217;s it!  Check out your new group home page and enjoy the results your BuddyPress hacking chops.  And if you do something really cool with a group Home page, send a link my way!</p>
<p><strong>Updated</strong>: Here&#8217;s a sample child theme to get you started.  It includes all the changes mentioned in this article.<br />
<a href="http://www.generalthreat.com/downloads/GroupHomePage-1.1.zip" title="Download BuddyPress Group Home Page - Example Theme">BuddyPress Group Home Page - Example Theme</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.generalthreat.com/2011/10/creating-a-buddypress-group-home-page/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Unified Search on BuddyPress 1.5</title>
		<link>http://www.generalthreat.com/2011/09/unified-search-on-buddypress-1-5/</link>
		<comments>http://www.generalthreat.com/2011/09/unified-search-on-buddypress-1-5/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 14:04:51 +0000</pubDate>
		<dc:creator><![CDATA[David]]></dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[buddypress]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.generalthreat.com/?p=61</guid>
		<description><![CDATA[Just a quick note to anyone wanting to use the unified search from buddydev.org with BuddyPress 1.5: Replace: remove_action&#40; 'init', 'bp_core_action_search_site', 5 &#41;;//force buddypress to not process the search/redirect add_action&#40; 'init', 'bp_buddydev_search', 10 &#41;;//&#46;&#46;&#46;]]></description>
				<content:encoded><![CDATA[<p>Just a quick note to anyone wanting to use the unified search from buddydev.org with BuddyPress 1.5:</p>
<p>Replace:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">remove_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bp_core_action_search_site'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//force buddypress to not process the search/redirect</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bp_buddydev_search'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">// custom handler for the search</span></pre></td></tr></table></div>

<p>with</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bp_buddydev_search'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// custom handler for the search</span>
remove_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'bp_init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bp_core_action_search_site'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">7</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//force buddypress to not process the search/redirect</span></pre></td></tr></table></div>

<p>And replace:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$bp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">current_component</span> <span style="color: #339933;">==</span> BP_SEARCH_SLUG <span style="color: #009900;">&#41;</span><span style="color: #666666; font-style: italic;">//if this is search page</span></pre></td></tr></table></div>

<p>with</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>bp_is_current_component<span style="color: #009900;">&#40;</span> bp_get_search_slug<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">//if this is search page</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.generalthreat.com/2011/09/unified-search-on-buddypress-1-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BuddyPress Group Organizer</title>
		<link>http://www.generalthreat.com/projects/buddypress-group-organizer/</link>
		<comments>http://www.generalthreat.com/projects/buddypress-group-organizer/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 02:05:43 +0000</pubDate>
		<dc:creator><![CDATA[David]]></dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[buddypress]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.generalthreat.com/?page_id=50</guid>
		<description><![CDATA[About Easily organize your BuddyPress groups with drag and drop simplicity. Also known as the BP Group Organizer, this plugin adds a page to your BuddyPress admin menu letting you easily drag and drop&#46;&#46;&#46;]]></description>
				<content:encoded><![CDATA[<p><div class='postTabs_divs postTabs_curr_div' id='postTabs_0_50'>
<span class='postTabs_titles'><b>About</b></span></p>
<p>Easily organize your <a href="http://buddypress.org">BuddyPress</a> groups with drag and drop simplicity. </p>
<p>Also known as the BP Group Organizer, this plugin adds a page to your BuddyPress admin menu letting you easily drag and drop your groups around, or create new groups just by filling out a single form.  No more paging through the group creation screen over and over again when setting up a new BuddyPress site!</p>
<p></div>

<div class='postTabs_divs' id='postTabs_1_50'>
<span class='postTabs_titles'><b>API for Developers</b></span></p>
<h3>Actions for extending the Organizer</h3>
<h5>bp_group_organizer_display_new_group_options</h5>
<p>Hook this action to display custom options when creating new groups in the Organizer.</p>
<h5>bp_group_organizer_display_group_options</h5>
<p>Hook this action to display custom options when creating new groups in the Organizer.</p>
<p>Parameters:</p>
<ul>
<li><code>$group</code> &#8211; object of group being edited in the Organizer</li>
</ul>
<h5>bp_group_organizer_save_new_group_options</h5>
<p>Hook this action to save custom options when users create new groups in the Organizer.</p>
<p>Parameters:</p>
<ul>
<li><code>$group_id</code> &#8211; ID of newly-created group</li>
</ul>
<h5>bp_group_organizer_save_group_options</h5>
<p>Hook this action to save custom options when users save changes in the Organizer.</p>
<p>Parameters:</p>
<ul>
<li><code>$group</code> &#8211; array of POSTed group options</li>
<li><code>$group_reference</code> &#8211; BP_Groups_Group object of the group being saved</li>
</ul>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.generalthreat.com/projects/buddypress-group-organizer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BuddyPress Group Hierarchy</title>
		<link>http://www.generalthreat.com/projects/buddypress-group-hierarchy/</link>
		<comments>http://www.generalthreat.com/projects/buddypress-group-hierarchy/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 02:26:32 +0000</pubDate>
		<dc:creator><![CDATA[David]]></dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[buddypress]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.generalthreat.com/?page_id=44</guid>
		<description><![CDATA[A plugin for BuddyPress that allows groups to belong to other groups About Features: Unlimited group hierarchy &#8211; nest groups as deeply as you like Per-group control over subgroups &#8211; create a site with&#46;&#46;&#46;]]></description>
				<content:encoded><![CDATA[<p>A plugin for BuddyPress that allows groups to belong to other groups</p>
<p><div class='postTabs_divs postTabs_curr_div' id='postTabs_0_44'>
<span class='postTabs_titles'><b>About</b></span></p>
<p>Features:</p>
<ul>
<li>Unlimited group hierarchy &#8211; nest groups as deeply as you like</li>
<li>Per-group control over subgroups &#8211; create a site with &#8220;sections,&#8221; or keep certain groups free of user-created subgroups</li>
<li>Toggle top-level group creation &#8211; keep as much control over the hierarchy as your needs dictate</li>
<li>Expandable tree display that can replace — or supplement — the main group list</li>
</ul>
<p>Language support for:</p>
<ul>
<li>Spanish translation generously provided by <a href="http://dorsvenabili.com">_DorsVenabili</a></li>
<li>Russian translation generously provided by Roman</li>
<li>Slovak translation generously provided by Branco, (<a href="http://webhostinggeeks.com/blog/">WebHostingGeeks.com</a>)</li>
<li>Danish translation generously provided by Mort3n</li>
<li>French translation generously provided by Mecanographik</li>
<li>Brazilian Portugese translation generously provided by <a href="http://wordpress.org/support/profile/stickfinger">stickFinger</a></li>
<li>Dutch translation generously provided by Zé Vandenhoeck</li>
<li>Italian translation generously provided by Stefano Colarelli</li>
</ul>
<p></div>

<div class='postTabs_divs' id='postTabs_1_44'>
<span class='postTabs_titles'><b>FAQ</b></span></p>
<h5>Does privacy or status propagate from group to subgroup?</h5>
<p>&mdash; No. The plugin creates a hierarchy of group URLs, but does not put restrictions on the subgroup.</p>
<h5>Are group members automatically added to a subgroup?</h5>
<p>&mdash; No. I don&#8217;t know how you will want to use subgroups, so no assumptions have been made.</p>
<h5>If I restrict new groups to member or admins, can a subgroup be made with more lenient restrictions?</h5>
<p>&mdash; Yes. Restrictions affect only the group to which they are applied. Subgroups can themselves be more or less restrictive.</p>
<h5>Do activity stream messages propagate up (from child to parent) or down (from parent to child)?</h5>
<p>No. This function was available (without an interface) but was removed, possibly for use in a forthcoming project.</p>
<p></div>

<div class='postTabs_divs' id='postTabs_2_44'>
<span class='postTabs_titles'><b>API for Developers</b></span></p>
<h2>Filters</h2>
<h5>bp_group_hierarchy_directory_order_sort</h5>
<p>[coming soon]</p>
<h5>bp_group_hierarchy_available_parent_groups</h5>
<p>Filter this array to limit the groups presented as possible parents when creating a new group</p>
<p>Parameters:</p>
<ul>
<li><code>$display_groups</code> &#8211; array of available, active groups</li>
<li><code>$group</code> &#8211; BP_Group_Hierarchy object of the group being created or edited</li>
</ul>
<h5>bp_group_hierarchy_subgroup_permission_options</h5>
<p>Filter this array to add or remove subgroup creation permission options</p>
<p>Parameters:</p>
<ul>
<li><code>$permission_options</code> &#8211; array of available permission options</li>
<li><code>$group</code> &#8211; BP_Group_Hierarchy object of the group being created or edited</li>
</ul>
<h5>bp_group_hierarchy_enforce_subgroup_permission_{your permission name}</h5>
<p>Return TRUE to allow a user to create subgroups; allows custom subgroup creation permission options</p>
<p>Parameters:</p>
<ul>
<li><code>$user_id</code> &#8211; ID of the user seeking to add child group</li>
<li><code>$group_id</code> &#8211; ID of the group user is trying to use as parent</li>
</ul>
<h2>Actions</h2>
<h5>bp_group_hierarchy_route_requests</h5>
<p>Run after BuddyPress is initialized, but before it makes page routing decisions. Can be used for setting cookies and sending params to pages that don&#8217;t otherwise accept them.</p>
<h2>Functions for theme developers</h2>
<p>No parameters are needed for these functions when run in the loop.</p>
<h5>bp_group_hierarchy_full_name()</h5>
<p>Echoes the name of the current group and all its ancestors.<br /> Use <code>bp_group_hierarchy_get_full_name()</code> for more advanced options.</p>
<h5>bp_group_hierarchy_breadcrumbs()</h5>
<p>Echoes a string of links to the current group and all its ancestors.<br /> Use <code>bp_group_hierarchy_get_breadcrumbs()</code> for more advanced options.</p>
<h5>bp_group_hierarchy_get_breadcrumbs( $separator = &#8216; | &#8216;, $group = null )</h5>
<p>Returns a string of links to the current group and all its ancestors.</p>
<h5>bp_group_hierarchy_has_subgroups()</h5>
<p>Returns the number of subgroups, including 0 if the group has none.</p>
<h5>bp_group_hierarchy_get_subgroups()</h5>
<p>Returns an array containing the IDs of the direct descendants of the current group.</p>
<h5>bp_group_hierarchy_has_parent()</h5>
<p>Returns the ID of the parent group, or 0 if the group is at the top level.</p>
<h5>bp_group_hierarchy_get_parents()</h5>
<p>Returns an array containing the IDs of the ancestors of the current group.</p>
<h2>Functions for plugin developers or integrators</h2>
<h5>groups_hierarchy_create_group( array $params )</h2>
<p>A hierarchy-aware wrapper for the BuddyPress <code>groups_create_group</code> function. Can be used the same way, but also accepts a <code>parent_id</code> parameter to specify a new group&#8217;s parent group.</p>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.generalthreat.com/projects/buddypress-group-hierarchy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

 Served from: www.generalthreat.com @ 2026-06-14 16:32:27 by W3 Total Cache -->