[ 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      /**
  31       * Fires after the default 'new member' activity types are registered.
  32       *
  33       * @since 2.2.0
  34       */
  35      do_action( 'bp_members_register_activity_actions' );
  36  }
  37  add_action( 'bp_register_activity_actions', 'bp_members_register_activity_actions' );
  38  
  39  /**
  40   * Format 'new_member' activity actions.
  41   *
  42   * @since 2.2.0
  43   *
  44   * @param string $action   Static activity action.
  45   * @param object $activity Activity object.
  46   * @return string $action
  47   */
  48  function bp_members_format_activity_action_new_member( $action, $activity ) {
  49      $userlink = bp_core_get_userlink( $activity->user_id );
  50      $action   = sprintf( esc_html__( '%s became a registered member', 'buddypress' ), $userlink );
  51  
  52      // Legacy filter - pass $user_id instead of $activity.
  53      if ( has_filter( 'bp_core_activity_registered_member_action' ) ) {
  54          $action = apply_filters( 'bp_core_activity_registered_member_action', $action, $activity->user_id );
  55      }
  56  
  57      /**
  58       * Filters the formatted 'new member' activity actions.
  59       *
  60       * @since 2.2.0
  61       *
  62       * @param string $action   Static activity action.
  63       * @param object $activity Activity object.
  64       */
  65      return apply_filters( 'bp_members_format_activity_action_new_member', $action, $activity );
  66  }
  67  
  68  /**
  69   * Create a "became a registered user" activity item when a user activates his account.
  70   *
  71   * @since 1.2.2
  72   *
  73   * @param array $user Array of userdata passed to bp_core_activated_user hook.
  74   * @return bool
  75   */
  76  function bp_core_new_user_activity( $user ) {
  77      if ( empty( $user ) ) {
  78          return false;
  79      }
  80  
  81      if ( is_array( $user ) ) {
  82          $user_id = $user['user_id'];
  83      } else {
  84          $user_id = $user;
  85      }
  86  
  87      if ( empty( $user_id ) ) {
  88          return false;
  89      }
  90  
  91      bp_activity_add( array(
  92          'user_id'   => $user_id,
  93          'component' => buddypress()->members->id,
  94          'type'      => 'new_member'
  95      ) );
  96  }
  97  add_action( 'bp_core_activated_user', 'bp_core_new_user_activity' );


Generated: Wed Jul 17 01:01:40 2019 Cross-referenced by PHPXref 0.7.1