From 5124e01b0d171c492da55564d00f62749b424efe Mon Sep 17 00:00:00 2001 From: Christian Wach Date: Wed, 6 Mar 2019 17:23:55 +0000 Subject: [PATCH] Add methods to retrieve "Groups" group data with CiviCRM group IDs --- includes/civicrm-groups-sync-wordpress.php | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/includes/civicrm-groups-sync-wordpress.php b/includes/civicrm-groups-sync-wordpress.php index 33375ab..bd2328f 100644 --- a/includes/civicrm-groups-sync-wordpress.php +++ b/includes/civicrm-groups-sync-wordpress.php @@ -373,6 +373,63 @@ class CiviCRM_Groups_Sync_WordPress { + /** + * Get a "Groups" group using a CiviCRM group ID. + * + * @since 0.1 + * + * @param int $civicrm_group_id The ID of the CiviCRM group. + * @return array|bool $wp_group The "Groups" group data, or false on failure. + */ + public function group_get_by_civicrm_id( $civicrm_group_id ) { + + // Get the ID of the "Groups" group. + $wp_group_id = $this->plugin->civicrm->group_get_wp_id_by_civicrm_id( $civicrm_group_id ); + + // Sanity check. + if ( empty( $wp_group_id ) ) { + return false; + } + + // Get full group data. + $wp_group = Groups_Group::read( $wp_group_id ); + + // --< + return $wp_group; + + } + + + + /** + * Get a "Groups" group ID using a CiviCRM group ID. + * + * @since 0.1 + * + * @param int $civicrm_group_id The ID of the CiviCRM group. + * @return int|bool $group_id The "Groups" group ID, or false on failure. + */ + public function group_get_wp_id_by_civicrm_id( $civicrm_group_id ) { + + // Get the "Groups" group. + $wp_group = $this->group_get_by_civicrm_id( $civicrm_group_id ); + + // Sanity check. + if ( empty( $wp_group ) ) { + return false; + } + + // --< + return $wp_group['group_id']; + + } + + + + //########################################################################## + + + /** * Filter the Add Group form. * -- GitLab