Changeset 8157
- Timestamp:
- 03/25/2014 06:30:56 PM (11 years ago)
- Location:
- trunk/bp-groups
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups/bp-groups-classes.php
r8069 r8157 265 265 266 266 do_action_ref_array( 'groups_group_before_save', array( &$this ) ); 267 268 // Groups need at least a name 269 if ( empty( $this->name ) ) { 270 return false; 271 } 272 273 // Set slug with group title if not passed 274 if ( empty( $this->slug ) ) { 275 $this->slug = sanitize_title( $this->name ); 276 } 277 278 // Sanity check 279 if ( empty( $this->slug ) ) { 280 return false; 281 } 282 283 // Check for slug conflicts if creating new group 284 if ( empty( $this->id ) ) { 285 $this->slug = groups_check_slug( $this->slug ); 286 } 267 287 268 288 if ( !empty( $this->id ) ) { -
trunk/bp-groups/bp-groups-functions.php
r8135 r8157 58 58 /*** Group Creation, Editing & Deletion *****************************************/ 59 59 60 /** 61 * Create a group. 62 * 63 * @since BuddyPress (1.0.0) 64 * 65 * @param array $args { 66 * An array of arguments. 67 * @type int|bool $group_id Pass a group ID to update an existing item, or 68 * 0 / false to create a new group. Default: 0. 69 * @type int $creator_id The user ID that creates the group. 70 * @type string $name The group name. 71 * @type string $description Optional. The group's description. 72 * @type string $slug The group slug. 73 * @type string $status The group's status. Accepts 'public', 'private' or 74 'hidden'. Defaults to 'public'. 75 * @type int $enable_forum Optional. Whether the group has a forum enabled. 76 * If the legacy forums are enabled for this group or if a bbPress 77 * forum is enabled for the group, set this to 1. Default: 0. 78 * @type string $date_created The GMT time, in Y-m-d h:i:s format, 79 * when the group was created. Defaults to the current time. 80 * } 81 * @return int|bool The ID of the group on success. False on error. 82 */ 60 83 function groups_create_group( $args = '' ) { 61 84 62 extract( $args ); 63 64 /** 65 * Possible parameters (pass as assoc array): 66 * 'group_id' 67 * 'creator_id' 68 * 'name' 69 * 'description' 70 * 'slug' 71 * 'status' 72 * 'enable_forum' 73 * 'date_created' 74 */ 75 76 if ( !empty( $group_id ) ) 77 $group = groups_get_group( array( 'group_id' => $group_id ) ); 78 else 85 $defaults = array( 86 'group_id' => 0, 87 'creator_id' => 0, 88 'name' => '', 89 'description' => '', 90 'slug' => '', 91 'status' => 'public', 92 'enable_forum' => 0, 93 'date_created' => bp_core_current_time() 94 ); 95 96 $args = wp_parse_args( $args, $defaults ); 97 extract( $args, EXTR_SKIP ); 98 99 // Pass an existing group ID 100 if ( ! empty( $group_id ) ) { 101 $group = groups_get_group( array( 'group_id' => (int) $group_id ) ); 102 $name = ! empty( $name ) ? $name : $group->name; 103 $slug = ! empty( $slug ) ? $slug : $group->slug; 104 105 // Groups need at least a name 106 if ( empty( $name ) ) { 107 return false; 108 } 109 110 // Create a new group 111 } else { 112 // Instantiate new group object 79 113 $group = new BP_Groups_Group; 80 81 if ( !empty( $creator_id ) ) 82 $group->creator_id = $creator_id; 83 else 114 } 115 116 // Set creator ID 117 if ( ! empty( $creator_id ) ) { 118 $group->creator_id = (int) $creator_id; 119 } else { 84 120 $group->creator_id = bp_loggedin_user_id(); 85 86 if ( isset( $name ) ) 87 $group->name = $name; 88 89 if ( isset( $description ) ) 90 $group->description = $description; 91 92 if ( isset( $slug ) && groups_check_slug( $slug ) ) 93 $group->slug = $slug; 94 95 if ( isset( $status ) ) { 96 if ( groups_is_valid_status( $status ) ) { 97 $group->status = $status; 98 } 99 } 100 101 if ( isset( $enable_forum ) ) 102 $group->enable_forum = $enable_forum; 103 else if ( empty( $group_id ) && !isset( $enable_forum ) ) 104 $group->enable_forum = 1; 105 106 if ( isset( $date_created ) ) 107 $group->date_created = $date_created; 108 109 if ( !$group->save() ) 110 return false; 121 } 122 123 // Validate status 124 if ( ! groups_is_valid_status( $status ) ) { 125 return false; 126 } 127 128 // Set group name 129 $group->name = $name; 130 $group->description = $description; 131 $group->slug = $slug; 132 $group->status = $status; 133 $group->enable_forum = (int) $enable_forum; 134 $group->date_created = $date_created; 135 136 // Save group 137 if ( ! $group->save() ) { 138 return false; 139 } 111 140 112 141 // If this is a new group, set up the creator as the first member and admin
Note: See TracChangeset
for help on using the changeset viewer.