[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-groups/ -> bp-groups-notifications.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Groups Notification Functions.
   4   *
   5   * These functions handle the recording, deleting and formatting of notifications
   6   * for the user and for this specific component.
   7   *
   8   * @package BuddyPress
   9   * @subpackage GroupsActivity
  10   * @since 1.0.0
  11   */
  12  
  13  // Exit if accessed directly.
  14  defined( 'ABSPATH' ) || exit;
  15  
  16  /** Emails ********************************************************************/
  17  
  18  /**
  19   * Notify all group members when a group is updated.
  20   *
  21   * @since 1.0.0
  22   *
  23   * @param int                  $group_id  ID of the group.
  24   * @param BP_Groups_Group|null $old_group Group before new details were saved.
  25   */
  26  function groups_notification_group_updated( $group_id = 0, $old_group = null ) {
  27      $group = groups_get_group( $group_id );
  28  
  29      if ( $old_group instanceof BP_Groups_Group ) {
  30          $changed = array();
  31  
  32          if ( $group->name !== $old_group->name ) {
  33              $changed[] = sprintf(
  34                  /* translators: 1: the old group name. 2: the new group name. */
  35                  _x( '* Name changed from "%1$s" to "%2$s".', 'Group update email text', 'buddypress' ),
  36                  esc_html( $old_group->name ),
  37                  esc_html( $group->name )
  38              );
  39          }
  40  
  41          if ( $group->description !== $old_group->description ) {
  42              $changed[] = sprintf(
  43                  /* translators: 1: the old group description. 2: the new group description. */
  44                  _x( '* Description changed from "%1$s" to "%2$s".', 'Group update email text', 'buddypress' ),
  45                  esc_html( $old_group->description ),
  46                  esc_html( $group->description )
  47              );
  48          }
  49  
  50          if ( $group->slug !== $old_group->slug ) {
  51              $changed[] = sprintf(
  52                  /* translators: 1: the old group permalink. 2: the new group permalink. */
  53                  _x( '* Permalink changed from "%1$s" to "%2$s".', 'Group update email text', 'buddypress' ),
  54                  esc_url( bp_get_group_permalink( $old_group ) ),
  55                  esc_url( bp_get_group_permalink( $group ) )
  56              );
  57          }
  58      }
  59  
  60      /**
  61       * Filters the bullet points listing updated items in the email notification after a group is updated.
  62       *
  63       * @since 2.2.0
  64       *
  65       * @param array $changed Array of bullet points.
  66       */
  67      $changed = apply_filters( 'groups_notification_group_update_updated_items', $changed );
  68  
  69      $changed_text = '';
  70      if ( ! empty( $changed ) ) {
  71          $changed_text = implode( "\n", $changed );
  72      }
  73  
  74      $user_ids = BP_Groups_Member::get_group_member_ids( $group->id );
  75      foreach ( (array) $user_ids as $user_id ) {
  76  
  77          // Continue if member opted out of receiving this email.
  78          if ( 'no' === bp_get_user_meta( $user_id, 'notification_groups_group_updated', true ) ) {
  79              continue;
  80          }
  81  
  82          $unsubscribe_args = array(
  83              'user_id'           => $user_id,
  84              'notification_type' => 'groups-details-updated',
  85          );
  86  
  87          $args = array(
  88              'tokens' => array(
  89                  'changed_text' => $changed_text,
  90                  'group'        => $group,
  91                  'group.id'     => $group_id,
  92                  'group.url'    => esc_url( bp_get_group_permalink( $group ) ),
  93                  'group.name'   => $group->name,
  94                  'unsubscribe'  => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
  95              ),
  96          );
  97          bp_send_email( 'groups-details-updated', (int) $user_id, $args );
  98      }
  99  
 100      /**
 101       * Fires after the notification is sent that a group has been updated.
 102       *
 103       * See https://buddypress.trac.wordpress.org/ticket/3644 for blank message parameter.
 104       *
 105       * @since 1.5.0
 106       * @since 2.5.0 $subject has been unset and is deprecated.
 107       *
 108       * @param array  $user_ids Array of user IDs to notify about the update.
 109       * @param string $subject  Deprecated in 2.5; now an empty string.
 110       * @param string $value    Empty string preventing PHP error.
 111       * @param int    $group_id ID of the group that was updated.
 112       */
 113      do_action( 'bp_groups_sent_updated_email', $user_ids, '', '', $group_id );
 114  }
 115  
 116  /**
 117   * Notify group admin about new membership request.
 118   *
 119   * @since 1.0.0
 120   *
 121   * @param int $requesting_user_id ID of the user requesting group membership.
 122   * @param int $admin_id           ID of the group admin.
 123   * @param int $group_id           ID of the group.
 124   * @param int $membership_id      ID of the group membership object.
 125   */
 126  function groups_notification_new_membership_request( $requesting_user_id = 0, $admin_id = 0, $group_id = 0, $membership_id = 0 ) {
 127  
 128      // Trigger a BuddyPress Notification.
 129      if ( bp_is_active( 'notifications' ) ) {
 130          bp_notifications_add_notification( array(
 131              'user_id'           => $admin_id,
 132              'item_id'           => $group_id,
 133              'secondary_item_id' => $requesting_user_id,
 134              'component_name'    => buddypress()->groups->id,
 135              'component_action'  => 'new_membership_request',
 136          ) );
 137      }
 138  
 139      // Bail if member opted out of receiving this email.
 140      if ( 'no' === bp_get_user_meta( $admin_id, 'notification_groups_membership_request', true ) ) {
 141          return;
 142      }
 143  
 144      $unsubscribe_args = array(
 145          'user_id'           => $admin_id,
 146          'notification_type' => 'groups-membership-request',
 147      );
 148  
 149      $request_message = '';
 150      $requests = groups_get_requests( $args = array(
 151          'user_id'    => $requesting_user_id,
 152          'item_id'    => $group_id,
 153      ) );
 154  
 155      if ( $requests ) {
 156          $request_message = current( $requests )->content;
 157  
 158          if ( $request_message ) {
 159              $request_message = "\n" . $request_message . "\n";
 160          }
 161      }
 162  
 163      $group = groups_get_group( $group_id );
 164      $args  = array(
 165          'tokens' => array(
 166              'admin.id'             => $admin_id,
 167              'group'                => $group,
 168              'group.name'           => $group->name,
 169              'group.id'             => $group_id,
 170              'group-requests.url'   => esc_url( bp_get_group_permalink( $group ) . 'admin/membership-requests' ),
 171              'profile.url'          => esc_url( bp_core_get_user_domain( $requesting_user_id ) ),
 172              'requesting-user.id'   => $requesting_user_id,
 173              'requesting-user.name' => bp_core_get_user_displayname( $requesting_user_id ),
 174              'request.message'      => $request_message,
 175              'unsubscribe'          => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
 176          ),
 177      );
 178      bp_send_email( 'groups-membership-request', (int) $admin_id, $args );
 179  }
 180  
 181  /**
 182   * Notify member about their group membership request.
 183   *
 184   * @since 1.0.0
 185   *
 186   * @param int  $requesting_user_id ID of the user requesting group membership.
 187   * @param int  $group_id           ID of the group.
 188   * @param bool $accepted           Optional. Whether the membership request was accepted.
 189   *                                 Default: true.
 190   */
 191  function groups_notification_membership_request_completed( $requesting_user_id = 0, $group_id = 0, $accepted = true ) {
 192  
 193      // Trigger a BuddyPress Notification.
 194      if ( bp_is_active( 'notifications' ) ) {
 195  
 196          // What type of acknowledgement.
 197          $type = ! empty( $accepted ) ? 'membership_request_accepted' : 'membership_request_rejected';
 198  
 199          bp_notifications_add_notification( array(
 200              'user_id'           => $requesting_user_id,
 201              'item_id'           => $group_id,
 202              'component_name'    => buddypress()->groups->id,
 203              'component_action'  => $type,
 204          ) );
 205      }
 206  
 207      // Bail if member opted out of receiving this email.
 208      if ( 'no' === bp_get_user_meta( $requesting_user_id, 'notification_membership_request_completed', true ) ) {
 209          return;
 210      }
 211  
 212      $group = groups_get_group( $group_id );
 213      $args  = array(
 214          'tokens' => array(
 215              'group'              => $group,
 216              'group.id'           => $group_id,
 217              'group.name'         => $group->name,
 218              'group.url'          => esc_url( bp_get_group_permalink( $group ) ),
 219              'requesting-user.id' => $requesting_user_id,
 220          ),
 221      );
 222  
 223      if ( ! empty( $accepted ) ) {
 224  
 225          $unsubscribe_args = array(
 226              'user_id'           => $requesting_user_id,
 227              'notification_type' => 'groups-membership-request-accepted',
 228          );
 229  
 230          $args['tokens']['unsubscribe'] = esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) );
 231  
 232          bp_send_email( 'groups-membership-request-accepted', (int) $requesting_user_id, $args );
 233  
 234      } else {
 235  
 236          $unsubscribe_args = array(
 237              'user_id'           => $requesting_user_id,
 238              'notification_type' => 'groups-membership-request-rejected',
 239          );
 240  
 241          $args['tokens']['unsubscribe'] = esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) );
 242  
 243          bp_send_email( 'groups-membership-request-rejected', (int) $requesting_user_id, $args );
 244      }
 245  }
 246  add_action( 'groups_membership_accepted', 'groups_notification_membership_request_completed', 10, 3 );
 247  add_action( 'groups_membership_rejected', 'groups_notification_membership_request_completed', 10, 3 );
 248  
 249  /**
 250   * Notify group member they have been promoted.
 251   *
 252   * @since 1.0.0
 253   *
 254   * @param int $user_id  ID of the user.
 255   * @param int $group_id ID of the group.
 256   */
 257  function groups_notification_promoted_member( $user_id = 0, $group_id = 0 ) {
 258  
 259      // What type of promotion is this?
 260      if ( groups_is_user_admin( $user_id, $group_id ) ) {
 261          $promoted_to = __( 'an administrator', 'buddypress' );
 262          $type        = 'member_promoted_to_admin';
 263      } else {
 264          $promoted_to = __( 'a moderator', 'buddypress' );
 265          $type        = 'member_promoted_to_mod';
 266      }
 267  
 268      // Trigger a BuddyPress Notification.
 269      if ( bp_is_active( 'notifications' ) ) {
 270          bp_notifications_add_notification( array(
 271              'user_id'           => $user_id,
 272              'item_id'           => $group_id,
 273              'component_name'    => buddypress()->groups->id,
 274              'component_action'  => $type,
 275          ) );
 276      }
 277  
 278      // Bail if admin opted out of receiving this email.
 279      if ( 'no' === bp_get_user_meta( $user_id, 'notification_groups_admin_promotion', true ) ) {
 280          return;
 281      }
 282  
 283      $unsubscribe_args = array(
 284          'user_id'           => $user_id,
 285          'notification_type' => 'groups-member-promoted',
 286      );
 287  
 288      $group = groups_get_group( $group_id );
 289      $args  = array(
 290          'tokens' => array(
 291              'group'       => $group,
 292              'group.id'    => $group_id,
 293              'group.url'   => esc_url( bp_get_group_permalink( $group ) ),
 294              'group.name'  => $group->name,
 295              'promoted_to' => $promoted_to,
 296              'user.id'     => $user_id,
 297              'unsubscribe' => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
 298          ),
 299      );
 300      bp_send_email( 'groups-member-promoted', (int) $user_id, $args );
 301  }
 302  add_action( 'groups_promoted_member', 'groups_notification_promoted_member', 10, 2 );
 303  
 304  /**
 305   * Notify a member they have been invited to a group.
 306   *
 307   * @since 1.0.0
 308   *
 309   * @param BP_Groups_Group      $group           Group object.
 310   * @param BP_Groups_Member|int $member          Member object or invited_user_id.
 311   * @param int                  $inviter_user_id ID of the user who sent the invite.
 312   */
 313  function groups_notification_group_invites( &$group, &$member, $inviter_user_id ) {
 314  
 315      // @todo $inviter_ud may be used for caching, test without it
 316      $inviter_ud      = bp_core_get_core_userdata( $inviter_user_id );
 317  
 318      if ( $member instanceof BP_Groups_Member ) {
 319          $invited_user_id = $member->user_id;
 320      } else if ( is_int( $member ) ) {
 321          $invited_user_id = $member;
 322      }
 323  
 324      // Trigger a BuddyPress Notification.
 325      if ( bp_is_active( 'notifications' ) ) {
 326          bp_notifications_add_notification( array(
 327              'user_id'          => $invited_user_id,
 328              'item_id'          => $group->id,
 329              'component_name'   => buddypress()->groups->id,
 330              'component_action' => 'group_invite',
 331          ) );
 332      }
 333  
 334      // Bail if member opted out of receiving this email.
 335      if ( 'no' === bp_get_user_meta( $invited_user_id, 'notification_groups_invite', true ) ) {
 336          return;
 337      }
 338  
 339      $invited_link = bp_core_get_user_domain( $invited_user_id ) . bp_get_groups_slug();
 340  
 341      $unsubscribe_args = array(
 342          'user_id'           => $invited_user_id,
 343          'notification_type' => 'groups-invitation',
 344      );
 345  
 346      $invite_message = '';
 347      $invitations = groups_get_invites( $args = array(
 348          'user_id'    => $invited_user_id,
 349          'item_id'    => $group->id,
 350          'inviter_id' => $inviter_user_id,
 351      ) );
 352      if ( $invitations ) {
 353          $invite_message = current( $invitations )->content;
 354      }
 355  
 356      $args         = array(
 357          'tokens' => array(
 358              'group'          => $group,
 359              'group.url'      => bp_get_group_permalink( $group ),
 360              'group.name'     => $group->name,
 361              'inviter.name'   => bp_core_get_userlink( $inviter_user_id, true, false, true ),
 362              'inviter.url'    => bp_core_get_user_domain( $inviter_user_id ),
 363              'inviter.id'     => $inviter_user_id,
 364              'invites.url'    => esc_url( $invited_link . '/invites/' ),
 365              'invite.message' => $invite_message,
 366              'unsubscribe'    => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
 367          ),
 368      );
 369  
 370      bp_send_email( 'groups-invitation', (int) $invited_user_id, $args );
 371  }
 372  
 373  /** Notifications *************************************************************/
 374  
 375  /**
 376   * Format notifications for the Groups component.
 377   *
 378   * @since 1.0.0
 379   *
 380   * @param string $action            The kind of notification being rendered.
 381   * @param int    $item_id           The primary item ID.
 382   * @param int    $secondary_item_id The secondary item ID.
 383   * @param int    $total_items       The total number of messaging-related notifications
 384   *                                  waiting for the user.
 385   * @param string $format            'string' for notification HTML link or 'array' for separate link and text.
 386   *                                  for WP Toolbar. Default: 'string'.
 387   * @return string
 388   */
 389  function groups_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
 390  
 391      switch ( $action ) {
 392          case 'new_membership_request':
 393              $group_id = $item_id;
 394              $requesting_user_id = $secondary_item_id;
 395  
 396              $group = groups_get_group( $group_id );
 397              $group_link = bp_get_group_permalink( $group );
 398              $amount = 'single';
 399  
 400              // Set up the string and the filter
 401              // because different values are passed to the filters,
 402              // we'll return values inline.
 403              if ( (int) $total_items > 1 ) {
 404                  /* translators: 1: number of group membership requests. 2: group name. */
 405                  $text = sprintf( __( '%1$d new membership requests for the group "%2$s"', 'buddypress' ), (int) $total_items, $group->name );
 406                  $amount = 'multiple';
 407                  $notification_link = $group_link . 'admin/membership-requests/?n=1';
 408  
 409                  if ( 'string' == $format ) {
 410  
 411                      /**
 412                       * Filters groups multiple new membership request notification for string format.
 413                       *
 414                       * This is a dynamic filter that is dependent on item count and action.
 415                       * Complete filter - bp_groups_multiple_new_membership_requests_notification.
 416                       *
 417                       * @since 1.0.0
 418                       *
 419                       * @param string $string            HTML anchor tag for request.
 420                       * @param string $group_link        The permalink for the group.
 421                       * @param int    $total_items       Total number of membership requests.
 422                       * @param string $group->name       Name of the group.
 423                       * @param string $text              Notification content.
 424                       * @param string $notification_link The permalink for notification.
 425                       */
 426                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . 's_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $total_items, $group->name, $text, $notification_link );
 427                  } else {
 428  
 429                      /**
 430                       * Filters groups multiple new membership request notification for any non-string format.
 431                       *
 432                       * This is a dynamic filter that is dependent on item count and action.
 433                       * Complete filter - bp_groups_multiple_new_membership_requests_notification.
 434                       *
 435                       * @since 1.0.0
 436                       *
 437                       * @param array  $array             Array holding permalink and content for notification.
 438                       * @param string $group_link        The permalink for the group.
 439                       * @param int    $total_items       Total number of membership requests.
 440                       * @param string $group->name       Name of the group.
 441                       * @param string $text              Notification content.
 442                       * @param string $notification_link The permalink for notification.
 443                       */
 444                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . 's_notification', array(
 445                          'link' => $notification_link,
 446                          'text' => $text
 447                      ), $group_link, $total_items, $group->name, $text, $notification_link );
 448                  }
 449              } else {
 450                  $user_fullname = bp_core_get_user_displayname( $requesting_user_id );
 451                  /* translators: %s: member name */
 452                  $text = sprintf( __( '%s requests group membership', 'buddypress' ), $user_fullname );
 453                  $notification_link = $group_link . 'admin/membership-requests/?n=1';
 454  
 455                  if ( 'string' == $format ) {
 456  
 457                      /**
 458                       * Filters groups single new membership request notification for string format.
 459                       *
 460                       * This is a dynamic filter that is dependent on item count and action.
 461                       * Complete filter - bp_groups_single_new_membership_request_notification.
 462                       *
 463                       * @since 1.0.0
 464                       *
 465                       * @param string $string            HTML anchor tag for request.
 466                       * @param string $group_link        The permalink for the group.
 467                       * @param string $user_fullname     Full name of requesting user.
 468                       * @param string $group->name       Name of the group.
 469                       * @param string $text              Notification content.
 470                       * @param string $notification_link The permalink for notification.
 471                       */
 472                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $user_fullname, $group->name, $text, $notification_link );
 473                  } else {
 474  
 475                      /**
 476                       * Filters groups single new membership request notification for any non-string format.
 477                       *
 478                       * This is a dynamic filter that is dependent on item count and action.
 479                       * Complete filter - bp_groups_single_new_membership_request_notification.
 480                       *
 481                       * @since 1.0.0
 482                       *
 483                       * @param array  $array             Array holding permalink and content for notification.
 484                       * @param string $group_link        The permalink for the group.
 485                       * @param string $user_fullname     Full name of requesting user.
 486                       * @param string $group->name       Name of the group.
 487                       * @param string $text              Notification content.
 488                       * @param string $notification_link The permalink for notification.
 489                       */
 490                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', array(
 491                          'link' => $notification_link,
 492                          'text' => $text
 493                      ), $group_link, $user_fullname, $group->name, $text, $notification_link );
 494                  }
 495              }
 496  
 497              break;
 498  
 499          case 'membership_request_accepted':
 500              $group_id = $item_id;
 501  
 502              $group = groups_get_group( $group_id );
 503              $group_link = bp_get_group_permalink( $group );
 504              $amount = 'single';
 505  
 506              if ( (int) $total_items > 1 ) {
 507                  /* translators: 1: number of accepted group membership requests. 2: group name. */
 508                  $text = sprintf( __( '%1$d accepted group membership requests for the group "%2$s"', 'buddypress' ), (int) $total_items, $group->name );
 509                  $amount = 'multiple';
 510                  $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1';
 511  
 512                  if ( 'string' == $format ) {
 513  
 514                      /**
 515                       * Filters multiple accepted group membership requests notification for string format.
 516                       * Complete filter - bp_groups_multiple_membership_request_accepted_notification.
 517                       *
 518                       * @since 1.0.0
 519                       *
 520                       * @param string $string            HTML anchor tag for notification.
 521                       * @param int    $total_items       Total number of accepted requests.
 522                       * @param string $group->name       Name of the group.
 523                       * @param string $text              Notification content.
 524                       * @param string $notification_link The permalink for notification.
 525                       */
 526                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $total_items, $group->name, $text, $notification_link );
 527                  } else {
 528  
 529                      /**
 530                       * Filters multiple accepted group membership requests notification for non-string format.
 531                       * Complete filter - bp_groups_multiple_membership_request_accepted_notification.
 532                       *
 533                       * @since 1.0.0
 534                       *
 535                       * @param array  $array             Array holding permalink and content for notification
 536                       * @param int    $total_items       Total number of accepted requests.
 537                       * @param string $group->name       Name of the group.
 538                       * @param string $text              Notification content.
 539                       * @param string $notification_link The permalink for notification.
 540                       */
 541                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', array(
 542                          'link' => $notification_link,
 543                          'text' => $text
 544                      ), $total_items, $group->name, $text, $notification_link );
 545                  }
 546              } else {
 547                  /* translators: %s: group name. */
 548                  $text = sprintf( __( 'Membership for group "%s" accepted', 'buddypress' ), $group->name );
 549                  $filter = 'bp_groups_single_membership_request_accepted_notification';
 550                  $notification_link = $group_link . '?n=1';
 551  
 552                  if ( 'string' == $format ) {
 553  
 554                      /**
 555                       * Filters single accepted group membership request notification for string format.
 556                       * Complete filter - bp_groups_single_membership_request_accepted_notification.
 557                       *
 558                       * @since 1.0.0
 559                       *
 560                       * @param string $string            HTML anchor tag for notification.
 561                       * @param string $group_link        The permalink for the group.
 562                       * @param string $group->name       Name of the group.
 563                       * @param string $text              Notification content.
 564                       * @param string $notification_link The permalink for notification.
 565                       */
 566                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link );
 567                  } else {
 568  
 569                      /**
 570                       * Filters single accepted group membership request notification for non-string format.
 571                       * Complete filter - bp_groups_single_membership_request_accepted_notification.
 572                       *
 573                       * @since 1.0.0
 574                       *
 575                       * @param array  $array             Array holding permalink and content for notification.
 576                       * @param string $group_link        The permalink for the group.
 577                       * @param string $group->name       Name of the group.
 578                       * @param string $text              Notification content.
 579                       * @param string $notification_link The permalink for notification.
 580                       */
 581                      return apply_filters( $filter, array(
 582                          'link' => $notification_link,
 583                          'text' => $text
 584                      ), $group_link, $group->name, $text, $notification_link );
 585                  }
 586              }
 587  
 588              break;
 589  
 590          case 'membership_request_rejected':
 591              $group_id = $item_id;
 592  
 593              $group = groups_get_group( $group_id );
 594              $group_link = bp_get_group_permalink( $group );
 595              $amount = 'single';
 596  
 597              if ( (int) $total_items > 1 ) {
 598                  /* translators: 1: number of accepted group membership requests. 2: group name. */
 599                  $text = sprintf( __( '%1$d rejected group membership requests for the group "%2$s"', 'buddypress' ), (int) $total_items, $group->name );
 600                  $amount = 'multiple';
 601                  $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1';
 602  
 603                  if ( 'string' == $format ) {
 604  
 605                      /**
 606                       * Filters multiple rejected group membership requests notification for string format.
 607                       * Complete filter - bp_groups_multiple_membership_request_rejected_notification.
 608                       *
 609                       * @since 1.0.0
 610                       *
 611                       * @param string $string            HTML anchor tag for notification.
 612                       * @param int    $total_items       Total number of rejected requests.
 613                       * @param string $group->name       Name of the group.
 614                       * @param string $text              Notification content.
 615                       * @param string $notification_link The permalink for notification.
 616                       */
 617                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $total_items, $group->name, $text, $notification_link );
 618                  } else {
 619  
 620                      /**
 621                       * Filters multiple rejected group membership requests notification for non-string format.
 622                       * Complete filter - bp_groups_multiple_membership_request_rejected_notification.
 623                       *
 624                       * @since 1.0.0
 625                       *
 626                       * @param array  $array             Array holding permalink and content for notification.
 627                       * @param int    $total_items       Total number of rejected requests.
 628                       * @param string $group->name       Name of the group.
 629                       * @param string $text              Notification content.
 630                       * @param string $notification_link The permalink for notification.
 631                       */
 632                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', array(
 633                          'link' => $notification_link,
 634                          'text' => $text
 635                      ), $total_items, $group->name, $text, $notification_link );
 636                  }
 637              } else {
 638                  /* translators: %s: group name. */
 639                  $text = sprintf( __( 'Membership for group "%s" rejected', 'buddypress' ), $group->name );
 640                  $notification_link = $group_link . '?n=1';
 641  
 642                  if ( 'string' == $format ) {
 643  
 644                      /**
 645                       * Filters single rejected group membership requests notification for string format.
 646                       * Complete filter - bp_groups_single_membership_request_rejected_notification.
 647                       *
 648                       * @since 1.0.0
 649                       *
 650                       * @param string $string            HTML anchor tag for notification.
 651                       * @param int    $group_link        The permalink for the group.
 652                       * @param string $group->name       Name of the group.
 653                       * @param string $text              Notification content.
 654                       * @param string $notification_link The permalink for notification.
 655                       */
 656                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link );
 657                  } else {
 658  
 659                      /**
 660                       * Filters single rejected group membership requests notification for non-string format.
 661                       * Complete filter - bp_groups_single_membership_request_rejected_notification.
 662                       *
 663                       * @since 1.0.0
 664                       *
 665                       * @param array  $array             Array holding permalink and content for notification.
 666                       * @param int    $group_link        The permalink for the group.
 667                       * @param string $group->name       Name of the group.
 668                       * @param string $text              Notification content.
 669                       * @param string $notification_link The permalink for notification.
 670                       */
 671                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', array(
 672                          'link' => $notification_link,
 673                          'text' => $text
 674                      ), $group_link, $group->name, $text, $notification_link );
 675                  }
 676              }
 677  
 678              break;
 679  
 680          case 'member_promoted_to_admin':
 681              $group_id = $item_id;
 682  
 683              $group = groups_get_group( $group_id );
 684              $group_link = bp_get_group_permalink( $group );
 685              $amount = 'single';
 686  
 687              if ( (int) $total_items > 1 ) {
 688                  /* translators: %d: number of groups the user has been promoted admin for */
 689                  $text = sprintf( __( 'You were promoted to an admin in %d groups', 'buddypress' ), (int) $total_items );
 690                  $amount = 'multiple';
 691                  $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1';
 692  
 693                  if ( 'string' == $format ) {
 694                      /**
 695                       * Filters multiple promoted to group admin notification for string format.
 696                       * Complete filter - bp_groups_multiple_member_promoted_to_admin_notification.
 697                       *
 698                       * @since 1.0.0
 699                       *
 700                       * @param string $string            HTML anchor tag for notification.
 701                       * @param int    $total_items       Total number of rejected requests.
 702                       * @param string $text              Notification content.
 703                       * @param string $notification_link The permalink for notification.
 704                       */
 705                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $total_items, $text, $notification_link );
 706                  } else {
 707                      /**
 708                       * Filters multiple promoted to group admin notification for non-string format.
 709                       * Complete filter - bp_groups_multiple_member_promoted_to_admin_notification.
 710                       *
 711                       * @since 1.0.0
 712                       *
 713                       * @param array  $array             Array holding permalink and content for notification.
 714                       * @param int    $total_items       Total number of rejected requests.
 715                       * @param string $text              Notification content.
 716                       * @param string $notification_link The permalink for notification.
 717                       */
 718                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', array(
 719                          'link' => $notification_link,
 720                          'text' => $text
 721                      ), $total_items, $text, $notification_link );
 722                  }
 723              } else {
 724                  /* translators: %s: group name. */
 725                  $text = sprintf( __( 'You were promoted to an admin in the group "%s"', 'buddypress' ), $group->name );
 726                  $notification_link = $group_link . '?n=1';
 727  
 728                  if ( 'string' == $format ) {
 729                      /**
 730                       * Filters single promoted to group admin notification for non-string format.
 731                       * Complete filter - bp_groups_single_member_promoted_to_admin_notification.
 732                       *
 733                       * @since 1.0.0
 734                       *
 735                       * @param string $string            HTML anchor tag for notification.
 736                       * @param int    $group_link        The permalink for the group.
 737                       * @param string $group->name       Name of the group.
 738                       * @param string $text              Notification content.
 739                       * @param string $notification_link The permalink for notification.
 740                       */
 741                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link );
 742                  } else {
 743                      /**
 744                       * Filters single promoted to group admin notification for non-string format.
 745                       * Complete filter - bp_groups_single_member_promoted_to_admin_notification.
 746                       *
 747                       * @since 1.0.0
 748                       *
 749                       * @param array  $array             Array holding permalink and content for notification.
 750                       * @param int    $group_link        The permalink for the group.
 751                       * @param string $group->name       Name of the group.
 752                       * @param string $text              Notification content.
 753                       * @param string $notification_link The permalink for notification.
 754                       */
 755                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', array(
 756                          'link' => $notification_link,
 757                          'text' => $text
 758                      ), $group_link, $group->name, $text, $notification_link );
 759                  }
 760              }
 761  
 762              break;
 763  
 764          case 'member_promoted_to_mod':
 765              $group_id = $item_id;
 766  
 767              $group = groups_get_group( $group_id );
 768              $group_link = bp_get_group_permalink( $group );
 769              $amount = 'single';
 770  
 771              if ( (int) $total_items > 1 ) {
 772                  /* translators: %d: number of groups the user has been promoted mod for */
 773                  $text = sprintf( __( 'You were promoted to a mod in %d groups', 'buddypress' ), (int) $total_items );
 774                  $amount = 'multiple';
 775                  $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1';
 776  
 777                  if ( 'string' == $format ) {
 778                      /**
 779                       * Filters multiple promoted to group mod notification for string format.
 780                       * Complete filter - bp_groups_multiple_member_promoted_to_mod_notification.
 781                       *
 782                       * @since 1.0.0
 783                       *
 784                       * @param string $string            HTML anchor tag for notification.
 785                       * @param int    $total_items       Total number of rejected requests.
 786                       * @param string $text              Notification content.
 787                       * @param string $notification_link The permalink for notification.
 788                       */
 789                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $total_items, $text, $notification_link );
 790                  } else {
 791                      /**
 792                       * Filters multiple promoted to group mod notification for non-string format.
 793                       * Complete filter - bp_groups_multiple_member_promoted_to_mod_notification.
 794                       *
 795                       * @since 1.0.0
 796                       *
 797                       * @param array  $array             Array holding permalink and content for notification.
 798                       * @param int    $total_items       Total number of rejected requests.
 799                       * @param string $text              Notification content.
 800                       * @param string $notification_link The permalink for notification.
 801                       */
 802                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', array(
 803                          'link' => $notification_link,
 804                          'text' => $text
 805                      ), $total_items, $text, $notification_link );
 806                  }
 807              } else {
 808                  /* translators: %s: group name. */
 809                  $text = sprintf( __( 'You were promoted to a mod in the group "%s"', 'buddypress' ), $group->name );
 810                  $notification_link = $group_link . '?n=1';
 811  
 812                  if ( 'string' == $format ) {
 813                      /**
 814                       * Filters single promoted to group mod notification for string format.
 815                       * Complete filter - bp_groups_single_member_promoted_to_mod_notification.
 816                       *
 817                       * @since 1.0.0
 818                       *
 819                       * @param string $string            HTML anchor tag for notification.
 820                       * @param int    $group_link        The permalink for the group.
 821                       * @param string $group->name       Name of the group.
 822                       * @param string $text              Notification content.
 823                       * @param string $notification_link The permalink for notification.
 824                       */
 825                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link );
 826                  } else {
 827                      /**
 828                       * Filters single promoted to group admin notification for non-string format.
 829                       * Complete filter - bp_groups_single_member_promoted_to_mod_notification.
 830                       *
 831                       * @since 1.0.0
 832                       *
 833                       * @param array  $array             Array holding permalink and content for notification.
 834                       * @param int    $group_link        The permalink for the group.
 835                       * @param string $group->name       Name of the group.
 836                       * @param string $text              Notification content.
 837                       * @param string $notification_link The permalink for notification.
 838                       */
 839                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', array(
 840                          'link' => $notification_link,
 841                          'text' => $text
 842                      ), $group_link, $group->name, $text, $notification_link );
 843                  }
 844              }
 845  
 846              break;
 847  
 848          case 'group_invite':
 849              $group_id = $item_id;
 850              $group = groups_get_group( $group_id );
 851              $group_link = bp_get_group_permalink( $group );
 852              $amount = 'single';
 853  
 854              $notification_link = bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/?n=1';
 855  
 856              if ( (int) $total_items > 1 ) {
 857                  /* translators: %d: number of group invites */
 858                  $text = sprintf( __( 'You have %d new group invitations', 'buddypress' ), (int) $total_items );
 859                  $amount = 'multiple';
 860  
 861                  if ( 'string' == $format ) {
 862                      /**
 863                       * Filters multiple group invitation notification for string format.
 864                       * Complete filter - bp_groups_multiple_group_invite_notification.
 865                       *
 866                       * @since 1.0.0
 867                       *
 868                       * @param string $string            HTML anchor tag for notification.
 869                       * @param int    $total_items       Total number of rejected requests.
 870                       * @param string $text              Notification content.
 871                       * @param string $notification_link The permalink for notification.
 872                       */
 873                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $total_items, $text, $notification_link );
 874                  } else {
 875                      /**
 876                       * Filters multiple group invitation notification for non-string format.
 877                       * Complete filter - bp_groups_multiple_group_invite_notification.
 878                       *
 879                       * @since 1.0.0
 880                       *
 881                       * @param array  $array             Array holding permalink and content for notification.
 882                       * @param int    $total_items       Total number of rejected requests.
 883                       * @param string $text              Notification content.
 884                       * @param string $notification_link The permalink for notification.
 885                       */
 886                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', array(
 887                          'link' => $notification_link,
 888                          'text' => $text
 889                      ), $total_items, $text, $notification_link );
 890                  }
 891              } else {
 892                  /* translators: %s: group name. */
 893                  $text = sprintf( __( 'You have an invitation to the group: %s', 'buddypress' ), $group->name );
 894                  $filter = 'bp_groups_single_group_invite_notification';
 895  
 896                  if ( 'string' == $format ) {
 897                      /**
 898                       * Filters single group invitation notification for string format.
 899                       * Complete filter - bp_groups_single_group_invite_notification.
 900                       *
 901                       * @since 1.0.0
 902                       *
 903                       * @param string $string            HTML anchor tag for notification.
 904                       * @param int    $group_link        The permalink for the group.
 905                       * @param string $group->name       Name of the group.
 906                       * @param string $text              Notification content.
 907                       * @param string $notification_link The permalink for notification.
 908                       */
 909                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', '<a href="' . $notification_link . '">' . $text . '</a>', $group_link, $group->name, $text, $notification_link );
 910                  } else {
 911                      /**
 912                       * Filters single group invitation notification for non-string format.
 913                       * Complete filter - bp_groups_single_group_invite_notification.
 914                       *
 915                       * @since 1.0.0
 916                       *
 917                       * @param array  $array             Array holding permalink and content for notification.
 918                       * @param int    $group_link        The permalink for the group.
 919                       * @param string $group->name       Name of the group.
 920                       * @param string $text              Notification content.
 921                       * @param string $notification_link The permalink for notification.
 922                       */
 923                      return apply_filters( 'bp_groups_' . $amount . '_' . $action . '_notification', array(
 924                          'link' => $notification_link,
 925                          'text' => $text
 926                      ), $group_link, $group->name, $text, $notification_link );
 927                  }
 928              }
 929  
 930              break;
 931  
 932          default:
 933  
 934              /**
 935               * Filters plugin-added group-related custom component_actions.
 936               *
 937               * @since 2.4.0
 938               *
 939               * @param string $notification      Null value.
 940               * @param int    $item_id           The primary item ID.
 941               * @param int    $secondary_item_id The secondary item ID.
 942               * @param int    $total_items       The total number of messaging-related notifications
 943               *                                  waiting for the user.
 944               * @param string $format            'string' for BuddyBar-compatible notifications;
 945               *                                  'array' for WP Toolbar.
 946               */
 947              $custom_action_notification = apply_filters( 'bp_groups_' . $action . '_notification', null, $item_id, $secondary_item_id, $total_items, $format );
 948  
 949              if ( ! is_null( $custom_action_notification ) ) {
 950                  return $custom_action_notification;
 951              }
 952  
 953              break;
 954      }
 955  
 956      /**
 957       * Fires right before returning the formatted group notifications.
 958       *
 959       * @since 1.0.0
 960       *
 961       * @param string $action            The type of notification being rendered.
 962       * @param int    $item_id           The primary item ID.
 963       * @param int    $secondary_item_id The secondary item ID.
 964       * @param int    $total_items       Total amount of items to format.
 965       */
 966      do_action( 'groups_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
 967  
 968      return false;
 969  }
 970  
 971  /**
 972   * Remove all notifications for any member belonging to a specific group.
 973   *
 974   * @since 1.9.0
 975   *
 976   * @param int $group_id ID of the group.
 977   */
 978  function bp_groups_delete_group_delete_all_notifications( $group_id ) {
 979      if ( bp_is_active( 'notifications' ) ) {
 980          bp_notifications_delete_all_notifications_by_type( $group_id, buddypress()->groups->id );
 981      }
 982  }
 983  add_action( 'groups_delete_group', 'bp_groups_delete_group_delete_all_notifications', 10 );
 984  
 985  /**
 986   * Remove Group invite notification when a user is uninvited.
 987   *
 988   * @since 5.0.0
 989   *
 990   * @param int $group_id ID of the group being uninvited from.
 991   * @param int $user_id  ID of the user being uninvited.
 992   */
 993  function bp_groups_uninvite_user_delete_group_invite_notification( $group_id = 0, $user_id = 0 ) {
 994      if ( ! bp_is_active( 'notifications' ) || ! $group_id || ! $user_id ) {
 995          return;
 996      }
 997  
 998      bp_notifications_delete_notifications_by_item_id( $user_id, $group_id, buddypress()->groups->id, 'group_invite' );
 999  }
1000  add_action( 'groups_uninvite_user', 'bp_groups_uninvite_user_delete_group_invite_notification', 10, 2 );
1001  
1002  /**
1003   * When a demotion takes place, delete any corresponding promotion notifications.
1004   *
1005   * @since 2.0.0
1006   *
1007   * @param int $user_id  ID of the user.
1008   * @param int $group_id ID of the group.
1009   */
1010  function bp_groups_delete_promotion_notifications( $user_id = 0, $group_id = 0 ) {
1011      if ( bp_is_active( 'notifications' ) && ! empty( $group_id ) && ! empty( $user_id ) ) {
1012          bp_notifications_delete_notifications_by_item_id( $user_id, $group_id, buddypress()->groups->id, 'member_promoted_to_admin' );
1013          bp_notifications_delete_notifications_by_item_id( $user_id, $group_id, buddypress()->groups->id, 'member_promoted_to_mod' );
1014      }
1015  }
1016  add_action( 'groups_demoted_member', 'bp_groups_delete_promotion_notifications', 10, 2 );
1017  
1018  /**
1019   * Mark notifications read when a member accepts a group invitation.
1020   *
1021   * @since 1.9.0
1022   *
1023   * @param int $user_id  ID of the user.
1024   * @param int $group_id ID of the group.
1025   */
1026  function bp_groups_accept_invite_mark_notifications( $user_id, $group_id ) {
1027      if ( bp_is_active( 'notifications' ) ) {
1028          bp_notifications_mark_notifications_by_item_id( $user_id, $group_id, buddypress()->groups->id, 'group_invite' );
1029      }
1030  }
1031  add_action( 'groups_accept_invite', 'bp_groups_accept_invite_mark_notifications', 10, 2 );
1032  add_action( 'groups_reject_invite', 'bp_groups_accept_invite_mark_notifications', 10, 2 );
1033  add_action( 'groups_delete_invite', 'bp_groups_accept_invite_mark_notifications', 10, 2 );
1034  
1035  /**
1036   * Mark notifications read when a member's group membership request is granted.
1037   *
1038   * @since 2.8.0
1039   *
1040   * @param int $user_id  ID of the user.
1041   * @param int $group_id ID of the group.
1042   */
1043  function bp_groups_accept_request_mark_notifications( $user_id, $group_id ) {
1044      if ( bp_is_active( 'notifications' ) ) {
1045          // First null parameter marks read for all admins.
1046          bp_notifications_mark_notifications_by_item_id( null, $group_id, buddypress()->groups->id, 'new_membership_request', $user_id );
1047      }
1048  }
1049  add_action( 'groups_membership_accepted', 'bp_groups_accept_request_mark_notifications', 10, 2 );
1050  add_action( 'groups_membership_rejected', 'bp_groups_accept_request_mark_notifications', 10, 2 );
1051  
1052  /**
1053   * Mark notifications read when a member views their group memberships.
1054   *
1055   * @since 1.9.0
1056   */
1057  function bp_groups_screen_my_groups_mark_notifications() {
1058  
1059      // Delete group request notifications for the user.
1060      if ( isset( $_GET['n'] ) && bp_is_active( 'notifications' ) ) {
1061  
1062          // Get the necessary ID's.
1063          $group_id = buddypress()->groups->id;
1064          $user_id  = bp_loggedin_user_id();
1065  
1066          // Mark notifications read.
1067          bp_notifications_mark_notifications_by_type( $user_id, $group_id, 'membership_request_accepted' );
1068          bp_notifications_mark_notifications_by_type( $user_id, $group_id, 'membership_request_rejected' );
1069          bp_notifications_mark_notifications_by_type( $user_id, $group_id, 'member_promoted_to_mod'      );
1070          bp_notifications_mark_notifications_by_type( $user_id, $group_id, 'member_promoted_to_admin'    );
1071      }
1072  }
1073  add_action( 'groups_screen_my_groups',  'bp_groups_screen_my_groups_mark_notifications', 10 );
1074  add_action( 'groups_screen_group_home', 'bp_groups_screen_my_groups_mark_notifications', 10 );
1075  
1076  /**
1077   * Mark group invitation notifications read when a member views their invitations.
1078   *
1079   * @since 1.9.0
1080   */
1081  function bp_groups_screen_invites_mark_notifications() {
1082      if ( bp_is_active( 'notifications' ) ) {
1083          bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->groups->id, 'group_invite' );
1084      }
1085  }
1086  add_action( 'groups_screen_group_invites', 'bp_groups_screen_invites_mark_notifications', 10 );
1087  
1088  /**
1089   * Mark group join requests read when an admin or moderator visits the group administration area.
1090   *
1091   * @since 1.9.0
1092   */
1093  function bp_groups_screen_group_admin_requests_mark_notifications() {
1094      if ( bp_is_active( 'notifications' ) ) {
1095          bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->groups->id, 'new_membership_request' );
1096      }
1097  }
1098  add_action( 'groups_screen_group_admin_requests', 'bp_groups_screen_group_admin_requests_mark_notifications', 10 );
1099  
1100  /**
1101   * Delete new group membership notifications when a user is being deleted.
1102   *
1103   * @since 1.9.0
1104   *
1105   * @param int $user_id ID of the user.
1106   */
1107  function bp_groups_remove_data_for_user_notifications( $user_id ) {
1108      if ( bp_is_active( 'notifications' ) ) {
1109          bp_notifications_delete_notifications_from_user( $user_id, buddypress()->groups->id, 'new_membership_request' );
1110      }
1111  }
1112  add_action( 'groups_remove_data_for_user', 'bp_groups_remove_data_for_user_notifications', 10 );
1113  
1114  /**
1115   * Render the group settings fields on the Notification Settings page.
1116   *
1117   * @since 1.0.0
1118   */
1119  function groups_screen_notification_settings() {
1120  
1121      if ( !$group_invite = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_invite', true ) )
1122          $group_invite  = 'yes';
1123  
1124      if ( !$group_update = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_group_updated', true ) )
1125          $group_update  = 'yes';
1126  
1127      if ( !$group_promo = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_admin_promotion', true ) )
1128          $group_promo   = 'yes';
1129  
1130      if ( !$group_request = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_membership_request', true ) )
1131          $group_request = 'yes';
1132  
1133      if ( ! $group_request_completed = bp_get_user_meta( bp_displayed_user_id(), 'notification_membership_request_completed', true ) ) {
1134          $group_request_completed = 'yes';
1135      }
1136      ?>
1137  
1138      <table class="notification-settings" id="groups-notification-settings">
1139          <thead>
1140              <tr>
1141                  <th class="icon"></th>
1142                  <th class="title"><?php _ex( 'Groups', 'Group settings on notification settings page', 'buddypress' ) ?></th>
1143                  <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
1144                  <th class="no"><?php _e( 'No', 'buddypress' )?></th>
1145              </tr>
1146          </thead>
1147  
1148          <tbody>
1149              <tr id="groups-notification-settings-invitation">
1150                  <td></td>
1151                  <td><?php _ex( 'A member invites you to join a group', 'group settings on notification settings page','buddypress' ) ?></td>
1152                  <td class="yes"><input type="radio" name="notifications[notification_groups_invite]" id="notification-groups-invite-yes" value="yes" <?php checked( $group_invite, 'yes', true ) ?>/><label for="notification-groups-invite-yes" class="bp-screen-reader-text"><?php
1153                      /* translators: accessibility text */
1154                      _e( 'Yes, send email', 'buddypress' );
1155                  ?></label></td>
1156                  <td class="no"><input type="radio" name="notifications[notification_groups_invite]" id="notification-groups-invite-no" value="no" <?php checked( $group_invite, 'no', true ) ?>/><label for="notification-groups-invite-no" class="bp-screen-reader-text"><?php
1157                      /* translators: accessibility text */
1158                      _e( 'No, do not send email', 'buddypress' );
1159                  ?></label></td>
1160              </tr>
1161              <tr id="groups-notification-settings-info-updated">
1162                  <td></td>
1163                  <td><?php _ex( 'Group information is updated', 'group settings on notification settings page', 'buddypress' ) ?></td>
1164                  <td class="yes"><input type="radio" name="notifications[notification_groups_group_updated]" id="notification-groups-group-updated-yes" value="yes" <?php checked( $group_update, 'yes', true ) ?>/><label for="notification-groups-group-updated-yes" class="bp-screen-reader-text"><?php
1165                      /* translators: accessibility text */
1166                      _e( 'Yes, send email', 'buddypress' );
1167                  ?></label></td>
1168                  <td class="no"><input type="radio" name="notifications[notification_groups_group_updated]" id="notification-groups-group-updated-no" value="no" <?php checked( $group_update, 'no', true ) ?>/><label for="notification-groups-group-updated-no" class="bp-screen-reader-text"><?php
1169                      /* translators: accessibility text */
1170                      _e( 'No, do not send email', 'buddypress' );
1171                  ?></label></td>
1172              </tr>
1173              <tr id="groups-notification-settings-promoted">
1174                  <td></td>
1175                  <td><?php _ex( 'You are promoted to a group administrator or moderator', 'group settings on notification settings page', 'buddypress' ) ?></td>
1176                  <td class="yes"><input type="radio" name="notifications[notification_groups_admin_promotion]" id="notification-groups-admin-promotion-yes" value="yes" <?php checked( $group_promo, 'yes', true ) ?>/><label for="notification-groups-admin-promotion-yes" class="bp-screen-reader-text"><?php
1177                      /* translators: accessibility text */
1178                      _e( 'Yes, send email', 'buddypress' );
1179                  ?></label></td>
1180                  <td class="no"><input type="radio" name="notifications[notification_groups_admin_promotion]" id="notification-groups-admin-promotion-no" value="no" <?php checked( $group_promo, 'no', true ) ?>/><label for="notification-groups-admin-promotion-no" class="bp-screen-reader-text"><?php
1181                      /* translators: accessibility text */
1182                      _e( 'No, do not send email', 'buddypress' );
1183                  ?></label></td>
1184              </tr>
1185              <tr id="groups-notification-settings-request">
1186                  <td></td>
1187                  <td><?php _ex( 'A member requests to join a private group for which you are an admin', 'group settings on notification settings page', 'buddypress' ) ?></td>
1188                  <td class="yes"><input type="radio" name="notifications[notification_groups_membership_request]" id="notification-groups-membership-request-yes" value="yes" <?php checked( $group_request, 'yes', true ) ?>/><label for="notification-groups-membership-request-yes" class="bp-screen-reader-text"><?php
1189                      /* translators: accessibility text */
1190                      _e( 'Yes, send email', 'buddypress' );
1191                  ?></label></td>
1192                  <td class="no"><input type="radio" name="notifications[notification_groups_membership_request]" id="notification-groups-membership-request-no" value="no" <?php checked( $group_request, 'no', true ) ?>/><label for="notification-groups-membership-request-no" class="bp-screen-reader-text"><?php
1193                      /* translators: accessibility text */
1194                      _e( 'No, do not send email', 'buddypress' );
1195                  ?></label></td>
1196              </tr>
1197              <tr id="groups-notification-settings-request-completed">
1198                  <td></td>
1199                  <td><?php _ex( 'Your request to join a group has been approved or denied', 'group settings on notification settings page', 'buddypress' ) ?></td>
1200                  <td class="yes"><input type="radio" name="notifications[notification_membership_request_completed]" id="notification-groups-membership-request-completed-yes" value="yes" <?php checked( $group_request_completed, 'yes', true ) ?>/><label for="notification-groups-membership-request-completed-yes" class="bp-screen-reader-text"><?php
1201                      /* translators: accessibility text */
1202                      _e( 'Yes, send email', 'buddypress' );
1203                  ?></label></td>
1204                  <td class="no"><input type="radio" name="notifications[notification_membership_request_completed]" id="notification-groups-membership-request-completed-no" value="no" <?php checked( $group_request_completed, 'no', true ) ?>/><label for="notification-groups-membership-request-completed-no" class="bp-screen-reader-text"><?php
1205                      /* translators: accessibility text */
1206                      _e( 'No, do not send email', 'buddypress' );
1207                  ?></label></td>
1208              </tr>
1209  
1210              <?php
1211  
1212              /**
1213               * Fires at the end of the available group settings fields on Notification Settings page.
1214               *
1215               * @since 1.0.0
1216               */
1217              do_action( 'groups_screen_notification_settings' ); ?>
1218  
1219          </tbody>
1220      </table>
1221  
1222  <?php
1223  }
1224  add_action( 'bp_notification_settings', 'groups_screen_notification_settings' );
1225  
1226  /**
1227   * Notify member about their group membership request accepted/rejected by admin.
1228   *
1229   * @since 11.0.0
1230   *
1231   * @param int $user_id  ID of the user requesting group membership.
1232   * @param int $group_id ID of the group.
1233   */
1234  function groups_email_notification_membership_request_completed_by_admin( $user_id, $group_id ) {
1235      if ( (int) $user_id === bp_loggedin_user_id() ) {
1236          return;
1237      }
1238  
1239      if ( false === bp_current_user_can( 'bp_moderate' ) ) {
1240          return;
1241      }
1242  
1243      $group = groups_get_group( $group_id );
1244      if ( true === empty( $group->id ) ) {
1245          return;
1246      }
1247  
1248      $args = array(
1249          'tokens' => array(
1250              'group'           => $group,
1251              'group.id'        => $group_id,
1252              'group.name'      => $group->name,
1253              'group.url'       => esc_url( bp_get_group_permalink( $group ) ),
1254              'leave-group.url' => esc_url( bp_core_get_user_domain( $user_id ) . bp_get_groups_slug() ),
1255          ),
1256      );
1257  
1258      $email_type = 'groups-membership-request-accepted-by-admin';
1259      if ( true === doing_action( 'groups_reject_invite' ) ) {
1260          unset( $args['tokens']['leave-group.url'] );
1261          $email_type = 'groups-membership-request-rejected-by-admin';
1262      }
1263  
1264      bp_send_email( $email_type, (int) $user_id, $args );
1265  }
1266  add_action( 'groups_accept_invite', 'groups_email_notification_membership_request_completed_by_admin', 10, 2 );
1267  add_action( 'groups_reject_invite', 'groups_email_notification_membership_request_completed_by_admin', 10, 2 );


Generated: Sat Apr 27 01:00:55 2024 Cross-referenced by PHPXref 0.7.1