Ticket #5214: 5214.01.patch
File 5214.01.patch, 4.8 KB (added by , 11 years ago) |
---|
-
bp-groups/bp-groups-classes.php
class BP_Groups_Group { 127 127 128 128 do_action_ref_array( 'groups_group_before_save', array( &$this ) ); 129 129 130 // Groups need at least a name 131 if ( empty( $this->name ) ) { 132 return false; 133 } 134 135 // No creator ID? stop now! 136 if ( empty( $this->creator_id ) ) { 137 return false; 138 } 139 140 // Set group status if passed 141 if ( $this->status != 'public' ) { 142 if ( ! groups_is_valid_status( $this->status ) ) { 143 return false; 144 } 145 } 146 147 // Set slug with group title if not passed 148 if ( empty( $this->slug ) ) { 149 $this->slug = sanitize_title( $this->name ); 150 } 151 152 // Sanity check 153 if ( empty( $this->slug ) ) { 154 return false; 155 } 156 157 // Check for slug conflicts if creating new group 158 if ( empty( $this->id ) ) { 159 $this->slug = groups_check_slug( $this->slug ); 160 } 161 130 162 if ( !empty( $this->id ) ) { 131 163 $sql = $wpdb->prepare( 132 164 "UPDATE {$bp->groups->table_name} SET -
bp-groups/bp-groups-functions.php
function groups_get_group( $args = '' ) { 60 60 61 61 /*** Group Creation, Editing & Deletion *****************************************/ 62 62 63 /** 64 * Create a group. 65 * 66 * @since BuddyPress (1.0.0) 67 * 68 * @param array $args { 69 * An array of arguments. 70 * @type int|bool $group_id Pass a group ID to update an existing item, or 71 * 0 / false to create a new group. Default: 0. 72 * @type int $creator_id The user ID that creates the group. 73 * @type string $name The group name. 74 * @type string $description Optional. The group's description. 75 * @type string $slug The group slug. 76 * @type string $status The group's status. Accepts 'public', 'private' or 77 'hidden'. Defaults to 'public'. 78 * @type int $enable_forum Optional. Whether the group has a forum enabled. 79 * If the legacy forums are enabled for this group or if a bbPress 80 * forum is enabled for the group, set this to 1. Default: 0. 81 * @type string $date_created The GMT time, in Y-m-d h:i:s format, 82 * when the group was created. Defaults to the current time. 83 * } 84 * @return int|bool The ID of the group on success. False on error. 85 */ 63 86 function groups_create_group( $args = '' ) { 64 87 65 extract( $args ); 66 67 /** 68 * Possible parameters (pass as assoc array): 69 * 'group_id' 70 * 'creator_id' 71 * 'name' 72 * 'description' 73 * 'slug' 74 * 'status' 75 * 'enable_forum' 76 * 'date_created' 77 */ 78 79 if ( !empty( $group_id ) ) 80 $group = groups_get_group( array( 'group_id' => $group_id ) ); 81 else 82 $group = new BP_Groups_Group; 83 84 if ( !empty( $creator_id ) ) 85 $group->creator_id = $creator_id; 86 else 87 $group->creator_id = bp_loggedin_user_id(); 88 89 if ( isset( $name ) ) 90 $group->name = $name; 88 $defaults = array( 89 'group_id' => 0, 90 'creator_id' => 0, 91 'name' => '', 92 'description' => '', 93 'slug' => '', 94 'status' => 'public', 95 'enable_forum' => 0, 96 'date_created' => bp_core_current_time() 97 ); 91 98 92 if ( isset( $description ) )93 $group->description = $description;99 $args = wp_parse_args( $args, $defaults ); 100 extract( $args, EXTR_SKIP ); 94 101 95 if ( isset( $slug ) && groups_check_slug( $slug ) ) 96 $group->slug = $slug; 102 // Pass an existing group ID 103 if ( ! empty( $group_id ) ) { 104 $group = groups_get_group( array( 'group_id' => (int) $group_id ) ); 105 $name = ! empty( $name ) ? $name : $group->name; 106 $slug = ! empty( $slug ) ? $slug : $group->slug; 97 107 98 if ( isset( $status ) ) {99 if ( groups_is_valid_status( $status) ) {100 $group->status = $status;108 // Groups need at least a name 109 if ( empty( $name ) ) { 110 return false; 101 111 } 112 113 // Create a new group 114 } else { 115 // Instantiate new group object 116 $group = new BP_Groups_Group; 102 117 } 103 118 104 if ( isset( $enable_forum ) ) 105 $group->enable_forum = $enable_forum; 106 else if ( empty( $group_id ) && !isset( $enable_forum ) ) 107 $group->enable_forum = 1; 119 // Set creator ID 120 if ( ! empty( $creator_id ) ) { 121 $group->creator_id = (int) $creator_id; 122 } else { 123 $group->creator_id = bp_loggedin_user_id(); 124 } 108 125 109 if ( isset( $date_created ) ) 110 $group->date_created = $date_created; 126 // Set group name 127 $group->name = $name; 128 $group->description = $description; 129 $group->slug = $slug; 130 $group->status = $status; 131 $group->enable_forum = (int) $enable_forum; 132 $group->date_created = $date_created; 111 133 112 if ( !$group->save() ) 134 // Save group 135 if ( ! $group->save() ) { 113 136 return false; 137 } 114 138 115 139 // If this is a new group, set up the creator as the first member and admin 116 140 if ( empty( $group_id ) ) {