Skip to:
Content

bbPress.org

Changeset 5017


Ignore:
Timestamp:
07/10/2013 07:17:14 AM (13 years ago)
Author:
johnjamesjacoby
Message:

Introduce bbp_repair_forum_visibility() and use it:

  • when creating a new BuddyPress Group Forum
  • in the bbp_admin_repair_forum_visibility() tool

Fixes issues with new group forums not bumping the private/hidden forum ID's. Props r-a-y. Fixes #2349.

Location:
trunk/includes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/admin/tools.php

    r5002 r5017  
    9191
    9292        foreach ( (array) bbp_admin_repair_list() as $item ) {
    93                 if ( isset( $item[2] ) && isset( $_POST[$item[0]] ) && 1 === $_POST[$item[0]] && is_callable( $item[2] ) ) {
     93                if ( isset( $item[2] ) && isset( $_POST[$item[0]] ) && 1 === absint( $_POST[$item[0]] ) && is_callable( $item[2] ) ) {
    9494                        $messages[] = call_user_func( $item[2] );
    9595                }
     
    938938 */
    939939function bbp_admin_repair_forum_visibility() {
    940 
    941940        $statement = __( 'Recalculating forum visibility … %s', 'bbpress' );
    942         $result    = __( 'Failed!', 'bbpress' );
    943 
    944         // First, delete everything.
    945         delete_option( '_bbp_private_forums' );
    946         delete_option( '_bbp_hidden_forums'  );
    947 
    948         // Next, get all the private and hidden forums
    949         $private_forums = new WP_Query( array(
    950                 'suppress_filters' => true,
    951                 'nopaging'         => true,
    952                 'post_type'        => bbp_get_forum_post_type(),
    953                 'post_status'      => bbp_get_private_status_id(),
    954                 'fields'           => 'ids'
    955         ) );
    956         $hidden_forums = new WP_Query( array(
    957                 'suppress_filters' => true,
    958                 'nopaging'         => true,
    959                 'post_type'        => bbp_get_forum_post_type(),
    960                 'post_status'      => bbp_get_hidden_status_id(),
    961                 'fields'           => 'ids'
    962         ) );
    963941
    964942        // Bail if queries returned errors
    965         if ( is_wp_error( $private_forums ) || is_wp_error( $hidden_forums ) )
    966                 return array( 2, sprintf( $statement, $result ) );
    967 
    968         update_option( '_bbp_private_forums', $private_forums->posts ); // Private forums
    969         update_option( '_bbp_hidden_forums',  $hidden_forums->posts  ); // Hidden forums
    970 
    971         // Reset the $post global
    972         wp_reset_postdata();
     943        if ( ! bbp_repair_forum_visibility() ) {
     944                return array( 2, sprintf( $statement, __( 'Failed!',   'bbpress' ) ) );
    973945
    974946        // Complete results
    975         return array( 0, sprintf( $statement, __( 'Complete!', 'bbpress' ) ) );
     947        } else {
     948                return array( 0, sprintf( $statement, __( 'Complete!', 'bbpress' ) ) );
     949        }
    976950}
    977951
  • trunk/includes/common/widgets.php

    r4995 r5017  
    557557
    558558                // Note: private and hidden forums will be excluded via the
    559                 // bbp_pre_get_posts_exclude_forums filter and function.
     559                // bbp_pre_get_posts_normalize_forum_visibility action and function.
    560560                $widget_query = new WP_Query( array(
    561561                        'post_type'           => bbp_get_forum_post_type(),
     
    781781
    782782                // Note: private and hidden forums will be excluded via the
    783                 // bbp_pre_get_posts_exclude_forums filter and function.
     783                // bbp_pre_get_posts_normalize_forum_visibility action and function.
    784784                $widget_query = new WP_Query( $topics_query );
    785785
     
    11221122
    11231123                // Note: private and hidden forums will be excluded via the
    1124                 // bbp_pre_get_posts_exclude_forums filter and function.
     1124                // bbp_pre_get_posts_normalize_forum_visibility action and function.
    11251125                $widget_query = new WP_Query( array(
    11261126                        'post_type'           => bbp_get_reply_post_type(),
  • trunk/includes/extend/buddypress/group.php

    r4995 r5017  
    680680                        $this->disconnect_forum_from_group( $group_id );
    681681                }
     682
     683                // Update bbPress' internal private and forum ID variables
     684                bbp_repair_forum_visibility();
    682685
    683686                // Return the group
  • trunk/includes/forums/functions.php

    r5010 r5017  
    910910}
    911911
     912/**
     913 * Recaches the private and hidden forums
     914 *
     915 * @since bbPress (r5017)
     916 *
     917 * @uses delete_option() to delete private and hidden forum pointers
     918 * @uses WP_Query() To query post IDs
     919 * @uses is_wp_error() To return if error occurred
     920 * @uses update_option() To update the private and hidden post ID pointers
     921 * @return array An array of the status code and the message
     922 */
     923function bbp_repair_forum_visibility() {
     924
     925        // First, delete everything.
     926        delete_option( '_bbp_private_forums' );
     927        delete_option( '_bbp_hidden_forums'  );
     928
     929        // Next, get all the private and hidden forums
     930        $private_forums = new WP_Query( array(
     931                'suppress_filters' => true,
     932                'nopaging'         => true,
     933                'post_type'        => bbp_get_forum_post_type(),
     934                'post_status'      => bbp_get_private_status_id(),
     935                'fields'           => 'ids'
     936        ) );
     937        $hidden_forums = new WP_Query( array(
     938                'suppress_filters' => true,
     939                'nopaging'         => true,
     940                'post_type'        => bbp_get_forum_post_type(),
     941                'post_status'      => bbp_get_hidden_status_id(),
     942                'fields'           => 'ids'
     943        ) );
     944
     945        // Reset the $post global
     946        wp_reset_postdata();
     947
     948        // Bail if queries returned errors
     949        if ( is_wp_error( $private_forums ) || is_wp_error( $hidden_forums ) )
     950                return false;
     951
     952        // Update the private/hidden options
     953        update_option( '_bbp_private_forums', $private_forums->posts ); // Private forums
     954        update_option( '_bbp_hidden_forums',  $hidden_forums->posts  ); // Hidden forums
     955
     956        // Complete results
     957        return true;
     958}
     959
    912960/** Count Bumpers *************************************************************/
    913961
Note: See TracChangeset for help on using the changeset viewer.