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
2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 | 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.