Changeset 11144
- Timestamp:
- 09/21/2016 10:40:12 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-functions.php
r11142 r11144 2116 2116 * 2117 2117 * @since 2.6.0 2118 * @since 2.7.0 Introduce $has_directory, $show_in_create_screen, $show_in_list, and 2119 * $description as $args parameters. 2118 2120 * 2119 2121 * @param string $group_type Unique string identifier for the group type. … … 2121 2123 * Array of arguments describing the group type. 2122 2124 * 2123 * @type array $labels { 2125 * @type string|bool $has_directory Set the slug to be used for custom group directory page. eg. 2126 * example.com/groups/type/MY_SLUG. Default: false. 2127 * @type bool $show_in_create_screen Whether this group type is allowed to be selected on the group creation 2128 * page. Default: false. 2129 * @type bool|null $show_in_list Whether this group type should be shown in lists rendered by 2130 * bp_group_type_list(). Default: null. If $show_in_create_screen is true, 2131 * this will default to true, unless this is set explicitly to false. 2132 * @type string $description A short descriptive summary of what the group type is. Currently shown 2133 * on a group's "Manage > Settings" page when selecting group types. 2134 * @type array $labels { 2124 2135 * Array of labels to use in various parts of the interface. 2125 2136 * … … 2138 2149 2139 2150 $r = bp_parse_args( $args, array( 2140 'labels' => array(), 2151 'has_directory' => false, 2152 'show_in_create_screen' => false, 2153 'show_in_list' => null, 2154 'description' => '', 2155 'labels' => array(), 2141 2156 ), 'register_group_type' ); 2142 2157 … … 2168 2183 'singular_name' => $default_name, 2169 2184 ), $r['labels'] ); 2185 2186 // Directory slug. 2187 if ( ! empty( $r['has_directory'] ) ) { 2188 // A string value is intepreted as the directory slug. 2189 if ( is_string( $r['has_directory'] ) ) { 2190 $directory_slug = $r['has_directory']; 2191 2192 // Otherwise fall back on group type. 2193 } else { 2194 $directory_slug = $group_type; 2195 } 2196 2197 // Sanitize for use in URLs. 2198 $r['directory_slug'] = sanitize_title( $directory_slug ); 2199 $r['has_directory'] = true; 2200 } else { 2201 $r['directory_slug'] = ''; 2202 $r['has_directory'] = false; 2203 } 2204 2205 // Type lists. 2206 if ( true === $r['show_in_create_screen'] && is_null( $r['show_in_list'] ) ) { 2207 $r['show_in_list'] = true; 2208 } else { 2209 $r['show_in_list'] = (bool) $r['show_in_list']; 2210 } 2170 2211 2171 2212 $bp->groups->types[ $group_type ] = $type = (object) $r; -
trunk/tests/phpunit/testcases/groups/types.php
r11142 r11144 265 265 } 266 266 267 public function test_bp_groups_register_group_type_show_in_list_true_when_show_in_create_screen_true() { 268 $object = bp_groups_register_group_type( 'foo', array( 269 'show_in_create_screen' => true, 270 ) ); 271 272 $this->assertTrue( $object->show_in_list ); 273 } 274 275 public function test_bp_groups_register_group_type_show_in_list_false_when_show_in_create_screen_false() { 276 $object = bp_groups_register_group_type( 'foo', array( 277 'show_in_create_screen' => false, 278 ) ); 279 280 $this->assertFalse( $object->show_in_list ); 281 } 282 283 public function test_bp_groups_register_group_type_show_in_list_false_and_show_in_create_screen_true() { 284 $object = bp_groups_register_group_type( 'foo', array( 285 'show_in_create_screen' => true, 286 'show_in_list' => false, 287 ) ); 288 289 $this->assertFalse( $object->show_in_list ); 290 } 291 292 public function test_bp_groups_set_group_type_should_remove_types_when_passing_an_empty_value() { 293 $g = $this->factory->group->create( array( 'creator_id' => self::$u1 ) ); 294 bp_groups_register_group_type( 'foo' ); 295 bp_groups_set_group_type( $g, 'foo' ); 296 297 // Make sure it's set up. 298 $this->assertSame( 'foo', bp_groups_get_group_type( $g ) ); 299 300 $this->assertSame( array(), bp_groups_set_group_type( $g, '' ) ); 301 $this->assertFalse( bp_groups_get_group_type( $g ) ); 302 } 303 267 304 public function test_bp_groups_set_group_type_should_set_multiple_types_when_passing_array_of_types() { 268 305 $g = $this->factory->group->create( array( 'creator_id' => self::$u1 ) );
Note: See TracChangeset
for help on using the changeset viewer.