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


Generated: Mon Apr 19 01:01:38 2021 Cross-referenced by PHPXref 0.7.1