Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/17/2017 06:57:15 PM (9 years ago)
Author:
dcavins
Message:

Change signature of groups_edit_base_group_details().

  • Changes the signature of groups_edit_base_group_details() to accept

a single array instead of several arguments.

  • Adds the capability to update the group slug, with the old slug being

stored as a group meta item.

See #6014.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-functions.php

    r11533 r11555  
    219219 * @since 1.0.0
    220220 *
    221  * @param int    $group_id       ID of the group.
    222  * @param string $group_name     Name of the group.
    223  * @param string $group_desc     Description of the group.
    224  * @param bool   $notify_members Whether to send an email notification to group
    225  *                               members about changes in these details.
     221 * @param array $args {
     222 *     An array of optional arguments.
     223 *     @type int    $group_id       ID of the group.
     224 *     @type string $name           Name of the group.
     225 *     @type string $slug           Slug of the group.
     226 *     @type string $description    Description of the group.
     227 *     @type bool   $notify_members Whether to send an email notification to group
     228 *                                  members about changes in these details.
     229 * }
    226230 * @return bool True on success, false on failure.
    227231 */
    228 function groups_edit_base_group_details( $group_id, $group_name, $group_desc, $notify_members ) {
    229 
    230         if ( empty( $group_name ) || empty( $group_desc ) )
    231                 return false;
    232 
    233         $group     = groups_get_group( $group_id );
     232function groups_edit_base_group_details( $args = array() ) {
     233
     234        // Backward compatibility with old method of passing arguments.
     235        if ( ! is_array( $args ) || func_num_args() > 1 ) {
     236                _deprecated_argument( __METHOD__, '2.9.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
     237
     238                $old_args_keys = array(
     239                        0 => 'group_id',
     240                        1 => 'name',
     241                        2 => 'description',
     242                        3 => 'notify_members',
     243                );
     244
     245                $args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
     246        }
     247
     248        $r = wp_parse_args( $args, array(
     249                'group_id'       => bp_get_current_group_id(),
     250                'name'           => null,
     251                'slug'           => null,
     252                'description'    => null,
     253                'notify_members' => false,
     254        ) );
     255
     256        if ( ! $r['group_id'] ) {
     257                return false;
     258        }
     259
     260        $group     = groups_get_group( $r['group_id'] );
    234261        $old_group = clone $group;
    235262
    236         $group->name        = $group_name;
    237         $group->description = $group_desc;
    238 
    239         if ( !$group->save() )
    240                 return false;
    241 
    242         if ( $notify_members ) {
     263        // Group name, slug and description can never be empty. Update only if provided.
     264        if ( $r['name'] ) {
     265                $group->name = $r['name'];
     266        }
     267        if ( $r['slug'] && $r['slug'] != $group->slug ) {
     268                $group->slug = groups_check_slug( $r['slug'] );
     269        }
     270        if ( $r['description'] ) {
     271                $group->description = $r['description'];
     272        }
     273
     274        if ( ! $group->save() ) {
     275                return false;
     276        }
     277
     278        // Maybe update the "previous_slug" groupmeta.
     279        if ( $group->slug != $old_group->slug ) {
     280                /*
     281                 * If the old slug exists in this group's past, delete that entry.
     282                 * Recent previous_slugs are preferred when selecting the current group
     283                 * from an old group slug, so we want the previous slug to be
     284                 * saved "now" in the groupmeta table and don't need the old record.
     285                 */
     286                groups_delete_groupmeta( $group->id, 'previous_slug', $old_group->slug );
     287                groups_add_groupmeta( $group->id, 'previous_slug', $old_group->slug );
     288        }
     289
     290        if ( $r['notify_members'] ) {
    243291                groups_notification_group_updated( $group->id, $old_group );
    244292        }
    … …  
    253301         * @param bool            $notify_members Whether to send an email notification to members about the change.
    254302         */
    255         do_action( 'groups_details_updated', $group->id, $old_group, $notify_members );
     303        do_action( 'groups_details_updated', $group->id, $old_group, $r['notify_members'] );
    256304
    257305        return true;
Note: See TracChangeset for help on using the changeset viewer.