bp_activity_post_update( array|string $args = '' )
Post an activity update.
Description
Parameters
- $args
-
(Optional)
- 'id'
(int) ID of the activity if update existing item. - 'content'
(string) The content of the activity update. - 'user_id'
(int) Optional. Defaults to the logged-in user. - 'error_type'
(string) Optional. Error type to return. Either 'bool' or 'wp_error'. Defaults to 'bool' for boolean. 'wp_error' will return a WP_Error object.
Default value: ''
- 'id'
Return
(int|bool|WP_Error) $activity_id The activity id on success. On failure, either boolean false or WP_Error object depending on the 'error_type' $args parameter.
Source
File: bp-activity/bp-activity-functions.php
function bp_activity_post_update( $args = '' ) { $r = wp_parse_args( $args, array( 'content' => false, 'user_id' => bp_loggedin_user_id(), 'hide_sitewide' => false, 'type' => 'activity_update', 'privacy' => 'public', 'error_type' => 'bool', ) ); // if ( empty( $r['content'] ) || !strlen( trim( $r['content'] ) ) ) { // return false; // } if ( bp_is_user_inactive( $r['user_id'] ) ) { return false; } // Record this on the user's profile. $activity_content = $r['content']; $primary_link = bp_core_get_userlink( $r['user_id'], false, true ); /** * Filters the new activity content for current activity item. * * @since BuddyPress 1.2.0 * * @param string $activity_content Activity content posted by user. */ $add_content = apply_filters( 'bp_activity_new_update_content', $activity_content ); /** * Filters the activity primary link for current activity item. * * @since BuddyPress 1.2.0 * * @param string $primary_link Link to the profile for the user who posted the activity. */ $add_primary_link = apply_filters( 'bp_activity_new_update_primary_link', $primary_link ); // Now write the values. $activity_id = bp_activity_add( array( 'user_id' => $r['user_id'], 'content' => $add_content, 'primary_link' => $add_primary_link, 'component' => buddypress()->activity->id, 'type' => $r['type'], 'hide_sitewide' => $r['hide_sitewide'], 'privacy' => $r['privacy'], 'error_type' => $r['error_type'] ) ); // Bail on failure. if ( false === $activity_id || is_wp_error( $activity_id ) ) { return $activity_id; } if ( ! empty( $r['content'] ) && !strlen( trim( $r['content'] ) ) ) { /** * Filters the latest update content for the activity item. * * @since BuddyPress 1.6.0 * * @param string $r Content of the activity update. * @param string $activity_content Content of the activity update. */ $activity_content = apply_filters( 'bp_activity_latest_update_content', $r['content'], $activity_content ); // Add this update to the "latest update" usermeta so it can be fetched anywhere. bp_update_user_meta( bp_loggedin_user_id(), 'bp_latest_update', array( 'id' => $activity_id, 'content' => $activity_content ) ); } /** * Fires at the end of an activity post update, before returning the updated activity item ID. * * @since BuddyPress 1.2.0 * * @param string $content Content of the activity post update. * @param int $user_id ID of the user posting the activity update. * @param int $activity_id ID of the activity item being updated. */ do_action( 'bp_activity_posted_update', $r['content'], $r['user_id'], $activity_id ); return $activity_id; }
Changelog
Version | Description |
---|---|
BuddyPress 1.2.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.