Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/23/2011 04:23:34 PM (15 years ago)
Author:
boonebgorges
Message:

Moves bp-pages data to a single site_option, an array keyed by blog_id. Fixes #3144

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-functions.php

    r4203 r4254  
    1717 *
    1818 * @package BuddyPress Core
     19 * @since 1.3
     20 *
     21 * @todo Remove the "Upgrading from an earlier version of BP pre-1.3" block. Temporary measure for
     22 *       people running trunk installations. Leave for a version or two, then remove.
    1923 */
    2024function bp_core_get_page_meta() {
    21         if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )
    22                 $page_ids = get_blog_option( BP_ROOT_BLOG, 'bp-pages' );
    23         else
    24                 $page_ids = get_option( 'bp-pages' );
    25 
    26         return $page_ids;
     25        $page_ids = get_site_option( 'bp-pages' );
     26       
     27        $is_enable_multiblog = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? true : false;
     28
     29        $page_blog_id = $is_enable_multiblog ? get_current_blog_id() : BP_ROOT_BLOG;
     30       
     31        // Upgrading from an earlier version of BP pre-1.3
     32        if ( empty( $page_ids ) || isset( $page_ids['members'] ) ) {           
     33                if ( empty( $page_ids ) ) {             
     34                        // We're probably coming from an old multisite install
     35                        $old_page_ids = get_blog_option( $page_blog_id, 'bp-pages' );
     36                } else {
     37                        // We're probably coming from an old single-WP install
     38                        $old_page_ids = $page_ids;
     39                }
     40               
     41                /**
     42                 * If $page_ids is found in a blog_option, and it's formatted in the new way (keyed
     43                 * by blog_id), it means that this is an MS upgrade. Return false and let the
     44                 * upgrade wizard handle the migration.
     45                 */
     46                if ( !isset( $old_page_ids['members'] ) )
     47                        return false;
     48                       
     49                // Finally, move the page ids over to site options
     50                $new_page_ids = array(
     51                        $page_blog_id => $old_page_ids
     52                );
     53
     54                update_site_option( 'bp-pages', $new_page_ids );
     55        }
     56       
     57        $blog_page_ids = !empty( $page_ids[$page_blog_id] ) ? $page_ids[$page_blog_id] : false;
     58       
     59        return apply_filters( 'bp_core_get_page_meta', $blog_page_ids );
    2760}
    2861
     
    3063 * Stores BP pages in the meta table, depending on setup
    3164 *
    32  * bp-pages data is stored in the options table of the root blog, except when BP_ENABLE_MULTIBLOG
    33  * is turned on.
     65 * bp-pages data is stored in site_options (falls back to options on non-MS), in an array keyed by
     66 * blog_id. This allows you to change your BP_ROOT_BLOG and go through the setup process again.
    3467 *
    3568 * @package BuddyPress Core
    3669 * @since 1.3
    3770 *
    38  * @param array $page_ids The IDs of the WP pages corresponding to BP component directories
    39  */
    40 function bp_core_update_page_meta( $page_ids ) {
    41         if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )
    42                 update_blog_option( BP_ROOT_BLOG, 'bp-pages', $page_ids );
    43         else
    44                 update_option( 'bp-pages', $page_ids );
     71 * @param array $blog_page_ids The IDs of the WP pages corresponding to BP component directories
     72 */
     73function bp_core_update_page_meta( $blog_page_ids ) {
     74        if ( !$page_ids = get_site_option( 'bp-pages' ) )
     75                $page_ids = array();
     76
     77        // Generally, we key by the BP_ROOT_BLOG. Exception: when BP_ENABLE_MULTIBLOG is turned on
     78        $key = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
     79       
     80        $page_ids[$key] = $blog_page_ids;
     81
     82        update_site_option( 'bp-pages', $page_ids );
    4583}
    4684
     
    64102                $posts_table_name = is_multisite() && !defined( 'BP_ENABLE_MULTIBLOG' ) ? $wpdb->get_blog_prefix( BP_ROOT_BLOG ) . 'posts' : $wpdb->posts;
    65103                $page_ids_sql     = implode( ',', (array)$page_ids );
    66                 $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' " ) );
     104                $page_names       = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent, post_title FROM {$posts_table_name} WHERE ID IN ({$page_ids_sql}) AND post_status = 'publish' " ) );
    67105
    68106                foreach ( (array)$page_ids as $key => $page_id ) {
    69107                        foreach ( (array)$page_names as $page_name ) {
    70108                                if ( $page_name->ID == $page_id ) {
    71                                         $pages->{$key}->name = $page_name->post_name;
    72                                         $pages->{$key}->id   = $page_name->ID;
    73                                         $slug[]              = $page_name->post_name;
     109                                        $pages->{$key}->name  = $page_name->post_name;
     110                                        $pages->{$key}->id    = $page_name->ID;
     111                                        $pages->{$key}->title = $page_name->post_title;
     112                                        $slug[]               = $page_name->post_name;
    74113
    75114                                        // Get the slug
Note: See TracChangeset for help on using the changeset viewer.