Skip to:
Content

BuddyPress.org

Ticket #5170: 5170.patch

File 5170.patch, 3.9 KB (added by johnjamesjacoby, 13 years ago)
  • bp-core/bp-core-widgets.php

     
    100100
    101101                <?php endif; ?>
    102102
    103                 <?php echo $after_widget; ?>
    104         <?php
     103                <?php echo $after_widget;
     104
     105                // Reset the members query
     106                bp_reset_members_query();
    105107        }
    106108
    107109        function update( $new_instance, $old_instance ) {
     
    189191
    190192                <?php endif; ?>
    191193
    192                 <?php echo $after_widget; ?>
    193         <?php
     194                <?php echo $after_widget;
     195
     196                // Reset the members query
     197                bp_reset_members_query();
    194198        }
    195199
    196200        function update( $new_instance, $old_instance ) {
     
    258262
    259263                <?php endif; ?>
    260264
    261                 <?php echo $after_widget; ?>
    262         <?php
     265                <?php echo $after_widget;
     266
     267                // Reset the members query
     268                bp_reset_members_query();
    263269        }
    264270
    265271        function update( $new_instance, $old_instance ) {
  • bp-loader.php

     
    9696         */
    9797        public $active_components = array();
    9898
     99        /**
     100         * @var array Main query loops (akin to $wp_the_query)
     101         */
     102        public $main_queries = array();
     103
    99104        /** Option Overload *******************************************************/
    100105
    101106        /**
  • bp-members/bp-members-template.php

     
    170170        var $total_member_count;
    171171
    172172        function __construct( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value, $page_arg = 'upage' ) {
     173                global $members_template;
    173174
     175                // Setup the main query
     176                if ( empty( $members_template ) ) {
     177                        $this->set_main_query();
     178                }
     179
    174180                $this->pag_page = !empty( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : (int) $page_number;
    175181                $this->pag_num  = !empty( $_REQUEST['num'] )   ? intval( $_REQUEST['num'] )   : (int) $per_page;
    176182                $this->type     = $type;
     
    253259                if ( 0 == $this->current_member )
    254260                        do_action( 'member_loop_start' );
    255261        }
     262
     263        /**
     264         * Is this the main members query?
     265         *
     266         * @since BuddyPress (1.9)
     267         *
     268         * @return boolean
     269         */
     270        public function is_main_query() {
     271                return (bool) ( self::get_main_query() === $this );
     272        }
     273
     274        /** Static Methods ********************************************************/
     275
     276        /**
     277         * @since BuddyPress (1.9)
     278         */
     279        public static function get_main_query() {
     280                $bp = buddypress();
     281
     282                // Bail if no members component (how did this happen)
     283                if ( empty( $bp->members->id ) ) {
     284                        return false;
     285                }
     286
     287                // Bail if no main query already set
     288                if ( empty( $bp->main_queries[ $bp->members->id ] ) ) {
     289                        return false;
     290                }
     291
     292                // Get and return the main members query
     293                return $bp->main_queries[ $bp->members->id ];
     294        }
     295
     296        /**
     297         * @since BuddyPress (1.9)
     298         */
     299        public static function set_main_query( $members_query ) {
     300                $bp = buddypress();
     301
     302                // Bail if no members component (how did this happen)
     303                if ( empty( $bp->members->id ) ) {
     304                        return;
     305                }
     306
     307                // Set the main query
     308                $bp->main_queries[ $bp->members->id ] = $members_query;
     309        }
     310
     311        /**
     312         *
     313         * @since BuddyPress (1.9)
     314         * @global type $members_template
     315         */
     316        public static function reset_query() {
     317                global $members_template;
     318
     319                $main_query = self::get_main_query();
     320
     321                if ( false !== $main_query ) {
     322                        $members_template = $main_query;
     323                } else {
     324                        unset( $members_template );
     325                }
     326        }
    256327}
    257328
     329/**
     330 * Destroy the previous members query and set up a new members query.
     331 *
     332 * This should be used after {@link bp_has_members()} and before another {@link
     333 * bp_has_members()}. This will remove obscure bugs that occur when the previous
     334 * BP_Core_Members_Template object is not destroyed properly before another is
     335 * set up. (This is akin to wp_reset_query() in WordPress core.)
     336 *
     337 * @since BuddyPress (1.9)
     338 *
     339 * @uses $members_template
     340 * @uses BP_Core_Members_Template::reset_query()
     341 */
     342function bp_reset_members_query() {
     343        global $members_template;
     344
     345        $members_template->reset_query();
     346}
     347
    258348function bp_rewind_members() {
    259349        global $members_template;
    260350