| 1 |
<?php |
| 2 |
|
| 3 |
namespace Buddypress\CLI\Command; |
| 4 |
|
| 5 |
use WP_CLI\Fetchers\Base; |
| 6 |
|
| 7 |
/** |
| 8 |
* Fetch a BuddyPress group based on one of its attributes. |
| 9 |
*/ |
| 10 |
class Group_Fetcher extends Base { |
| 11 |
|
| 12 |
/** |
| 13 |
* @var string $msg Error message to use when invalid data is provided. |
| 14 |
*/ |
| 15 |
protected $msg = 'Could not find the group with ID %d.'; |
| 16 |
|
| 17 |
/** |
| 18 |
* Get a group ID from its identifier (ID or slug). |
| 19 |
* |
| 20 |
* @param int|string $arg Group ID or slug. |
| 21 |
* @return BP_Groups_Group|bool |
| 22 |
*/ |
| 23 |
public function get( $arg ) { |
| 24 |
|
| 25 |
// Group ID or slug. |
| 26 |
if ( ! is_numeric( $arg ) ) { |
| 27 |
$arg = groups_get_id( $arg ); |
| 28 |
} |
| 29 |
|
| 30 |
// Get group object. |
| 31 |
$group = groups_get_group( |
| 32 |
[ 'group_id' => $arg ] |
| 33 |
); |
| 34 |
|
| 35 |
if ( empty( $group->id ) ) { |
| 36 |
return false; |
| 37 |
} |
| 38 |
|
| 39 |
return $group; |
| 40 |
} |
| 41 |
} |
| 42 |
|