<?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>Dan Polant :: Web Interaction Designer &#187; class</title>
	<atom:link href="http://danpolant.com/tag/class/feed/" rel="self" type="application/rss+xml" />
	<link>http://danpolant.com</link>
	<description></description>
	<lastBuildDate>Tue, 01 Nov 2011 03:55:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to: Make sure Buddypress loads first</title>
		<link>http://danpolant.com/how-to-make-sure-buddypress-loads-first/</link>
		<comments>http://danpolant.com/how-to-make-sure-buddypress-loads-first/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 22:18:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[buddypress]]></category>
		<category><![CDATA[class]]></category>

		<guid isPermaLink="false">http://danpolant.com/?p=259</guid>
		<description><![CDATA[Often, it doesn&#8217;t matter whether your Buddypress plugin loads before or after Buddypress. However, if you are using groups API, or extending other Buddypress plugins, your class extensions require that Buddypress be loaded beforehand. Functions hooked into actions that occur before Buddypress loads that use Buddypress functions will cause problems as well if the load [...]]]></description>
			<content:encoded><![CDATA[<p>Often, it doesn&#8217;t matter whether your Buddypress plugin loads before or after Buddypress. However, if you are using groups API, or extending other Buddypress plugins, your class extensions require that Buddypress be loaded beforehand. Functions hooked into actions that occur before Buddypress loads that use Buddypress functions will cause problems as well if the load order is wrong.</p>
<p>WordPress loads plugins in alphabetical order. So the simplest (and most janky) solution is to name your plugin something that comes after &#8220;buddypress&#8221; in the alphabet. But there are better methods that you should use instead.</p>
<h4>For versions before BP 1.2</h4>
<p>The goal here is to check whether Buddypress has been loaded at the point when your plugin loads, and if it has not, load it manually. The manual load will prevent the normal load from happening later, so you won&#8217;t get double what you need.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co1">//hack required to load BP first</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> bpgc_load_buddypress<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//buddypress is loaded</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span> <a href="http://www.php.net/function_exists"><span class="kw3">function_exists</span></a><span class="br0">&#40;</span> <span class="st0">&#8216;bp_core_setup_globals&#8217;</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Get the list of active sitewide plugins </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$active_sitewide_plugins</span> = maybe_unserialize<span class="br0">&#40;</span> get_site_option<span class="br0">&#40;</span> <span class="st0">&#8216;active_sitewide_plugins&#8217;</span> <span class="br0">&#41;</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$bp_activated</span> = <span class="re0">$active_sitewide_plugins</span><span class="br0">&#91;</span><span class="st0">&#8216;buddypress/bp-loader.php&#8217;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//bp is not activated</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span> !<span class="re0">$bp_activated</span> <span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//bp is activated but not yet loaded</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span> <span class="re0">$bp_activated</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">true</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">false</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//load bp if its not activated</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw1">if</span> <span class="br0">&#40;</span> bpgc_load_buddypress<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">require_once</span><span class="br0">&#40;</span> WP_PLUGIN_DIR . <span class="st0">&#8216;/buddypress/bp-loader.php&#8217;</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<h4>If you are using BP 1.2+</h4>
<p>Fortunately, they made this much easier to do in BP 1.2. For my plugin, all I needed to do was:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> bpgc_bp_loaded<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">require</span> <span class="br0">&#40;</span> WP_PLUGIN_DIR . <span class="st0">&quot;/BP-Group-Control/bpgc-classes.php&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">add_action<span class="br0">&#40;</span><span class="st0">&#8216;bp_init&#8217;</span>, <span class="st0">&#8216;bpgc_bp_loaded&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>&#8230; in order to load my classes only once Buddypress has finished loading. Probably the safest way to ensure that your plugin completely loads after Buddypress is to create a loader.php file that contains this action and loads all of your other files. </p>
]]></content:encoded>
			<wfw:commentRss>http://danpolant.com/how-to-make-sure-buddypress-loads-first/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to: create groups in Buddypress with PHP</title>
		<link>http://danpolant.com/how-to-create-groups-in-buddypress-with-php/</link>
		<comments>http://danpolant.com/how-to-create-groups-in-buddypress-with-php/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 03:26:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[buddypress]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[extends]]></category>
		<category><![CDATA[group]]></category>

		<guid isPermaLink="false">http://danpolant.com/?p=40</guid>
		<description><![CDATA[Ever want to make a buddypress function that creates a group? Here&#8217;s how:
You can do this without writing any SQL. Buddypress uses a class called BP_Groups_Group to handle its group creation.  BP_Groups_Group is defined in /groups/bp-groups-classes if you want to see it.  I highly recommend taking a look at this, as you will [...]]]></description>
			<content:encoded><![CDATA[<p>Ever want to make a buddypress function that creates a group? Here&#8217;s how:</p>
<p>You can do this without writing any SQL. Buddypress uses a class called <code>BP_Groups_Group</code> to handle its group creation.  BP_Groups_Group is defined in /groups/bp-groups-classes if you want to see it.  I highly recommend taking a look at this, as you will discover other class methods that do other group-related things.</p>
<p>Say you want a plugin that upon activation creates a certain group. First add an action to the activation hook:</p>
<p><code>register_activation_hook(__file__, 'create_a_group');</code></p>
<p>Next, we need to call a function that instantiates the class BP_Groups_Group. Lets do this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> create_a_group<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$new_group</span> = BP_Groups_Group;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">creator_id</span> = <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">name</span> = <span class="st0">&#8216;test&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">slug</span> = <span class="st0">&#8216;test&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">description</span> = <span class="st0">&#8216;nothing&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">news</span> = <span class="st0">&#8216;whatever&#8217;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">status</span> = <span class="st0">&#8216;public&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">is_invitation_only</span> = <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">enable_wire</span> = <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">enable_forum</span> = <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">enable_photos</span> = <span class="nu0">1</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">photos_admin_only</span> = <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">date_created</span> = current_time<span class="br0">&#40;</span><span class="st0">&#8216;mysql&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">total_member_count</span> = <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">avatar_thumb</span> = <span class="st0">&#8216;some kind of path&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">avatar_full</span> = <span class="st0">&#8216;some kind of path&#8217;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$new_group</span> -&gt; <span class="me1">save</span><span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="co1">//this does the database insert</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>The whole point of doing it this way is so you that can use the <code>save()</code> method. Check this function out on line 90 of bp-groups-classes.php. It does all the SQL for you, and to reproduce this would be very tedious.</p>
<p><code>create_a_group()</code> will dump a row into wp_bp_groups. But if you go to your site and look at the groups directory, it won&#8217;t show up. Why? Because Buddypress checks for certain kinds of metadata before it displays a group in the main directory. So add this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> create_a_group<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$new_group</span> = <span class="kw2">new</span> BP_Groups_Group;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">creator_id</span> = <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">name</span> = <span class="st0">&#8216;test&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">slug</span> = <span class="st0">&#8216;test&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">description</span> = <span class="st0">&#8216;nothing&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">news</span> = <span class="st0">&#8216;whatever&#8217;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">status</span> = <span class="st0">&#8216;public&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">is_invitation_only</span> = <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">enable_wire</span> = <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">enable_forum</span> = <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">enable_photos</span> = <span class="nu0">1</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">photos_admin_only</span> = <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">date_created</span> = current_time<span class="br0">&#40;</span><span class="st0">&#8216;mysql&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">total_member_count</span> = <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">avatar_thumb</span> = <span class="st0">&#8216;some kind of path&#8217;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_group</span>-&gt;<span class="me1">avatar_full</span> = <span class="st0">&#8216;some kind of path&#8217;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$new_group</span> -&gt; <span class="me1">save</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; groups_update_groupmeta<span class="br0">&#40;</span> <span class="re0">$id</span>, <span class="st0">&#8216;total_member_count&#8217;</span>, <span class="nu0">1</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; groups_update_groupmeta<span class="br0">&#40;</span> <span class="re0">$id</span>, <span class="st0">&#8216;last_activity&#8217;</span>, <a href="http://www.php.net/time"><span class="kw3">time</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; groups_update_groupmeta<span class="br0">&#40;</span> <span class="re0">$id</span>, <span class="st0">&#8216;theme&#8217;</span>, <span class="st0">&#8216;buddypress&#8217;</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; groups_update_groupmeta<span class="br0">&#40;</span> <span class="re0">$id</span>, <span class="st0">&#8216;stylesheet&#8217;</span>, <span class="st0">&#8216;buddypress&#8217;</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>This is how Buddypress updates group metadata. Your new group should show up.</p>
<p>It is worth mentioning that the other database operations in Buddypress work exactly the same way: first you instantiate a database class, populate the object with data, then you call save().  But look at the code, there are tons of other methods for these kinds of classes that will help you do things without writing redundant SQL.</p>
<p>Basically, what you are doing here mirrors what Buddypress does in step one (case 1) of <code>groups_create_group()</code> on line 1451 of bp-groups.php.  The reason you can&#8217;t just use this function is that you need your own data, not the canned query that comes with the plain old <code>populate()</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://danpolant.com/how-to-create-groups-in-buddypress-with-php/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

