Exemple #1
0
/**
 * Delete activity item(s).
 *
 * If you're looking to hook into one action that provides the ID(s) of
 * the activity/activities deleted, then use:
 *
 * add_action( 'bp_activity_deleted_activities', 'my_function' );
 *
 * The action passes one parameter that is a single activity ID or an
 * array of activity IDs depending on the number deleted.
 *
 * If you are deleting an activity comment please use bp_activity_delete_comment();
 *
 * @since BuddyPress (1.0.0)
 *
 * @see BP_Activity_Activity::get() For more information on accepted arguments.
 * @uses wp_parse_args()
 * @uses bp_activity_adjust_mention_count()
 * @uses BP_Activity_Activity::delete() {@link BP_Activity_Activity}
 * @uses do_action() To call the 'bp_before_activity_delete' hook.
 * @uses bp_get_user_meta()
 * @uses bp_delete_user_meta()
 * @uses do_action() To call the 'bp_activity_delete' hook.
 * @uses do_action() To call the 'bp_activity_deleted_activities' hook.
 * @uses wp_cache_delete()
 *
 * @param array $args To delete specific activity items, use
 *            $args = array( 'id' => $ids );
 *        Otherwise, to use filters for item deletion, the argument format is
 *        the same as BP_Activity_Activity::get(). See that method for a description.
 * @return bool True on success, false on failure.
 */
function bp_activity_delete($args = '')
{
    // Pass one or more the of following variables to delete by those variables
    $args = bp_parse_args($args, array('id' => false, 'action' => false, 'content' => false, 'component' => false, 'type' => false, 'primary_link' => false, 'user_id' => false, 'item_id' => false, 'secondary_item_id' => false, 'date_recorded' => false, 'hide_sitewide' => false));
    do_action('bp_before_activity_delete', $args);
    // Adjust the new mention count of any mentioned member
    bp_activity_adjust_mention_count($args['id'], 'delete');
    $activity_ids_deleted = BP_Activity_Activity::delete($args);
    if (empty($activity_ids_deleted)) {
        return false;
    }
    // Check if the user's latest update has been deleted
    $user_id = empty($args['user_id']) ? bp_loggedin_user_id() : $args['user_id'];
    $latest_update = bp_get_user_meta($user_id, 'bp_latest_update', true);
    if (!empty($latest_update)) {
        if (in_array((int) $latest_update['id'], (array) $activity_ids_deleted)) {
            bp_delete_user_meta($user_id, 'bp_latest_update');
        }
    }
    do_action('bp_activity_delete', $args);
    do_action('bp_activity_deleted_activities', $activity_ids_deleted);
    wp_cache_delete('bp_activity_sitewide_front', 'bp');
    return true;
}
/**
 * Finds and links @-mentioned users in the contents of activity items
 *
 * @since 1.2.0
 *
 * @param string $content The activity content
 * @param int $activity_id The activity id
 *
 * @uses bp_activity_find_mentions()
 * @uses bp_is_username_compatibility_mode()
 * @uses bp_core_get_userid_from_nicename()
 * @uses bp_activity_at_message_notification()
 * @uses bp_core_get_user_domain()
 * @uses bp_activity_adjust_mention_count()
 *
 * @return string $content Content filtered for mentions
 */
function bp_activity_at_name_filter($content, $activity_id = 0)
{
    $usernames = bp_activity_find_mentions($content);
    foreach ((array) $usernames as $username) {
        if (bp_is_username_compatibility_mode()) {
            $user_id = username_exists($username);
        } else {
            $user_id = bp_core_get_userid_from_nicename($username);
        }
        if (empty($user_id)) {
            continue;
        }
        // If an activity_id is provided, we can send email and BP notifications
        if ($activity_id) {
            bp_activity_at_message_notification($activity_id, $user_id);
        }
        $content = preg_replace('/(@' . $username . '\\b)/', "<a href='" . bp_core_get_user_domain($user_id) . "' rel='nofollow'>@{$username}</a>", $content);
    }
    // Adjust the activity count for this item
    if ($activity_id) {
        bp_activity_adjust_mention_count($activity_id, 'add');
    }
    return $content;
}
/**
 * Delete activity item(s).
 *
 * If you're looking to hook into one action that provides the ID(s) of
 * the activity/activities deleted, then use:
 *
 * add_action( 'bp_activity_deleted_activities', 'my_function' );
 *
 * The action passes one parameter that is a single activity ID or an
 * array of activity IDs depending on the number deleted.
 *
 * If you are deleting an activity comment please use bp_activity_delete_comment();
 *
 * @since 1.0.0
 *
 * @see BP_Activity_Activity::get() For more information on accepted arguments.
 * @uses wp_parse_args()
 * @uses bp_activity_adjust_mention_count()
 * @uses BP_Activity_Activity::delete() {@link BP_Activity_Activity}
 * @uses do_action() To call the 'bp_before_activity_delete' hook.
 * @uses bp_get_user_meta()
 * @uses bp_delete_user_meta()
 * @uses do_action() To call the 'bp_activity_delete' hook.
 * @uses do_action() To call the 'bp_activity_deleted_activities' hook.
 * @uses wp_cache_delete()
 *
 * @param array|string $args To delete specific activity items, use
 *                           $args = array( 'id' => $ids ); Otherwise, to use
 *                           filters for item deletion, the argument format is
 *                           the same as BP_Activity_Activity::get().
 *                           See that method for a description.
 * @return bool True on success, false on failure.
 */
function bp_activity_delete($args = '')
{
    // Pass one or more the of following variables to delete by those variables.
    $args = bp_parse_args($args, array('id' => false, 'action' => false, 'content' => false, 'component' => false, 'type' => false, 'primary_link' => false, 'user_id' => false, 'item_id' => false, 'secondary_item_id' => false, 'date_recorded' => false, 'hide_sitewide' => false));
    /**
     * Fires before an activity item proceeds to be deleted.
     *
     * @since 1.5.0
     *
     * @param array $args Array of arguments to be used with the activity deletion.
     */
    do_action('bp_before_activity_delete', $args);
    // Adjust the new mention count of any mentioned member.
    bp_activity_adjust_mention_count($args['id'], 'delete');
    $activity_ids_deleted = BP_Activity_Activity::delete($args);
    if (empty($activity_ids_deleted)) {
        return false;
    }
    // Check if the user's latest update has been deleted.
    $user_id = empty($args['user_id']) ? bp_loggedin_user_id() : $args['user_id'];
    $latest_update = bp_get_user_meta($user_id, 'bp_latest_update', true);
    if (!empty($latest_update)) {
        if (in_array((int) $latest_update['id'], (array) $activity_ids_deleted)) {
            bp_delete_user_meta($user_id, 'bp_latest_update');
        }
    }
    /**
     * Fires after the activity item has been deleted.
     *
     * @since 1.0.0
     *
     * @param array $args Array of arguments used with the activity deletion.
     */
    do_action('bp_activity_delete', $args);
    /**
     * Fires after the activity item has been deleted.
     *
     * @since 1.2.0
     *
     * @param array $activity_ids_deleted Array of affected activity item IDs.
     */
    do_action('bp_activity_deleted_activities', $activity_ids_deleted);
    wp_cache_delete('bp_activity_sitewide_front', 'bp');
    return true;
}
/**
 * Finds and links @-mentioned users in the contents of activity items
 *
 * @since 1.2.0
 *
 * @param string $content The activity content
 * @param int $activity_id The activity id
 *
 * @uses bp_activity_find_mentions()
 * @uses bp_is_username_compatibility_mode()
 * @uses bp_core_get_userid_from_nicename()
 * @uses bp_activity_at_message_notification()
 * @uses bp_core_get_user_domain()
 * @uses bp_activity_adjust_mention_count()
 *
 * @return string $content Content filtered for mentions
 */
function bp_activity_at_name_filter($content, $activity_id = 0)
{
    if ($activity_id & bp_is_active('activity')) {
        $activity = new BP_Activity_Activity($activity_id);
        // If this activity has been marked as spam, don't do anything. This prevents @notifications being sent.
        if (!empty($activity) && $activity->is_spam) {
            return $content;
        }
    }
    $usernames = bp_activity_find_mentions($content);
    foreach ((array) $usernames as $username) {
        if (bp_is_username_compatibility_mode()) {
            $user_id = username_exists($username);
        } else {
            $user_id = bp_core_get_userid_from_nicename($username);
        }
        if (empty($user_id)) {
            continue;
        }
        // If an activity_id is provided, we can send email and BP notifications
        if ($activity_id) {
            bp_activity_at_message_notification($activity_id, $user_id);
        }
        $content = preg_replace('/(@' . $username . '\\b)/', "<a href='" . bp_core_get_user_domain($user_id) . "' rel='nofollow'>@{$username}</a>", $content);
    }
    // Adjust the activity count for this item
    if ($activity_id) {
        bp_activity_adjust_mention_count($activity_id, 'add');
    }
    return $content;
}