BP_REST_Topics_Actions_Endpoint::rest_update_subscribe( integer $topic_id, boolean $value, integer $user_id )
Update Subscription for the topic.
Description
Parameters
- $topic_id
-
(Required) Topic ID.
- $value
-
(Required) Action value.
- $user_id
-
(Required) Current users ID.
Return
(bool|WP_Error)
Source
File: bp-forums/classes/class-bp-rest-topics-actions-endpoint.php
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 | protected function rest_update_subscribe( $topic_id , $value , $user_id ) { if ( ! bbp_is_subscriptions_active() ) { return new WP_Error( 'bp_rest_bbp_topic_action_disabled' , __( 'Subscriptions are no longer active.' , 'buddyboss' ), array ( 'status' => 404, ) ); } // Bail if user cannot add subscription for this user. if ( ! current_user_can( 'edit_user' , $user_id ) ) { return new WP_Error( 'bp_rest_authorization_required' , __( 'You do not have permission to do this.' , 'buddyboss' ), array ( 'status' => 404, ) ); } $status = true; $subscribed = bbp_is_user_subscribed( $user_id , $topic_id ); // Subscribed and unsubscribing. if ( true === $subscribed && empty ( $value ) ) { $status = bbp_remove_user_subscription( $user_id , $topic_id ); // Not subscribed and subscribing. } elseif ( false === $subscribed && ! empty ( $value ) ) { $status = bbp_add_user_subscription( $user_id , $topic_id ); } return $status ; } |
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.