Skip to:
Content

bbPress.org

Changeset 7210


Ignore:
Timestamp:
09/21/2021 03:14:26 AM (5 weeks ago)
Author:
johnjamesjacoby
Message:

BuddyPress Groups: sync forum Title, Description, and Slug to Group.

This change ensures that when editing an existing group with a forum, its stays up-to-date with its parent group.

Props johnjamesjacoby.

In trunk, for 2.7.0.

Fixes #3417.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/extend/buddypress/groups.php

    r7098 r7210  
    8787        add_action( 'bbp_after_group_forum_display',  array( $this, 'remove_group_forum_meta_cap_map' ) );
    8888
    89         // Validate group forum IDs when editing topics & replies
     89        // Validate group IDs when editing topics & replies
    9090        add_action( 'bbp_edit_topic_pre_extras',      array( $this, 'validate_topic_forum_id' ) );
    9191        add_action( 'bbp_edit_reply_pre_extras',      array( $this, 'validate_reply_to_id'    ) );
    9292
    93         // Check if group-forum status should be changed
    94         add_action( 'groups_group_after_save',        array( $this, 'update_group_forum_visibility'  ) );
     93        // Check if group-forum attributes should be changed
     94        add_action( 'groups_group_after_save',        array( $this, 'update_group_forum' ) );
    9595
    9696        // bbPress needs to listen to BuddyPress group deletion
     
    861861
    862862    /**
    863      * Set forums' status to match the privacy status of the associated group
     863     * Update forum attributes to match those of the associated group.
    864864     *
    865865     * Fired whenever a group is saved
    866866     *
     867     * @since 2.6.7 bbPress (r7208)
     868     *
    867869     * @param BP_Groups_Group $group Group object.
    868870     */
    869     public static function update_group_forum_visibility( BP_Groups_Group $group ) {
     871    public static function update_group_forum( BP_Groups_Group $group ) {
    870872
    871873        // Get group forum IDs
     
    903905                        break;
    904906                }
     907            }
     908        }
     909
     910        // Maybe update the first group forum title, content, and slug
     911        if ( ! empty( $forum_ids[0] ) ) {
     912
     913            // Get forum from ID
     914            $forum = bbp_get_forum( $forum_ids[0] );
     915
     916            // Only update the forum if changes are being made
     917            if (
     918
     919                // Title
     920                ( $forum->post_title !== $group->name )
     921
     922                ||
     923
     924                // Content
     925                ( $forum->post_content !== $group->description )
     926
     927                ||
     928
     929                // Slug
     930                ( $forum->post_name !== $group->slug )
     931            ) {
     932                wp_update_post(
     933                    array(
     934                        'ID'           => $forum->ID,
     935                        'post_title'   => $group->name,
     936                        'post_content' => $group->description,
     937                        'post_name'    => $group->slug
     938                    )
     939                );
    905940            }
    906941        }
Note: See TracChangeset for help on using the changeset viewer.