<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][5941] trunk: Introduces template function bp_get_groups_current_create_step() to avoid direct calls to the bp global.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/5941">5941</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2012-03-23 18:01:28 +0000 (Fri, 23 Mar 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Introduces template function bp_get_groups_current_create_step() to avoid direct calls to the bp global.
Replaces calls to bp-&gt;groups-&gt;current_create_step with bp_get_groups_current_create_step() throughout BP.
Adds current create step to body classes during group creation process. See <a href="http://buddypress.trac.wordpress.org/ticket/4095">#4095</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpcorebpcoretemplatephp">trunk/bp-core/bp-core-template.php</a></li>
<li><a href="#trunkbpgroupsbpgroupsactionsphp">trunk/bp-groups/bp-groups-actions.php</a></li>
<li><a href="#trunkbpgroupsbpgroupstemplatephp">trunk/bp-groups/bp-groups-template.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpcorebpcoretemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-template.php (5940 => 5941)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-template.php        2012-03-20 21:16:58 UTC (rev 5940)
+++ trunk/bp-core/bp-core-template.php        2012-03-23 18:01:28 UTC (rev 5941)
</span><span class="lines">@@ -1624,8 +1624,10 @@
</span><span class="cx">                 if ( bp_is_group_admin_page() )
</span><span class="cx">                         $bp_classes[] = 'group-admin';
</span><span class="cx"> 
</span><del>-                if ( bp_is_group_create() )
</del><ins>+                if ( bp_is_group_create() ) {
</ins><span class="cx">                         $bp_classes[] = 'group-create';
</span><ins>+                        $bp_classes[] = bp_get_groups_current_create_step();
+                }
</ins><span class="cx"> 
</span><span class="cx">                 if ( bp_is_group_home() )
</span><span class="cx">                         $bp_classes[] = 'group-home';
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupsactionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-actions.php (5940 => 5941)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-actions.php        2012-03-20 21:16:58 UTC (rev 5940)
+++ trunk/bp-groups/bp-groups-actions.php        2012-03-23 18:01:28 UTC (rev 5941)
</span><span class="lines">@@ -34,7 +34,7 @@
</span><span class="cx"> 
</span><span class="cx">         // If no current step is set, reset everything so we can start a fresh group creation
</span><span class="cx">         $bp-&gt;groups-&gt;current_create_step = bp_action_variable( 1 );
</span><del>-        if ( !$bp-&gt;groups-&gt;current_create_step ) {
</del><ins>+        if ( !bp_get_groups_current_create_step() ) {
</ins><span class="cx">                 unset( $bp-&gt;groups-&gt;current_create_step );
</span><span class="cx">                 unset( $bp-&gt;groups-&gt;completed_create_steps );
</span><span class="cx"> 
</span><span class="lines">@@ -46,7 +46,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // If this is a creation step that is not recognized, just redirect them back to the first screen
</span><del>-        if ( !empty( $bp-&gt;groups-&gt;current_create_step ) &amp;&amp; empty( $bp-&gt;groups-&gt;group_creation_steps[$bp-&gt;groups-&gt;current_create_step] ) ) {
</del><ins>+        if ( bp_get_groups_current_create_step() &amp;&amp; empty( $bp-&gt;groups-&gt;group_creation_steps[bp_get_groups_current_create_step()] ) ) {
</ins><span class="cx">                 bp_core_add_message( __('There was an error saving group details. Please try again.', 'buddypress'), 'error' );
</span><span class="cx">                 bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/' );
</span><span class="cx">         }
</span><span class="lines">@@ -65,26 +65,26 @@
</span><span class="cx">         if ( isset( $_POST['save'] ) ) {
</span><span class="cx"> 
</span><span class="cx">                 // Check the nonce
</span><del>-                check_admin_referer( 'groups_create_save_' . $bp-&gt;groups-&gt;current_create_step );
</del><ins>+                check_admin_referer( 'groups_create_save_' . bp_get_groups_current_create_step() );
</ins><span class="cx"> 
</span><del>-                if ( 'group-details' == $bp-&gt;groups-&gt;current_create_step ) {
</del><ins>+                if ( 'group-details' == bp_get_groups_current_create_step() ) {
</ins><span class="cx">                         if ( empty( $_POST['group-name'] ) || empty( $_POST['group-desc'] ) || !strlen( trim( $_POST['group-name'] ) ) || !strlen( trim( $_POST['group-desc'] ) ) ) {
</span><span class="cx">                                 bp_core_add_message( __( 'Please fill in all of the required fields', 'buddypress' ), 'error' );
</span><del>-                                bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . $bp-&gt;groups-&gt;current_create_step . '/' );
</del><ins>+                                bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/' );
</ins><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         $new_group_id = isset( $bp-&gt;groups-&gt;new_group_id ) ? $bp-&gt;groups-&gt;new_group_id : 0;
</span><span class="cx"> 
</span><span class="cx">                         if ( !$bp-&gt;groups-&gt;new_group_id = groups_create_group( array( 'group_id' =&gt; $new_group_id, 'name' =&gt; $_POST['group-name'], 'description' =&gt; $_POST['group-desc'], 'slug' =&gt; groups_check_slug( sanitize_title( esc_attr( $_POST['group-name'] ) ) ), 'date_created' =&gt; bp_core_current_time(), 'status' =&gt; 'public' ) ) ) {
</span><span class="cx">                                 bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
</span><del>-                                bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . $bp-&gt;groups-&gt;current_create_step . '/' );
</del><ins>+                                bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/' );
</ins><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         groups_update_groupmeta( $bp-&gt;groups-&gt;new_group_id, 'total_member_count', 1 );
</span><span class="cx">                         groups_update_groupmeta( $bp-&gt;groups-&gt;new_group_id, 'last_activity', bp_core_current_time() );
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                if ( 'group-settings' == $bp-&gt;groups-&gt;current_create_step ) {
</del><ins>+                if ( 'group-settings' == bp_get_groups_current_create_step() ) {
</ins><span class="cx">                         $group_status = 'public';
</span><span class="cx">                         $group_enable_forum = 1;
</span><span class="cx"> 
</span><span class="lines">@@ -104,7 +104,7 @@
</span><span class="cx"> 
</span><span class="cx">                         if ( !$bp-&gt;groups-&gt;new_group_id = groups_create_group( array( 'group_id' =&gt; $bp-&gt;groups-&gt;new_group_id, 'status' =&gt; $group_status, 'enable_forum' =&gt; $group_enable_forum ) ) ) {
</span><span class="cx">                                 bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
</span><del>-                                bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . $bp-&gt;groups-&gt;current_create_step . '/' );
</del><ins>+                                bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/' );
</ins><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         // Set the invite status
</span><span class="lines">@@ -115,10 +115,10 @@
</span><span class="cx">                         groups_update_groupmeta( $bp-&gt;groups-&gt;new_group_id, 'invite_status', $invite_status );
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                if ( 'group-invites' == $bp-&gt;groups-&gt;current_create_step )
</del><ins>+                if ( 'group-invites' == bp_get_groups_current_create_step() )
</ins><span class="cx">                         groups_send_invites( bp_loggedin_user_id(), $bp-&gt;groups-&gt;new_group_id );
</span><span class="cx"> 
</span><del>-                do_action( 'groups_create_group_step_save_' . $bp-&gt;groups-&gt;current_create_step );
</del><ins>+                do_action( 'groups_create_group_step_save_' . bp_get_groups_current_create_step() );
</ins><span class="cx">                 do_action( 'groups_create_group_step_complete' ); // Mostly for clearing cache on a generic action name
</span><span class="cx"> 
</span><span class="cx">                 /**
</span><span class="lines">@@ -127,8 +127,8 @@
</span><span class="cx">                  * holding the information
</span><span class="cx">                  */
</span><span class="cx">                 $completed_create_steps = isset( $bp-&gt;groups-&gt;completed_create_steps ) ? $bp-&gt;groups-&gt;completed_create_steps : array();
</span><del>-                if ( !in_array( $bp-&gt;groups-&gt;current_create_step, $completed_create_steps ) )
-                        $bp-&gt;groups-&gt;completed_create_steps[] = $bp-&gt;groups-&gt;current_create_step;
</del><ins>+                if ( !in_array( bp_get_groups_current_create_step(), $completed_create_steps ) )
+                        $bp-&gt;groups-&gt;completed_create_steps[] = bp_get_groups_current_create_step();
</ins><span class="cx"> 
</span><span class="cx">                 // Reset cookie info
</span><span class="cx">                 setcookie( 'bp_new_group_id', $bp-&gt;groups-&gt;new_group_id, time()+60*60*24, COOKIEPATH );
</span><span class="lines">@@ -136,7 +136,7 @@
</span><span class="cx"> 
</span><span class="cx">                 // If we have completed all steps and hit done on the final step we
</span><span class="cx">                 // can redirect to the completed group
</span><del>-                if ( count( $bp-&gt;groups-&gt;completed_create_steps ) == count( $bp-&gt;groups-&gt;group_creation_steps ) &amp;&amp; $bp-&gt;groups-&gt;current_create_step == array_pop( array_keys( $bp-&gt;groups-&gt;group_creation_steps ) ) ) {
</del><ins>+                if ( count( $bp-&gt;groups-&gt;completed_create_steps ) == count( $bp-&gt;groups-&gt;group_creation_steps ) &amp;&amp; bp_get_groups_current_create_step() == array_pop( array_keys( $bp-&gt;groups-&gt;group_creation_steps ) ) ) {
</ins><span class="cx">                         unset( $bp-&gt;groups-&gt;current_create_step );
</span><span class="cx">                         unset( $bp-&gt;groups-&gt;completed_create_steps );
</span><span class="cx"> 
</span><span class="lines">@@ -156,7 +156,7 @@
</span><span class="cx">                          * we need to loop the step array and fetch the next step that way.
</span><span class="cx">                          */
</span><span class="cx">                         foreach ( (array) $bp-&gt;groups-&gt;group_creation_steps as $key =&gt; $value ) {
</span><del>-                                if ( $key == $bp-&gt;groups-&gt;current_create_step ) {
</del><ins>+                                if ( $key == bp_get_groups_current_create_step() ) {
</ins><span class="cx">                                         $next = 1;
</span><span class="cx">                                         continue;
</span><span class="cx">                                 }
</span><span class="lines">@@ -172,7 +172,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         // Group avatar is handled separately
</span><del>-        if ( 'group-avatar' == $bp-&gt;groups-&gt;current_create_step &amp;&amp; isset( $_POST['upload'] ) ) {
</del><ins>+        if ( 'group-avatar' == bp_get_groups_current_create_step() &amp;&amp; isset( $_POST['upload'] ) ) {
</ins><span class="cx">                 if ( !empty( $_FILES ) &amp;&amp; isset( $_POST['upload'] ) ) {
</span><span class="cx">                         // Normally we would check a nonce here, but the group save nonce is used instead
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupstemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-template.php (5940 => 5941)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-template.php        2012-03-20 21:16:58 UTC (rev 5940)
+++ trunk/bp-groups/bp-groups-template.php        2012-03-23 18:01:28 UTC (rev 5941)
</span><span class="lines">@@ -1993,7 +1993,7 @@
</span><span class="cx">         if ( !is_array( $bp-&gt;groups-&gt;group_creation_steps ) )
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><del>-        if ( !$bp-&gt;groups-&gt;current_create_step )
</del><ins>+        if ( !bp_get_groups_current_create_step() )
</ins><span class="cx">                 $bp-&gt;groups-&gt;current_create_step = array_shift( array_keys( $bp-&gt;groups-&gt;group_creation_steps ) );
</span><span class="cx"> 
</span><span class="cx">         $counter = 1;
</span><span class="lines">@@ -2001,7 +2001,7 @@
</span><span class="cx">         foreach ( (array) $bp-&gt;groups-&gt;group_creation_steps as $slug =&gt; $step ) {
</span><span class="cx">                 $is_enabled = bp_are_previous_group_creation_steps_complete( $slug ); ?&gt;
</span><span class="cx"> 
</span><del>-                &lt;li&lt;?php if ( $bp-&gt;groups-&gt;current_create_step == $slug ) : ?&gt; class=&quot;current&quot;&lt;?php endif; ?&gt;&gt;&lt;?php if ( $is_enabled ) : ?&gt;&lt;a href=&quot;&lt;?php echo bp_get_root_domain() . '/' . bp_get_groups_root_slug() ?&gt;/create/step/&lt;?php echo $slug ?&gt;/&quot;&gt;&lt;?php else: ?&gt;&lt;span&gt;&lt;?php endif; ?&gt;&lt;?php echo $counter ?&gt;. &lt;?php echo $step['name'] ?&gt;&lt;?php if ( $is_enabled ) : ?&gt;&lt;/a&gt;&lt;?php else: ?&gt;&lt;/span&gt;&lt;?php endif ?&gt;&lt;/li&gt;&lt;?php
</del><ins>+                &lt;li&lt;?php if ( bp_get_groups_current_create_step() == $slug ) : ?&gt; class=&quot;current&quot;&lt;?php endif; ?&gt;&gt;&lt;?php if ( $is_enabled ) : ?&gt;&lt;a href=&quot;&lt;?php echo bp_get_root_domain() . '/' . bp_get_groups_root_slug() ?&gt;/create/step/&lt;?php echo $slug ?&gt;/&quot;&gt;&lt;?php else: ?&gt;&lt;span&gt;&lt;?php endif; ?&gt;&lt;?php echo $counter ?&gt;. &lt;?php echo $step['name'] ?&gt;&lt;?php if ( $is_enabled ) : ?&gt;&lt;/a&gt;&lt;?php else: ?&gt;&lt;/span&gt;&lt;?php endif ?&gt;&lt;/li&gt;&lt;?php
</ins><span class="cx">                 $counter++;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -2013,7 +2013,7 @@
</span><span class="cx"> function bp_group_creation_stage_title() {
</span><span class="cx">         global $bp;
</span><span class="cx"> 
</span><del>-        echo apply_filters( 'bp_group_creation_stage_title', '&lt;span&gt;&amp;mdash; ' . $bp-&gt;groups-&gt;group_creation_steps[$bp-&gt;groups-&gt;current_create_step]['name'] . '&lt;/span&gt;' );
</del><ins>+        echo apply_filters( 'bp_group_creation_stage_title', '&lt;span&gt;&amp;mdash; ' . $bp-&gt;groups-&gt;group_creation_steps[bp_get_groups_current_create_step()]['name'] . '&lt;/span&gt;' );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> function bp_group_creation_form_action() {
</span><span class="lines">@@ -2191,12 +2191,40 @@
</span><span class="cx">                 return apply_filters( 'bp_get_group_creation_previous_link', trailingslashit( bp_get_root_domain() ) . bp_get_groups_root_slug() . '/create/step/' . array_pop( $previous_steps ) );
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+/**
+ * Echoes the current group creation step
+ *
+ * @since 1.6
+ */
+function bp_groups_current_create_step() {
+        echo bp_get_groups_current_create_step();
+}
+        /**
+         * Returns the current group creation step. If none is found, returns an empty string
+         *
+         * @since 1.6
+         *
+         * @uses apply_filters() Filter bp_get_groups_current_create_step to modify
+         * @return str $current_create_step
+         */
+        function bp_get_groups_current_create_step() {
+                global $bp;
+                
+                if ( !empty( $bp-&gt;groups-&gt;current_create_step ) ) {
+                        $current_create_step = $bp-&gt;groups-&gt;current_create_step;
+                } else {
+                        $current_create_step = '';
+                }
+                
+                return apply_filters( 'bp_get_groups_current_create_step', $current_create_step );
+        }
+
</ins><span class="cx"> function bp_is_last_group_creation_step() {
</span><span class="cx">         global $bp;
</span><span class="cx"> 
</span><span class="cx">         $last_step = array_pop( array_keys( $bp-&gt;groups-&gt;group_creation_steps ) );
</span><span class="cx"> 
</span><del>-        if ( $last_step == $bp-&gt;groups-&gt;current_create_step )
</del><ins>+        if ( $last_step == bp_get_groups_current_create_step() )
</ins><span class="cx">                 return true;
</span><span class="cx"> 
</span><span class="cx">         return false;
</span><span class="lines">@@ -2207,7 +2235,7 @@
</span><span class="cx"> 
</span><span class="cx">         $first_step = array_shift( array_keys( $bp-&gt;groups-&gt;group_creation_steps ) );
</span><span class="cx"> 
</span><del>-        if ( $first_step == $bp-&gt;groups-&gt;current_create_step )
</del><ins>+        if ( $first_step == bp_get_groups_current_create_step() )
</ins><span class="cx">                 return true;
</span><span class="cx"> 
</span><span class="cx">         return false;
</span></span></pre>
</div>
</div>

</body>
</html>