<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[BuddyPress] [3488] trunk:
Allow any component to be set to display on the front page.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>3488</dd>
<dt>Author</dt> <dd>djpaul</dd>
<dt>Date</dt> <dd>2010-11-27 22:21:26 +0000 (Sat, 27 Nov 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Allow any component to be set to display on the front page. Fixes #2743.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpcorebpcorecatchuriphp">trunk/bp-core/bp-core-catchuri.php</a></li>
<li><a href="#trunkbpcorebpcoresignupphp">trunk/bp-core/bp-core-signup.php</a></li>
<li><a href="#trunkbpcorebpcoretemplatetagsphp">trunk/bp-core/bp-core-templatetags.php</a></li>
<li><a href="#trunkbpthemesbpdefaultfunctionsphp">trunk/bp-themes/bp-default/functions.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpcorebpcorecatchuriphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-catchuri.php (3487 => 3488)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-catchuri.php        2010-11-27 14:02:42 UTC (rev 3487)
+++ trunk/bp-core/bp-core-catchuri.php        2010-11-27 22:21:26 UTC (rev 3488)
</span><span class="lines">@@ -104,9 +104,16 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         // Reset the keys by merging with an empty array
</span><del>-        $bp_uri                                 = array_merge( array(), $bp_uri );
-        $bp_unfiltered_uri         = $bp_uri;
</del><ins>+        $bp_uri = array_merge( array(), $bp_uri );
+        $bp_unfiltered_uri = $bp_uri;
</ins><span class="cx">
</span><ins>+        // If a component is set to the front page, force its name into $bp_uri so that $current_component is populated
+        if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) && empty( $bp_uri ) ) {
+                $post = get_post( get_option( 'page_on_front' ) );
+                if ( !empty( $post ) )
+                        $bp_uri[0] = $post->post_name;
+        }
+
</ins><span class="cx">         // Find a match within registered BuddyPress controlled WP pages (check members first)
</span><span class="cx">         foreach ( (array)$bp_pages as $page_key => $bp_page ) {
</span><span class="cx">                 if ( in_array( $bp_page->name, (array)$bp_uri ) ) {
</span><span class="lines">@@ -214,45 +221,23 @@
</span><span class="cx"> *
</span><span class="cx"> * @package BuddyPress Core
</span><span class="cx"> * @param $username str Username to check.
</span><del>- * @global $wpdb WordPress DB access object.
- * @return false on no match
- * @return int the user ID of the matched user.
</del><ins>+ * @return false|int The user ID of the matched user, or false.
</ins><span class="cx"> */
</span><span class="cx"> function bp_core_load_template( $templates ) {
</span><del>-        global $post, $bp, $wpdb, $wp_query, $bp_unfiltered_uri, $bp_unfiltered_uri_offset;
</del><ins>+        global $bp, $wpdb, $wp_query, $bp_unfiltered_uri, $bp_unfiltered_uri_offset;
</ins><span class="cx">
</span><span class="cx">         // Determine if the root object WP page exists for this request (TODO: is there an API function for this?
</span><del>-        if ( !$page_exists = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s", $bp_unfiltered_uri[$bp_unfiltered_uri_offset] ) ) )
-                return false;
</del><ins>+        if ( !empty( $bp_unfiltered_uri[$bp_unfiltered_uri_offset] ) )
+                if ( !$page_exists = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s", $bp_unfiltered_uri[$bp_unfiltered_uri_offset] ) ) )
+                        return false;
</ins><span class="cx">
</span><del>-        // Set the root object as the current wp_query-ied item
-        $object_id = 0;
-        foreach ( (array)$bp->pages as $page ) {
-                if ( isset( $bp_unfiltered_uri[$bp_unfiltered_uri_offset] ) && $page->name == $bp_unfiltered_uri[$bp_unfiltered_uri_offset] )
-                        $object_id = $page->id;
-        }
-
-        // Make the queried/post object an actual valid page
-        if ( !empty( $object_id ) ) {
-                $wp_query->queried_object = &get_post( $object_id );
-                $wp_query->queried_object_id = $object_id;
-
-                $post = $wp_query->queried_object;
-        }
-
</del><span class="cx">         // Fetch each template and add the php suffix
</span><span class="cx">         foreach ( (array)$templates as $template )
</span><span class="cx">                 $filtered_templates[] = $template . '.php';
</span><span class="cx">
</span><span class="cx">         // Filter the template locations so that plugins can alter where they are located
</span><del>-        if ( $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates ) ) {
-                // Template was located, lets set this as a valid page and not a 404.
-                 status_header( 200 );
-                $wp_query->is_page = true;
-                $wp_query->is_404 = false;
-
</del><ins>+        if ( $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates ) )
</ins><span class="cx">                 load_template( apply_filters( 'bp_load_template', $located_template ) );
</span><del>-        }
</del><span class="cx">
</span><span class="cx">         // Kill any other output after this.
</span><span class="cx">         die;
</span></span></pre></div>
<a id="trunkbpcorebpcoresignupphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-signup.php (3487 => 3488)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-signup.php        2010-11-27 14:02:42 UTC (rev 3487)
+++ trunk/bp-core/bp-core-signup.php        2010-11-27 22:21:26 UTC (rev 3488)
</span><span class="lines">@@ -15,6 +15,9 @@
</span><span class="cx">                 return false;
</span><span class="cx">
</span><span class="cx">         $bp->is_directory = false;
</span><ins>+        
+        if ( bp_is_component_front_page( 'register' ) && ( is_user_logged_in() || !bp_get_signup_allowed() ) )
+                bp_core_redirect( $bp->root_domain . '/' . $bp->members->slug );
</ins><span class="cx">
</span><span class="cx">         /* If the user is logged in, redirect away from here */
</span><span class="cx">         if ( is_user_logged_in() )
</span></span></pre></div>
<a id="trunkbpcorebpcoretemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-templatetags.php (3487 => 3488)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-templatetags.php        2010-11-27 14:02:42 UTC (rev 3487)
+++ trunk/bp-core/bp-core-templatetags.php        2010-11-27 22:21:26 UTC (rev 3488)
</span><span class="lines">@@ -1517,6 +1517,32 @@
</span><span class="cx">
</span><span class="cx"> /* Template is_() functions to determine the current page */
</span><span class="cx">
</span><ins>+/**
+ * Checks if the site's front page is set to the specified BuddyPress component page in wp-admin's Settings > Reading screen.
+ *
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
+ * @global $current_blog WordPress global containing information and settings for the current blog being viewed.
+ * @param string $component Optional; name of the component to check for. If not specified, uses $bp->current_component.
+ * @return bool True if the specified component is set to be the site's front page.
+ * @since 1.3
+ */
+function bp_is_component_front_page( $component='' ) {
+        global $bp, $current_blog;
+
+        if ( !$component && !empty( $bp->current_component ) )
+                $component = $bp->current_component;
+
+        if ( is_main_site() )
+                $path = bp_core_get_site_path();
+        else
+                $path = $current_blog->path;
+                
+        if ( 'page' != get_option( 'show_on_front' ) || !$component || empty( $bp->pages->{$component} ) || $_SERVER['REQUEST_URI'] != $path )
+                return false;
+
+        return apply_filters( 'bp_is_component_front_page', ( $bp->pages->{$component}->id == get_option( 'page_on_front' ) ), $component );
+}
+
</ins><span class="cx"> function bp_is_blog_page() {
</span><span class="cx">         global $bp, $is_member_page, $wp_query;
</span><span class="cx">
</span><span class="lines">@@ -1541,24 +1567,28 @@
</span><span class="cx"> }
</span><span class="cx"> function bp_is_home() { return bp_is_my_profile(); }
</span><span class="cx">
</span><ins>+/**
+ * Is the user on the front page of the site?
+ *
+ * @deprecated 1.3
+ * @deprecated Use is_front_page()
+ * @return bool
+ */
</ins><span class="cx"> function bp_is_front_page() {
</span><del>-        if ( 'posts' == get_option('show_on_front') && is_home() )
-                return true;
-        else if ( bp_is_activity_front_page() )
-                return true;
-        else
-                return is_front_page();
</del><ins>+        _deprecated_function( __FUNCTION__, '1.3', "is_front_page()" );
+        return is_front_page();
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+/**
+ * Is the front page of the site set to the Activity component?
+ *
+ * @deprecated 1.3
+ * @deprecated Use bp_is_component_front_page( 'activity' )
+ * @return bool
+ */
</ins><span class="cx"> function bp_is_activity_front_page() {
</span><del>-        global $current_blog;
-
-        if ( is_main_site() )
-                $path = bp_core_get_site_path();
-        else
-                $path = $current_blog->path;
-
-        return ( 'page' == get_option('show_on_front') && 'activity' == get_option('page_on_front') && $_SERVER['REQUEST_URI'] == $path );
</del><ins>+        _deprecated_function( __FUNCTION__, '1.3', "bp_is_component_front_page( 'activity' )" );
+        return bp_is_component_front_page( 'activity' );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function bp_is_directory() {
</span><span class="lines">@@ -1979,7 +2009,7 @@
</span><span class="cx">
</span><span class="cx">                 $bp_classes = array();
</span><span class="cx">
</span><del>-                if ( bp_is_front_page() )
</del><ins>+                if ( is_front_page() )
</ins><span class="cx">                         $bp_classes[] = 'home-page';
</span><span class="cx">
</span><span class="cx">                 if ( bp_is_directory() )
</span><span class="lines">@@ -1988,19 +2018,19 @@
</span><span class="cx">                 if ( bp_is_user_profile() && !bp_is_blog_page() )
</span><span class="cx">                         $bp_classes[] = 'profile';
</span><span class="cx">
</span><del>-                if ( bp_is_activity_component() && !bp_is_blog_page() || ( bp_is_activity_front_page() && bp_is_front_page() ) )
</del><ins>+                if ( bp_is_activity_component() && !bp_is_blog_page() )
</ins><span class="cx">                         $bp_classes[] = 'activity';
</span><span class="cx">
</span><del>-                if ( bp_is_blogs_component() && !bp_is_blog_page() )
</del><ins>+                if ( bp_is_blogs_component() && !bp_is_blog_page() )
</ins><span class="cx">                         $bp_classes[] = 'blogs';
</span><span class="cx">
</span><span class="cx">                 if ( bp_is_messages_component() && !bp_is_blog_page() )
</span><span class="cx">                         $bp_classes[] = 'messages';
</span><span class="cx">
</span><del>-                if ( bp_is_friends_component() && !bp_is_blog_page() )
</del><ins>+                if ( bp_is_friends_component() && !bp_is_blog_page() )
</ins><span class="cx">                         $bp_classes[] = 'friends';
</span><span class="cx">
</span><del>-                if ( bp_is_groups_component() && !bp_is_blog_page() )
</del><ins>+                if ( bp_is_groups_component() && !bp_is_blog_page() )
</ins><span class="cx">                         $bp_classes[] = 'groups';
</span><span class="cx">
</span><span class="cx">                 if ( bp_is_settings_component() && !bp_is_blog_page() )
</span></span></pre></div>
<a id="trunkbpthemesbpdefaultfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/functions.php (3487 => 3488)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/functions.php        2010-11-27 14:02:42 UTC (rev 3487)
+++ trunk/bp-themes/bp-default/functions.php        2010-11-27 22:21:26 UTC (rev 3488)
</span><span class="lines">@@ -154,76 +154,60 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Filter the dropdown for selecting the page to show on front to include "Activity Stream"
</del><ins>+ * In BuddyPress 1.2.x, this function filtered the dropdown on the Settings > Reading screen for selecting
+ * the page to show on front to include "Activity Stream."
+ * As of 1.3.x, it is no longer required.
</ins><span class="cx"> *
</span><ins>+ * @deprecated 1.3
+ * @deprecated No longer required.
</ins><span class="cx"> * @param string $page_html A list of pages as a dropdown (select list)
</span><del>- * @see wp_dropdown_pages()
</del><span class="cx"> * @return string
</span><del>- * @package BuddyPress Theme
</del><ins>+ * @see wp_dropdown_pages()
</ins><span class="cx"> * @since 1.2
</span><span class="cx"> */
</span><span class="cx"> function bp_dtheme_wp_pages_filter( $page_html ) {
</span><del>-        if ( !bp_is_active( 'activity' ) )
-                return $page_html;
-
-        if ( 'page_on_front' != substr( $page_html, 14, 13 ) )
-                return $page_html;
-
-        $selected = false;
-        $page_html = str_replace( '</select>', '', $page_html );
-
-        if ( bp_dtheme_page_on_front() == 'activity' )
-                $selected = ' selected="selected"';
-
-        $page_html .= '<option class="level-0" value="activity"' . $selected . '>' . __( 'Activity Stream', 'buddypress' ) . '</option></select>';
</del><ins>+        _deprecated_function( __FUNCTION__, '1.3', "No longer required." );
</ins><span class="cx">         return $page_html;
</span><span class="cx"> }
</span><del>-add_filter( 'wp_dropdown_pages', 'bp_dtheme_wp_pages_filter' );
</del><span class="cx">
</span><span class="cx"> /**
</span><del>- * Hijack the saving of page on front setting to save the activity stream setting
</del><ins>+ * In BuddyPress 1.2.x, this function hijacked the saving of page on front setting to save the activity stream setting.
+ * As of 1.3.x, it is no longer required.
</ins><span class="cx"> *
</span><ins>+ * @deprecated 1.3
+ * @deprecated No longer required.
</ins><span class="cx"> * @param $string $oldvalue Previous value of get_option( 'page_on_front' )
</span><span class="cx"> * @param $string $oldvalue New value of get_option( 'page_on_front' )
</span><span class="cx"> * @return string
</span><del>- * @package BuddyPress Theme
</del><span class="cx"> * @since 1.2
</span><span class="cx"> */
</span><span class="cx"> function bp_dtheme_page_on_front_update( $oldvalue, $newvalue ) {
</span><ins>+        _deprecated_function( __FUNCTION__, '1.3', "No longer required." );
</ins><span class="cx">         if ( !is_admin() || !is_super_admin() )
</span><span class="cx">                 return false;
</span><span class="cx">
</span><del>-        if ( 'activity' == $_POST['page_on_front'] )
-                return 'activity';
-        else
-                return $oldvalue;
</del><ins>+        return $oldvalue;
</ins><span class="cx"> }
</span><del>-add_action( 'pre_update_option_page_on_front', 'bp_dtheme_page_on_front_update', 10, 2 );
</del><span class="cx">
</span><span class="cx"> /**
</span><del>- * Load the activity stream template if settings allow
</del><ins>+ * In BuddyPress 1.2.x, this function loaded the activity stream template if the front page display settings allow.
+ * As of 1.3.x, it is no longer required.
</ins><span class="cx"> *
</span><ins>+ * @deprecated 1.3
+ * @deprecated No longer required.
</ins><span class="cx"> * @param string $template Absolute path to the page template
</span><span class="cx"> * @return string
</span><del>- * @global WP_Query $wp_query WordPress query object
- * @package BuddyPress Theme
</del><span class="cx"> * @since 1.2
</span><span class="cx"> */
</span><span class="cx"> function bp_dtheme_page_on_front_template( $template ) {
</span><del>-        global $wp_query;
-
-        if ( empty( $wp_query->post->ID ) )
-                return locate_template( array( 'activity/index.php' ), false );
-        else
-                return $template;
</del><ins>+        _deprecated_function( __FUNCTION__, '1.3', "No longer required." );
+        return $template;
</ins><span class="cx"> }
</span><del>-add_filter( 'page_template', 'bp_dtheme_page_on_front_template' );
</del><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Return the ID of a page set as the home page.
</span><span class="cx"> *
</span><span class="cx"> * @return false|int ID of page set as the home page
</span><del>- * @package BuddyPress Theme
</del><span class="cx"> * @since 1.2
</span><span class="cx"> */
</span><span class="cx"> function bp_dtheme_page_on_front() {
</span><span class="lines">@@ -234,39 +218,31 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Force the page ID as a string to stop the get_posts query from kicking up a fuss.
</del><ins>+ * In BuddyPress 1.2.x, this forced the page ID as a string to stop the get_posts query from kicking up a fuss.
+ * As of 1.3.x, it is no longer required.
</ins><span class="cx"> *
</span><del>- * @global WP_Query $wp_query WordPress query object
- * @package BuddyPress Theme
</del><ins>+ * @deprecated 1.3
+ * @deprecated No longer required.
</ins><span class="cx"> * @since 1.2
</span><span class="cx"> */
</span><span class="cx"> function bp_dtheme_fix_get_posts_on_activity_front() {
</span><del>-        global $wp_query;
-
-        if ( !empty($wp_query->query_vars['page_id']) && 'activity' == $wp_query->query_vars['page_id'] )
-                $wp_query->query_vars['page_id'] = '"activity"';
</del><ins>+        _deprecated_function( __FUNCTION__, '1.3', "No longer required." );
</ins><span class="cx"> }
</span><del>-add_action( 'pre_get_posts', 'bp_dtheme_fix_get_posts_on_activity_front' );
</del><span class="cx">
</span><span class="cx"> /**
</span><del>- * WP 3.0 requires there to be a non-null post in the posts array
</del><ins>+ * In BuddyPress 1.3, this was used as part of the code that set the activity stream to be on the front page.
+ * As of 1.3.x, it is no longer required.
</ins><span class="cx"> *
</span><ins>+ * @deprecated 1.3
+ * @deprecated No longer required.
</ins><span class="cx"> * @param array $posts Posts as retrieved by WP_Query
</span><del>- * @global WP_Query $wp_query WordPress query object
</del><span class="cx"> * @return array
</span><del>- * @package BuddyPress Theme
</del><span class="cx"> * @since 1.2.5
</span><span class="cx"> */
</span><span class="cx"> function bp_dtheme_fix_the_posts_on_activity_front( $posts ) {
</span><del>-        global $wp_query;
-
-        // NOTE: the double quotes around '"activity"' are thanks to our previous function bp_dtheme_fix_get_posts_on_activity_front()
-        if ( empty( $posts ) && !empty( $wp_query->query_vars['page_id'] ) && '"activity"' == $wp_query->query_vars['page_id'] )
-                $posts = array( (object) array( 'ID' => 'activity' ) );
-
</del><ins>+        _deprecated_function( __FUNCTION__, '1.3', "No longer required." );
</ins><span class="cx">         return $posts;
</span><span class="cx"> }
</span><del>-add_filter( 'the_posts', 'bp_dtheme_fix_the_posts_on_activity_front' );
</del><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Add secondary avatar image to this activity stream's record, if supported
</span><span class="lines">@@ -405,7 +381,7 @@
</span><span class="cx"> function bp_dtheme_main_nav( $args ) {
</span><span class="cx"> ?>
</span><span class="cx">         <ul id="nav">
</span><del>-                <li<?php if ( bp_is_front_page() ) : ?> class="selected"<?php endif; ?>>
</del><ins>+                <li<?php if ( is_front_page() ) : ?> class="selected"<?php endif; ?>>
</ins><span class="cx">                         <a href="<?php echo site_url() ?>" title="<?php _e( 'Home', 'buddypress' ) ?>"><?php _e( 'Home', 'buddypress' ) ?></a>
</span><span class="cx">                 </li>
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>