<!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][4183] trunk: Adds warning notices to Dashboard when required BP component directory pages are missing.</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>4183</dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2011-04-09 17:32:00 +0000 (Sat, 09 Apr 2011)</dd>
</dl>
<h3>Log Message</h3>
<pre>Adds warning notices to Dashboard when required BP component directory pages are missing. Fixes #3026. Adds warning notices to Dashboard when bp-pages are present but the corresponding component is deactivated. Fixes #3025. Removes root_slug declaration from components that should not have top-level directories.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpcoreadminbpcoreadminphp">trunk/bp-core/admin/bp-core-admin.php</a></li>
<li><a href="#trunkbpcorebpcorefunctionsphp">trunk/bp-core/bp-core-functions.php</a></li>
<li><a href="#trunkbpfriendsbpfriendsloaderphp">trunk/bp-friends/bp-friends-loader.php</a></li>
<li><a href="#trunkbpmessagesbpmessagesloaderphp">trunk/bp-messages/bp-messages-loader.php</a></li>
<li><a href="#trunkbpsettingsbpsettingsloaderphp">trunk/bp-settings/bp-settings-loader.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpcoreadminbpcoreadminphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/admin/bp-core-admin.php (4182 => 4183)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/admin/bp-core-admin.php        2011-04-09 14:30:32 UTC (rev 4182)
+++ trunk/bp-core/admin/bp-core-admin.php        2011-04-09 17:32:00 UTC (rev 4183)
</span><span class="lines">@@ -358,32 +358,30 @@
</span><span class="cx">         
</span><span class="cx">         <h3><?php _e( 'Directory Pages', 'buddypress' ); ?></h3>
</span><span class="cx">         
</span><del>-        <p><?php _e( 'Choose a WordPress Page to associate with each BuddyPress component directory. Setting to "None" will render that page inaccessible.', 'buddypress' ); ?></p>
</del><ins>+        <p><?php _e( 'Choose a WordPress Page to associate with each BuddyPress component directory. Deactivated components should be set to "None".', 'buddypress' ); ?></p>
</ins><span class="cx">
</span><span class="cx">         <table class="form-table">
</span><span class="cx">                 <tbody>
</span><span class="cx">
</span><span class="cx">                         <?php foreach ( $directory_pages as $name => $label ) : ?>
</span><ins>+                                <?php $disabled = !bp_is_active( $name ) ? ' disabled="disabled"' : ''; ?>
+                                
+                                <tr valign="top">
+                                        <th scope="row">
+                                                <label for="bp_pages[<?php echo esc_attr( $name ) ?>]"><?php echo esc_html( $label ) ?><?php if ( !bp_is_active( $name ) ) : ?> <span class="description">(deactivated)</span><?php endif ?></label>
+                                        </th>
</ins><span class="cx">
</span><del>-                                <?php if ( bp_is_active( $name ) ) : ?>
</del><ins>+                                        <td>
+                                                <?php echo wp_dropdown_pages( array(
+                                                        'name' => 'bp_pages[' . esc_attr( $name ) . ']',
+                                                        'echo' => false,
+                                                        'show_option_none' => __( '- None -', 'buddypress' ),
+                                                        'selected' => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
+                                                ) ) ?>
+                                        </td>
+                                </tr>
</ins><span class="cx">
</span><del>-                                        <tr valign="top">
-                                                <th scope="row">
-                                                        <label for="bp_pages[<?php echo esc_attr( $name ) ?>]"><?php echo esc_html( $label ) ?></label>
-                                                </th>
</del><span class="cx">
</span><del>-                                                <td>
-                                                        <?php echo wp_dropdown_pages( array(
-                                                                'name' => 'bp_pages[' . esc_attr( $name ) . ']',
-                                                                'echo' => false,
-                                                                'show_option_none' => __( '- None -', 'buddypress' ),
-                                                                'selected' => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
-                                                        ) ) ?>
-                                                </td>
-                                        </tr>
-
-                                <?php endif; ?>
-
</del><span class="cx">                         <?php endforeach ?>
</span><span class="cx">
</span><span class="cx">                         <?php do_action( 'bp_active_external_directories' ); ?>
</span></span></pre></div>
<a id="trunkbpcorebpcorefunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-functions.php (4182 => 4183)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-functions.php        2011-04-09 14:30:32 UTC (rev 4182)
+++ trunk/bp-core/bp-core-functions.php        2011-04-09 17:32:00 UTC (rev 4183)
</span><span class="lines">@@ -29,7 +29,13 @@
</span><span class="cx"> /**
</span><span class="cx"> * Stores BP pages in the meta table, depending on setup
</span><span class="cx"> *
</span><ins>+ * bp-pages data is stored in the options table of the root blog, except when BP_ENABLE_MULTIBLOG
+ * is turned on.
+ *
</ins><span class="cx"> * @package BuddyPress Core
</span><ins>+ * @since 1.3
+ *
+ * @param array $page_ids The IDs of the WP pages corresponding to BP component directories
</ins><span class="cx"> */
</span><span class="cx"> function bp_core_update_page_meta( $page_ids ) {
</span><span class="cx">         if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )
</span><span class="lines">@@ -38,6 +44,14 @@
</span><span class="cx">                 update_option( 'bp-pages', $page_ids );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+/**
+ * Get bp-pages names and slugs
+ *
+ * @package BuddyPress Core
+ * @since 1.3
+ *
+ * @return obj $pages Page names, IDs, and slugs
+ */
</ins><span class="cx"> function bp_core_get_page_names() {
</span><span class="cx">         global $wpdb, $bp;
</span><span class="cx">
</span><span class="lines">@@ -49,7 +63,7 @@
</span><span class="cx">
</span><span class="cx">                 $posts_table_name = is_multisite() && !defined( 'BP_ENABLE_MULTIBLOG' ) ? $wpdb->get_blog_prefix( BP_ROOT_BLOG ) . 'posts' : $wpdb->posts;
</span><span class="cx">                 $page_ids_sql = implode( ',', (array)$page_ids );
</span><del>-                $page_names = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM {$posts_table_name} WHERE ID IN ({$page_ids_sql}) " ) );
</del><ins>+                $page_names = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM {$posts_table_name} WHERE ID IN ({$page_ids_sql}) AND post_status = 'publish' " ) );
</ins><span class="cx">
</span><span class="cx">                 foreach ( (array)$page_ids as $key => $page_id ) {
</span><span class="cx">                         foreach ( (array)$page_names as $page_name ) {
</span><span class="lines">@@ -221,22 +235,42 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * When BuddyPress is activated we must make sure that mod_rewrite is enabled.
- * We must also make sure a BuddyPress compatible theme is enabled. This function
- * will show helpful messages to the administrator.
</del><ins>+ * Verify that some BP prerequisites are set up properly, and notify the admin if not
</ins><span class="cx"> *
</span><ins>+ * On every Dashboard page, this function checks the following:
+ * - that pretty permalinks are enabled
+ * - that a BP-compatible theme is activated
+ * - that every BP component that needs a WP page for a directory has one
+ * - that no directory WP pages are published for deactivated components
+ * The administrator will be shown a notice for each check that fails.
+ *
</ins><span class="cx"> * @package BuddyPress Core
</span><span class="cx"> */
</span><span class="cx"> function bp_core_activation_notice() {
</span><span class="cx">         global $wp_rewrite, $wpdb, $bp;
</span><span class="cx">
</span><ins>+        // Only the super admin gets warnings
+        if ( !is_super_admin() )
+                return;
+        
+        // On multisite installs, don't log on a non-root blog
+        if ( !bp_is_root_blog() )
+                return;
+
+        /**
+         * Are pretty permalinks enabled?
+         */
</ins><span class="cx">         if ( isset( $_POST['permalink_structure'] ) )
</span><span class="cx">                 return false;
</span><span class="cx">
</span><span class="cx">         if ( empty( $wp_rewrite->permalink_structure ) ) {
</span><span class="cx">                 bp_core_add_admin_notice( sprintf( __( '<strong>BuddyPress is almost ready</strong>. You must <a href="%s">update your permalink structure</a> to something other than the default for it to work.', 'buddypress' ), admin_url( 'options-permalink.php' ) ) );
</span><span class="cx">         }
</span><del>-                
</del><ins>+        
+        /**
+         * Are you using a BP-compatible theme?
+         */
+        
</ins><span class="cx">         // Get current theme info
</span><span class="cx">         $ct = current_theme_info();
</span><span class="cx">
</span><span class="lines">@@ -245,6 +279,88 @@
</span><span class="cx">         if ( !defined( 'BP_SILENCE_THEME_NOTICE' ) && !in_array( 'buddypress', (array)$ct->tags ) ) {
</span><span class="cx">                 bp_core_add_admin_notice( sprintf( __( "You'll need to <a href='%s'>activate a <strong>BuddyPress-compatible theme</strong></a> to take advantage of all of BuddyPress's features. We've bundled a default theme, but you can always <a href='%s'>install some other compatible themes</a> or <a href='%s'>update your existing WordPress theme</a>.", 'buddypress' ), admin_url( 'themes.php' ), network_admin_url( 'theme-install.php?type=tag&s=buddypress&tab=search' ), network_admin_url( 'plugin-install.php?type=term&tab=search&s=%22bp-template-pack%22' ) ) );
</span><span class="cx">         }
</span><ins>+                
+        /**
+         * Check for orphaned directory pages (BP component is disabled, WP page exists)
+         */
+        
+        $orphaned_pages = array();
+        foreach( $bp->pages as $component_id => $page ) {
+                
+                // Some members of $bp->pages will not have corresponding $bp->{component}, so we
+                // skip them. Plugins can add themselves here if necessary.
+                $exceptions = apply_filters( 'bp_pages_without_components', array( 'register', 'activate' ) );
+                if ( in_array( $component_id, $exceptions ) )
+                        continue;
+                
+                if ( !isset( $bp->{$component_id} ) ) {
+                        // We'll need to get some more information about the page for the notice
+                        $page_data = get_post( $page->id );
+
+                        $orphaned_pages[] = array(
+                                'id'        => $page_data->ID,
+                                'title'        => $page_data->post_title
+                        );
+                }
+                
+        }
+        
+        // If orphaned pages are found, post a notice about them.
+        if ( !empty( $orphaned_pages ) ) {
+                
+                // Create the string of links to the Edit Page screen for the pages
+                $edit_pages_links = array();
+                foreach( $orphaned_pages as $op ) {
+                        $edit_pages_links[] = sprintf( '<a href="%1$s">%2$s</a>', admin_url( 'post.php?action=edit&post=' . $op['id'] ), $op['title'] );
+                }
+                
+                $notice = sprintf( __( 'Some of your WordPress pages are linked to BuddyPress components that have been disabled. These pages may continue to show up in your site navigation. Consider <a href="%1$s">reactivating the components</a>, or unpublishing the pages: <strong>%2$s</strong>', 'buddypress' ), network_admin_url( 'admin.php?page=bp-general-settings' ), implode( ', ', $edit_pages_links ) );
+                
+                bp_core_add_admin_notice( $notice );
+        }
+        
+        /**
+         * Check for orphaned BP components (BP component is enabled, no WP page exists)
+         */
+        
+        $orphaned_components = array();
+        $wp_page_components = array();
+        
+        // Only some BP components require a WP page to function - those with a non-empty root_slug
+        foreach( $bp->active_components as $component_id => $is_active ) {
+                if ( !empty( $bp->{$component_id}->root_slug ) ) {
+                        $wp_page_components[] = array(
+                                'id'        => $component_id,
+                                'name'        => $bp->{$component_id}->name
+                        );
+                }
+        }
+        
+        // Activate and Register are special cases. They are not components but they need WP pages.
+        // If user registration is disabled, we can skip this step.
+        if ( isset( $bp->site_options['registration'] ) && ( 'user' == $bp->site_options['registration'] || ( 'all' == $bp->site_options['registration'] ) ) ) {
+                $wp_page_components[] = array(
+                        'id'        => 'activate',
+                        'name'        => __( 'Activate', 'buddypress' )
+                );
+                
+                $wp_page_components[] = array(
+                        'id'        => 'register',
+                        'name'        => __( 'Register', 'buddypress' )
+                );
+        }        
+        
+        foreach( $wp_page_components as $component ) {                
+                if ( !isset( $bp->pages->{$component['id']} ) ) {
+                        $orphaned_components[] = $component['name'];
+                }
+        }
+        
+        if ( !empty( $orphaned_components ) ) {
+                $notice = sprintf( __( 'Some BuddyPress components must be associated with WordPress pages for your site to work properly. The following components are missing their required WP pages: <strong>%1$s</strong>. Visit the <a href="%2$s">BuddyPress Components</a> panel, where you can either deactivate unused components or complete the page setup.', 'buddypress' ), implode( ', ', $orphaned_components ), network_admin_url( 'admin.php?page=bp-general-settings' ) );
+                
+                bp_core_add_admin_notice( $notice );
+        }
</ins><span class="cx"> }
</span><span class="cx"> add_action( 'admin_init', 'bp_core_activation_notice' );
</span><span class="cx">
</span></span></pre></div>
<a id="trunkbpfriendsbpfriendsloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-friends/bp-friends-loader.php (4182 => 4183)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-friends/bp-friends-loader.php        2011-04-09 14:30:32 UTC (rev 4182)
+++ trunk/bp-friends/bp-friends-loader.php        2011-04-09 17:32:00 UTC (rev 4183)
</span><span class="lines">@@ -61,18 +61,17 @@
</span><span class="cx">                 if ( !defined( 'BP_FRIENDS_SLUG' ) )
</span><span class="cx">                         define( 'BP_FRIENDS_SLUG', $this->id );
</span><span class="cx">
</span><del>-                // Global tables for messaging component
</del><ins>+                // Global tables for the friends component
</ins><span class="cx">                 $global_tables = array(
</span><span class="cx">                         'table_name' => $bp->table_prefix . 'bp_friends',
</span><span class="cx">                         'table_name_meta' => $bp->table_prefix . 'bp_friends_meta',
</span><span class="cx">                 );
</span><span class="cx">
</span><del>-                // All globals for messaging component.
</del><ins>+                // All globals for the friends component.
</ins><span class="cx">                 // Note that global_tables is included in this array.
</span><span class="cx">                 $globals = array(
</span><span class="cx">                         'path' => BP_PLUGIN_DIR,
</span><span class="cx">                         'slug' => BP_FRIENDS_SLUG,
</span><del>-                        'root_slug' => isset( $bp->pages->friends->slug ) ? $bp->pages->friends->slug : BP_FRIENDS_SLUG,
</del><span class="cx">                         'search_string' => __( 'Search Friends...', 'buddypress' ),
</span><span class="cx">                         'notification_callback' => 'friends_format_notifications',
</span><span class="cx">                         'global_tables' => $global_tables,
</span></span></pre></div>
<a id="trunkbpmessagesbpmessagesloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-messages/bp-messages-loader.php (4182 => 4183)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-messages/bp-messages-loader.php        2011-04-09 14:30:32 UTC (rev 4182)
+++ trunk/bp-messages/bp-messages-loader.php        2011-04-09 17:32:00 UTC (rev 4183)
</span><span class="lines">@@ -70,7 +70,6 @@
</span><span class="cx">                 // Note that global_tables is included in this array.
</span><span class="cx">                 $globals = array(
</span><span class="cx">                         'slug' => BP_MESSAGES_SLUG,
</span><del>-                        'root_slug' => isset( $bp->pages->messages->slug ) ? $bp->pages->messages->slug : BP_MESSAGES_SLUG,
</del><span class="cx">                         'notification_callback' => 'messages_format_notifications',
</span><span class="cx">                         'search_string' => __( 'Search Messages...', 'buddypress' ),
</span><span class="cx">                         'global_tables' => $global_tables,
</span></span></pre></div>
<a id="trunkbpsettingsbpsettingsloaderphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-settings/bp-settings-loader.php (4182 => 4183)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-settings/bp-settings-loader.php        2011-04-09 14:30:32 UTC (rev 4182)
+++ trunk/bp-settings/bp-settings-loader.php        2011-04-09 17:32:00 UTC (rev 4183)
</span><span class="lines">@@ -48,11 +48,9 @@
</span><span class="cx">                 if ( !defined( 'BP_SETTINGS_SLUG' ) )
</span><span class="cx">                         define( 'BP_SETTINGS_SLUG', $this->id );
</span><span class="cx">
</span><del>-                // All globals for messaging component.
-                // Note that global_tables is included in this array.
</del><ins>+                // All globals for settings component.
</ins><span class="cx">                 $globals = array(
</span><span class="cx">                         'slug' => BP_SETTINGS_SLUG,
</span><del>-                        'root_slug' => isset( $bp->pages->settings->slug ) ? $bp->pages->settings->slug : BP_SETTINGS_SLUG,
</del><span class="cx">                 );
</span><span class="cx">
</span><span class="cx">                 parent::_setup_globals( $globals );
</span></span></pre>
</div>
</div>
</body>
</html>