[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-members/ -> bp-members-activity.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Member Activity
   4   *
   5   * @package BuddyPress
   6   * @subpackage MembersActivity
   7   * @since 2.2.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Register the 'new member' activity type.
  15   *
  16   * @since 2.2.0
  17   */
  18  function bp_members_register_activity_actions() {
  19  
  20      bp_activity_set_action(
  21          buddypress()->members->id,
  22          'new_member',
  23          __( 'New member registered', 'buddypress' ),
  24          'bp_members_format_activity_action_new_member',
  25          __( 'New Members', 'buddypress' ),
  26          array( 'activity' )
  27      );
  28  
  29      // Register the activity stream actions for this component.
  30      bp_activity_set_action(
  31          // Older avatar activity items use 'profile' for component. See r4273.
  32          buddypress()->members->id,
  33          'new_avatar',
  34          __( 'Member changed profile picture', 'buddypress' ),
  35          'bp_members_format_activity_action_new_avatar',
  36          __( 'Updated Profile Photos', 'buddypress' )
  37      );
  38  
  39      /**
  40       * Fires after the default 'new member' activity types are registered.
  41       *
  42       * @since 2.2.0
  43       */
  44      do_action( 'bp_members_register_activity_actions' );
  45  }
  46  add_action( 'bp_register_activity_actions', 'bp_members_register_activity_actions' );
  47  
  48  /**
  49   * Format 'new_member' activity actions.
  50   *
  51   * @since 2.2.0
  52   *
  53   * @param string $action   Static activity action.
  54   * @param object $activity Activity object.
  55   * @return string $action
  56   */
  57  function bp_members_format_activity_action_new_member( $action, $activity ) {
  58      $userlink         = bp_core_get_userlink( $activity->user_id );
  59      $inviter_userlink = false;
  60      $invite_id        = bp_get_user_meta( $activity->user_id, 'accepted_members_invitation', true );
  61  
  62      if ( $invite_id ) {
  63          $invite = new BP_Invitation( (int) $invite_id );
  64  
  65          if ( $invite->inviter_id ) {
  66              $inviter_userlink = bp_core_get_userlink( $invite->inviter_id );
  67          }
  68      }
  69  
  70      if ( $inviter_userlink ) {
  71          $action = sprintf(
  72              /* translators: 1: new user link. 2: inviter user link. */
  73              esc_html__( '%1$s accepted an invitation from %2$s and became a registered member', 'buddypress' ),
  74              $userlink,
  75              $inviter_userlink
  76          );
  77      } else {
  78          /* translators: %s: user link */
  79          $action = sprintf( esc_html__( '%s became a registered member', 'buddypress' ), $userlink );
  80      }
  81  
  82      // Legacy filter - pass $user_id instead of $activity.
  83      if ( has_filter( 'bp_core_activity_registered_member_action' ) ) {
  84          $action = apply_filters( 'bp_core_activity_registered_member_action', $action, $activity->user_id );
  85      }
  86  
  87      /**
  88       * Filters the formatted 'new member' activity actions.
  89       *
  90       * @since 2.2.0
  91       * @since 8.0.0 Added $invite_id
  92       *
  93       * @param string $action    Static activity action.
  94       * @param object $activity  Activity object.
  95       * @param int    $invite_id The ID of the invite.
  96       */
  97      return apply_filters( 'bp_members_format_activity_action_new_member', $action, $activity, $invite_id );
  98  }
  99  
 100  /**
 101   * Format 'new_avatar' activity actions.
 102   *
 103   * @since 8.0.0
 104   *
 105   * @param string $action   Static activity action.
 106   * @param object $activity Activity object.
 107   * @return string
 108   */
 109  function bp_members_format_activity_action_new_avatar( $action, $activity ) {
 110      $userlink = bp_core_get_userlink( $activity->user_id );
 111  
 112      /* translators: %s: user link */
 113      $action = sprintf( esc_html__( '%s changed their profile picture', 'buddypress' ), $userlink );
 114  
 115      // Legacy filter - pass $user_id instead of $activity.
 116      if ( has_filter( 'bp_xprofile_new_avatar_action' ) ) {
 117          $action = apply_filters( 'bp_xprofile_new_avatar_action', $action, $activity->user_id );
 118      }
 119  
 120      /** This filter is documented in wp-includes/deprecated.php */
 121      $action = apply_filters_deprecated( 'bp_xprofile_format_activity_action_new_avatar', array( $action, $activity ), '8.0.0', 'bp_members_format_activity_action_new_avatar' );
 122  
 123      /**
 124       * Filters the formatted 'new_avatar' activity stream action.
 125       *
 126       * @since 8.0.0
 127       *
 128       * @param string $action   Formatted action for activity stream.
 129       * @param object $activity Activity object.
 130       */
 131      return apply_filters( 'bp_members_format_activity_action_new_avatar', $action, $activity );
 132  }
 133  
 134  /**
 135   * Create a "became a registered user" activity item when a user activates his account.
 136   *
 137   * @since 1.2.2
 138   *
 139   * @param array $user Array of userdata passed to bp_core_activated_user hook.
 140   * @return bool
 141   */
 142  function bp_core_new_user_activity( $user ) {
 143      if ( empty( $user ) ) {
 144          return false;
 145      }
 146  
 147      if ( is_array( $user ) ) {
 148          $user_id = $user['user_id'];
 149      } else {
 150          $user_id = $user;
 151      }
 152  
 153      if ( empty( $user_id ) ) {
 154          return false;
 155      }
 156  
 157      bp_activity_add( array(
 158          'user_id'   => $user_id,
 159          'component' => buddypress()->members->id,
 160          'type'      => 'new_member'
 161      ) );
 162  }
 163  add_action( 'bp_core_activated_user', 'bp_core_new_user_activity' );
 164  
 165  /**
 166   * Adds an activity stream item when a user has uploaded a new avatar.
 167   *
 168   * @since 8.0.0
 169   *
 170   * @param int $user_id The user id the avatar was set for.
 171   */
 172  function bp_members_new_avatar_activity( $user_id = 0 ) {
 173  
 174      // Bail if activity component is not active.
 175      if ( ! bp_is_active( 'activity' ) ) {
 176          return false;
 177      }
 178  
 179      if ( empty( $user_id ) ) {
 180          $user_id = bp_displayed_user_id();
 181      }
 182  
 183      /** This filter is documented in wp-includes/deprecated.php */
 184      $user_id = apply_filters_deprecated( 'bp_xprofile_new_avatar_user_id', array( $user_id ), '8.0.0', 'bp_members_new_avatar_user_id' );
 185  
 186      /**
 187       * Filters the user ID when a user has uploaded a new avatar.
 188       *
 189       * @since 8.0.0
 190       *
 191       * @param int $user_id ID of the user the avatar was set for.
 192       */
 193      $user_id = apply_filters( 'bp_members_new_avatar_user_id', $user_id );
 194  
 195      // Add the activity.
 196      bp_activity_add( array(
 197          'user_id'   => $user_id,
 198          'component' => buddypress()->members->id,
 199          'type'      => 'new_avatar'
 200      ) );
 201  }
 202  add_action( 'bp_members_avatar_uploaded', 'bp_members_new_avatar_activity' );


Generated: Wed Sep 22 01:01:36 2021 Cross-referenced by PHPXref 0.7.1