[ 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  
  51      /* translators: %s: user link */
  52      $action = sprintf( esc_html__( '%s became a registered member', 'buddypress' ), $userlink );
  53  
  54      // Legacy filter - pass $user_id instead of $activity.
  55      if ( has_filter( 'bp_core_activity_registered_member_action' ) ) {
  56          $action = apply_filters( 'bp_core_activity_registered_member_action', $action, $activity->user_id );
  57      }
  58  
  59      /**
  60       * Filters the formatted 'new member' activity actions.
  61       *
  62       * @since 2.2.0
  63       *
  64       * @param string $action   Static activity action.
  65       * @param object $activity Activity object.
  66       */
  67      return apply_filters( 'bp_members_format_activity_action_new_member', $action, $activity );
  68  }
  69  
  70  /**
  71   * Create a "became a registered user" activity item when a user activates his account.
  72   *
  73   * @since 1.2.2
  74   *
  75   * @param array $user Array of userdata passed to bp_core_activated_user hook.
  76   * @return bool
  77   */
  78  function bp_core_new_user_activity( $user ) {
  79      if ( empty( $user ) ) {
  80          return false;
  81      }
  82  
  83      if ( is_array( $user ) ) {
  84          $user_id = $user['user_id'];
  85      } else {
  86          $user_id = $user;
  87      }
  88  
  89      if ( empty( $user_id ) ) {
  90          return false;
  91      }
  92  
  93      bp_activity_add( array(
  94          'user_id'   => $user_id,
  95          'component' => buddypress()->members->id,
  96          'type'      => 'new_member'
  97      ) );
  98  }
  99  add_action( 'bp_core_activated_user', 'bp_core_new_user_activity' );


Generated: Mon Sep 21 01:01:31 2020 Cross-referenced by PHPXref 0.7.1