Ticket #7210: 7210.01.patch
File 7210.01.patch, 18.9 KB (added by , 8 years ago) |
---|
-
src/bp-core/bp-core-template.php
2621 2621 * @return True if the current page is the groups directory. 2622 2622 */ 2623 2623 function bp_is_groups_directory() { 2624 if ( bp_is_groups_component() && ! bp_ current_action() && ! bp_current_item() ) {2624 if ( bp_is_groups_component() && ! bp_is_group() && ( ! bp_current_action() || ( bp_action_variable() && bp_is_current_action( bp_get_groups_group_type_base() ) ) ) ) { 2625 2625 return true; 2626 2626 } 2627 2627 -
src/bp-groups/bp-groups-actions.php
210 210 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . bp_get_groups_current_create_step() ) ); 211 211 } 212 212 213 // Save group types. 214 if ( ! empty( $_POST['group-types'] ) ) { 215 bp_groups_set_group_type( $bp->groups->new_group_id, $_POST['group-types'] ); 216 } 217 213 218 /** 214 219 * Filters the allowed invite statuses. 215 220 * -
src/bp-groups/bp-groups-functions.php
2167 2167 'singular_name' => $default_name, 2168 2168 ), $r['labels'] ); 2169 2169 2170 // Directory slug. 2171 if ( ! empty( $r['has_directory'] ) ) { 2172 // A string value is intepreted as the directory slug. 2173 if ( is_string( $r['has_directory'] ) ) { 2174 $directory_slug = $r['has_directory']; 2175 2176 // Otherwise fall back on group type. 2177 } else { 2178 $directory_slug = $group_type; 2179 } 2180 2181 // Sanitize for use in URLs. 2182 $r['directory_slug'] = sanitize_title( $directory_slug ); 2183 $r['has_directory'] = true; 2184 } else { 2185 $r['directory_slug'] = ''; 2186 $r['has_directory'] = false; 2187 } 2188 2170 2189 $bp->groups->types[ $group_type ] = $type = (object) $r; 2171 2190 2172 2191 /** … … 2246 2265 * Set type for a group. 2247 2266 * 2248 2267 * @since 2.6.0 2268 * @since 2.7.0 $group_type parameter also accepts an array of group types now. 2249 2269 * 2250 * @param int $group ID of the group.2251 * @param string $group_type Group type.2252 * @param bool $append Optional. True to append this to existing types for group,2253 * false to replace. Default: false.2270 * @param int $group ID of the group. 2271 * @param string|array $group_type Group type or array of group types to set. 2272 * @param bool $append Optional. True to append this to existing types for group, 2273 * false to replace. Default: false. 2254 2274 * @return array $retval See bp_set_object_terms(). 2255 2275 */ 2256 2276 function bp_groups_set_group_type( $group_id, $group_type, $append = false ) { 2257 2277 // Pass an empty group type to remove group's type. 2258 if ( ! empty( $group_type ) && ! bp_groups_get_group_type_object( $group_type ) ) {2278 if ( ! empty( $group_type ) && is_string( $group_type ) && ! bp_groups_get_group_type_object( $group_type ) ) { 2259 2279 return false; 2260 2280 } 2261 2281 2282 // Cast as array. 2283 $group_type = (array) $group_type; 2284 2285 // Validate group types. 2286 foreach ( $group_type as $type ) { 2287 // Remove any invalid group types. 2288 if ( is_null( bp_groups_get_group_type_object( $type ) ) ) { 2289 unset( $group_type[ $type ] ); 2290 } 2291 } 2292 2262 2293 $retval = bp_set_object_terms( $group_id, $group_type, 'bp_group_type', $append ); 2263 2294 2264 2295 // Bust the cache if the type has been updated. … … 2270 2301 * 2271 2302 * @since 2.6.0 2272 2303 * 2273 * @param int $group_id ID of the group whose group type has been updated.2274 * @param string $group_type Group type.2275 * @param bool $append Whether the type is being appended to existing types.2304 * @param int $group_id ID of the group whose group type has been updated. 2305 * @param string|array $group_type Group type or array of group types. 2306 * @param bool $append Whether the type is being appended to existing types. 2276 2307 */ 2277 2308 do_action( 'bp_groups_set_group_type', $group_id, $group_type, $append ); 2278 2309 } … … 2383 2414 } 2384 2415 2385 2416 /** 2417 * Get the "current" group type, if one is provided, in group directories. 2418 * 2419 * @since 2.7.0 2420 * 2421 * @return string 2422 */ 2423 function bp_get_current_group_directory_type() { 2424 2425 /** 2426 * Filters the "current" group type, if one is provided, in group directories. 2427 * 2428 * @since 2.7.0 2429 * 2430 * @param string $value "Current" group type. 2431 */ 2432 return apply_filters( 'bp_get_current_group_directory_type', buddypress()->groups->current_directory_type ); 2433 } 2434 2435 /** 2386 2436 * Delete a group's type when the group is deleted. 2387 2437 * 2388 2438 * @since 2.6.0 -
src/bp-groups/bp-groups-screens.php
25 25 */ 26 26 function groups_directory_groups_setup() { 27 27 if ( bp_is_groups_directory() ) { 28 // Set group type if available. 29 if ( bp_is_current_action( bp_get_groups_group_type_base() ) && bp_action_variable() ) { 30 $matched_types = bp_groups_get_group_types( array( 31 'has_directory' => true, 32 'directory_slug' => bp_action_variable(), 33 ) ); 34 35 // Redirect back to group directory if no match. 36 if ( empty( $matched_types ) ) { 37 bp_core_redirect( bp_get_groups_directory_permalink() ); 38 } 39 40 // Set our global variable. 41 buddypress()->groups->current_directory_type = reset( $matched_types ); 42 } 43 28 44 bp_update_is_directory( true, 'groups' ); 29 45 30 46 /** … … 915 931 if ( !check_admin_referer( 'groups_edit_group_settings' ) ) 916 932 return false; 917 933 934 // Save group types. 935 if ( isset( $_POST['group-types'] ) ) { 936 // Validate group types. 937 bp_groups_set_group_type( bp_get_current_group_id(), $_POST['group-types'] ); 938 } 939 918 940 if ( !groups_edit_group_settings( $_POST['group-id'], $enable_forum, $status, $invite_status ) ) { 919 941 bp_core_add_message( __( 'There was an error updating group settings. Please try again.', 'buddypress' ), 'error' ); 920 942 } else { -
src/bp-groups/bp-groups-template.php
72 72 } 73 73 74 74 /** 75 * Output the group type base slug. 76 * 77 * @since 2.7.0 78 */ 79 function bp_groups_group_type_base() { 80 echo esc_url( bp_get_groups_group_type_base() ); 81 } 82 /** 83 * Get the group type base slug. 84 * 85 * The base slug is the string used as the base prefix when generating group 86 * type directory URLs. For example, in example.com/groups/type/foo/, 'foo' is 87 * the group type and 'type' is the base slug. 88 * 89 * @since 2.7.0 90 * 91 * @return string 92 */ 93 function bp_get_groups_group_type_base() { 94 /** 95 * Filters the group type URL base. 96 * 97 * @since 2.7.0 98 * 99 * @param string $base 100 */ 101 return apply_filters( 'bp_groups_group_type_base', _x( 'type', 'group type URL base', 'buddypress' ) ); 102 } 103 104 /** 75 105 * Output group directory permalink. 76 106 * 77 107 * @since 1.5.0 … … 99 129 } 100 130 101 131 /** 132 * Output group type directory permalink. 133 * 134 * @since 2.7.0 135 * 136 * @param string $group_type Optional. Group type. 137 */ 138 function bp_group_type_directory_permalink( $group_type = '' ) { 139 echo esc_url( bp_get_group_type_directory_permalink( $group_type ) ); 140 } 141 /** 142 * Return group type directory permalink. 143 * 144 * @since 2.7.0 145 * 146 * @param string $group_type Optional. Group type. Defaults to current group type. 147 * @return string Group type directory URL on success, an empty string on failure. 148 */ 149 function bp_get_group_type_directory_permalink( $group_type = '' ) { 150 151 if ( $group_type ) { 152 $_group_type = $group_type; 153 } else { 154 // Fall back on the current group type. 155 $_group_type = bp_get_current_group_directory_type(); 156 } 157 158 $type = bp_groups_get_group_type_object( $_group_type ); 159 160 // Bail when member type is not found or has no directory. 161 if ( ! $type || ! $type->has_directory ) { 162 return ''; 163 } 164 165 /** 166 * Filters the group type directory permalink. 167 * 168 * @since 2.7.0 169 * 170 * @param string $value Group type directory permalink. 171 * @param object $type Group type object. 172 * @param string $member_type Group type name, as passed to the function. 173 */ 174 return apply_filters( 'bp_get_group_type_directory_permalink', trailingslashit( bp_get_groups_directory_permalink() . bp_get_groups_group_type_base() . '/' . $type->directory_slug ), $type, $group_type ); 175 } 176 177 /** 178 * Output group type directory link. 179 * 180 * @since 2.7.0 181 * 182 * @param string $group_type Unique group type identifier as used in bp_groups_register_group_type(). 183 */ 184 function bp_group_type_directory_link( $group_type = '' ) { 185 echo bp_get_group_type_directory_link( $group_type ); 186 } 187 /** 188 * Return group type directory link. 189 * 190 * @since 2.7.0 191 * 192 * @param string $group_type Unique group type identifier as used in bp_groups_register_group_type(). 193 * @return string 194 */ 195 function bp_get_group_type_directory_link( $group_type = '' ) { 196 if ( empty( $group_type ) ) { 197 return ''; 198 } 199 200 return sprintf( '<a href="%s">%s</a>', esc_url( bp_get_group_type_directory_permalink( $group_type ) ), bp_groups_get_group_type_object( $group_type )->labels['name'] ); 201 } 202 203 /** 204 * Output a comma-delimited list of group types. 205 * 206 * @since 2.7.0 207 * @see bp_get_group_type_list() for parameter documentation. 208 */ 209 function bp_group_type_list( $group_id = 0, $r = array() ) { 210 echo bp_get_group_type_list( $group_id, $r ); 211 } 212 /** 213 * Return a comma-delimited list of group types. 214 * 215 * @since 2.7.0 216 * 217 * @param int $group_id Group ID. Defaults to current group ID if on a group page. 218 * @param array|string $args { 219 * Array of parameters. All items are optional. 220 * @type string $wrapper_element Element to wrap around the list. Defaults to 'p'. 221 * @type string $wrapper_class CSS class for wrapper element. Defaults to 'bp-group-type-list'. 222 * @type string $label Label to add before the list. Defaults to 'Group Types:'. 223 * @type string $label_element Element to wrap around the label. Defaults to 'strong'. 224 * } 225 * @return string 226 */ 227 function bp_get_group_type_list( $group_id = 0, $r = array() ) { 228 if ( empty( $group_id ) ) { 229 $group_id = bp_get_current_group_id(); 230 } 231 232 $r = bp_parse_args( $r, array( 233 'wrapper_element' => 'p', 234 'wrapper_class' => 'bp-group-type-list', 235 'label' => __( 'Group Types:', 'buddypress' ), 236 'label_element' => 'strong', 237 ), 'group_type_list' ); 238 239 $retval = $wrapper = $label = ''; 240 241 if ( $types = bp_groups_get_group_type( $group_id, false ) ) { 242 $r['label'] = esc_html( $r['label'] ); 243 $r['label_element'] = sanitize_html_class( $r['label_element'] ); 244 $r['wrapper_element'] = sanitize_html_class( $r['wrapper_element'] ); 245 $r['wrapper_class'] = sanitize_html_class( $r['wrapper_class'] ); 246 247 if ( ! empty( $r['wrapper_element'] ) ) { 248 $wrapper = sprintf( '<%1$s%2$s>', 249 $r['wrapper_element'], 250 ! empty( $r['wrapper_class'] ) ? " class=\"{$r['wrapper_class']}\"" : '' 251 ); 252 } 253 254 if ( ! empty( $r['label'] ) && ! empty( $r['label_element'] ) ) { 255 $label = sprintf( '<%1$s>%2$s</%1$s>', 256 $r['label_element'], 257 $r['label'] 258 ); 259 } elseif ( ! empty( $r['label'] ) ) { 260 $label = $r['label']; 261 } 262 263 // Comma-delimit each type into the group type directory link. 264 $type_list = implode( ', ', array_map( 'bp_get_group_type_directory_link', $types ) ); 265 266 // Retval time! 267 $retval = "{$wrapper}{$label}"; 268 269 // Add some whitespace if needed. 270 if ( ! empty( $retval ) ) { 271 $retval .= ' '; 272 } 273 274 $retval .= $type_list; 275 276 if ( ! empty( $wrapper ) ) { 277 $retval .= "</{$r['wrapper_element']}>"; 278 } 279 } 280 281 return $retval; 282 } 283 284 /** 102 285 * Start the Groups Template Loop. 103 286 * 104 287 * @since 1.0.0 … … 169 352 $slug = bp_get_current_group_slug(); 170 353 } 171 354 355 $group_type = bp_get_current_group_directory_type(); 356 if ( ! $group_type && ! empty( $_GET['group_type'] ) ) { 357 if ( is_array( $_GET['group_type'] ) ) { 358 $group_type = $_GET['group_type']; 359 } else { 360 // Can be a comma-separated list. 361 $group_type = explode( ',', $_GET['group_type'] ); 362 } 363 } 364 172 365 // Default search string (too soon to escape here). 173 366 $search_query_arg = bp_core_get_component_search_query_arg( 'groups' ); 174 367 if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) { … … 192 385 'user_id' => bp_displayed_user_id(), 193 386 'slug' => $slug, 194 387 'search_terms' => $search_terms, 195 'group_type' => '',388 'group_type' => $group_type, 196 389 'group_type__in' => '', 197 390 'group_type__not_in' => '', 198 391 'meta_query' => false, … … 5043 5236 } 5044 5237 5045 5238 /** 5239 * Echo the current group type message. 5240 * 5241 * @since 2.7.0 5242 */ 5243 function bp_current_group_directory_type_message() { 5244 echo bp_get_current_group_directory_type_message(); 5245 } 5246 /** 5247 * Generate the current group type message. 5248 * 5249 * @since 2.7.0 5250 * 5251 * @return string 5252 */ 5253 function bp_get_current_group_directory_type_message() { 5254 $type_object = bp_groups_get_group_type_object( bp_get_current_group_directory_type() ); 5255 5256 $message = sprintf( __( 'Viewing groups of the type: %s', 'buddypress' ), '<strong>' . $type_object->labels['singular_name'] . '</strong>' ); 5257 5258 /** 5259 * Filters the current group type message. 5260 * 5261 * @since 2.7.0 5262 * 5263 * @param string $message Message to filter. 5264 */ 5265 return apply_filters( 'bp_get_current_group_type_message', $message ); 5266 } 5267 5268 /** 5046 5269 * Is the current page a specific group admin screen? 5047 5270 * 5048 5271 * @since 1.1.0 -
src/bp-groups/classes/class-bp-groups-component.php
85 85 public $types = array(); 86 86 87 87 /** 88 * Current directory group type. 89 * 90 * @see groups_directory_groups_setup() 91 * 92 * @since 2.7.0 93 * @var string 94 */ 95 public $current_directory_type = ''; 96 97 /** 88 98 * Start the groups component creation process. 89 99 * 90 100 * @since 1.5.0 -
src/bp-groups/classes/class-bp-groups-theme-compat.php
40 40 return; 41 41 42 42 // Group Directory. 43 if ( ! bp_current_action() && ! bp_current_item() ) {43 if ( bp_is_groups_directory() ) { 44 44 bp_update_is_directory( true, 'groups' ); 45 45 46 46 /** -
src/bp-templates/bp-legacy/buddypress/groups/create.php
132 132 133 133 </fieldset> 134 134 135 <?php // Group type selection ?> 136 <?php if ( $group_types = bp_groups_get_group_types( array( 'has_directory' => true ), 'objects' ) ): ?> 137 138 <fieldset class="group-create-types"> 139 <legend><?php _e( 'Group Types', 'buddypress' ); ?></legend> 140 141 <p><?php _e( 'Select the types this group should be a part of.', 'buddypress' ); ?></p> 142 143 <?php foreach ( $group_types as $type ) : ?> 144 <div class="checkbox"> 145 <label for="<?php printf( 'group-type-%s', $type->name ); ?>"><input type="checkbox" name="group-types[]" id="<?php printf( 'group-type-%s', $type->name ); ?>" value="<?php esc_attr_e( $type->name ); ?>" /> <?php esc_html_e( $type->labels['name'] ); ?> 146 <?php 147 if ( isset( $type->description ) ) { 148 printf( __( '– %s', 'buddypress' ), '<span class="bp-group-type-desc">' . $type->description . '</span>' ); 149 } 150 ?> 151 </label> 152 </div> 153 154 <?php endforeach; ?> 155 156 </fieldset> 157 158 <?php endif; ?> 159 135 160 <fieldset class="group-create-invitations"> 136 161 137 162 <legend><?php _e( 'Group Invitations', 'buddypress' ); ?></legend> -
src/bp-templates/bp-legacy/buddypress/groups/groups-loop.php
19 19 */ 20 20 do_action( 'bp_before_groups_loop' ); ?> 21 21 22 <?php if ( bp_get_current_group_directory_type() ) : ?> 23 <p class="current-group-type"><?php bp_current_group_directory_type_message() ?></p> 24 <?php endif; ?> 25 22 26 <?php if ( bp_has_groups( bp_ajax_querystring( 'groups' ) ) ) : ?> 23 27 24 28 <div id="pag-top" class="pagination"> -
src/bp-templates/bp-legacy/buddypress/groups/single/admin.php
131 131 132 132 </fieldset> 133 133 134 <?php // Group type selection ?> 135 <?php if ( $group_types = bp_groups_get_group_types( array( 'has_directory' => true ), 'objects' ) ): ?> 136 137 <fieldset class="group-create-types"> 138 <legend><?php _e( 'Group Types', 'buddypress' ); ?></legend> 139 140 <p><?php _e( 'Select the types this group should be a part of.', 'buddypress' ); ?></p> 141 142 <?php foreach ( $group_types as $type ) : ?> 143 <div class="checkbox"> 144 <label for="<?php printf( 'group-type-%s', $type->name ); ?>"> 145 <input type="checkbox" name="group-types[]" id="<?php printf( 'group-type-%s', $type->name ); ?>" value="<?php esc_attr_e( $type->name ); ?>" <?php checked( bp_groups_has_group_type( bp_get_current_group_id(), $type->name ) ); ?>/> <?php esc_html_e( $type->labels['name'] ); ?> 146 <?php 147 if ( isset( $type->description ) ) { 148 printf( __( '– %s', 'buddypress' ), '<span class="bp-group-type-desc">' . $type->description . '</span>' ); 149 } 150 ?> 151 </label> 152 </div> 153 154 <?php endforeach; ?> 155 156 </fieldset> 157 158 <?php endif; ?> 159 134 160 <fieldset class="group-create-invitations"> 135 161 136 162 <legend><?php _e( 'Group Invitations', 'buddypress' ); ?></legend> -
src/bp-templates/bp-legacy/buddypress/groups/single/cover-image-header.php
63 63 64 64 <?php bp_group_description(); ?> 65 65 66 <?php bp_group_type_list(); ?> 66 67 </div> 67 68 </div><!-- #item-header-content --> 68 69 -
src/bp-templates/bp-legacy/buddypress/groups/single/group-header.php
83 83 84 84 <?php bp_group_description(); ?> 85 85 86 <?php bp_group_type_list(); ?> 87 86 88 <div id="item-buttons"> 87 89 88 90 <?php