Changeset 13085 for trunk/src/bp-groups/bp-groups-functions.php
- Timestamp:
- 08/22/2021 12:38:43 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-functions.php
r12991 r13085 68 68 */ 69 69 return apply_filters( 'groups_get_group', $group ); 70 } 71 72 /** 73 * Retrieve group by a given field. 74 * 75 * @since 10.0.0 76 * 77 * @param string $field (Required) The field to use to retrieve the group. 78 * Possible values are `'id'` or `'slug'`. 79 * @param string|int $value (Required) A value for the $field. A Group ID or slug. 80 * @return BP_Groups_Group|false The Group object if found, false otherwise. 81 */ 82 function bp_get_group_by( $field, $value ) { 83 $group_id = $value; 84 85 if ( 'slug' === $field && is_string( $value ) ) { 86 $group_id = groups_get_id( $value ); 87 } 88 89 $group = groups_get_group( array( 'group_id' => (int) $group_id ) ); 90 91 if ( empty( $group->id ) ) { 92 return false; 93 } 94 95 return $group; 96 } 97 98 /** 99 * Retrieve a Group. 100 * 101 * When used into the context of a Groups loop built by the `BP_Groups_Template` class, it defaults to the 102 * Group being iterated on. 103 * 104 * @since 10.0.0 105 * 106 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object. 107 * Default: false. 108 * @return BP_Groups_Group|false The Group object if found, false otherwise. 109 */ 110 function bp_get_group( $group = false ) { 111 global $groups_template; 112 113 $group_obj = false; 114 115 if ( $group instanceof BP_Groups_Group ) { 116 $group_obj = $group; 117 } elseif ( is_string( $group ) ) { 118 $group_obj = bp_get_group_by( 'slug', $group ); 119 } elseif ( is_numeric( $group ) ) { 120 $group_obj = bp_get_group_by( 'id', $group ); 121 } elseif ( isset( $groups_template->group ) && is_object( $groups_template->group ) ) { 122 $group_obj = $groups_template->group; 123 } 124 125 return $group_obj; 70 126 } 71 127
Note: See TracChangeset
for help on using the changeset viewer.