Changeset 6493
- Timestamp:
- 06/06/2017 06:55:55 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/users/engagements.php
r6439 r6493 489 489 * id and action 490 490 * @uses bbp_is_favorites() To check if it's the favorites page 491 * @uses bbp_get_favorites_link() To get the favorites page link492 491 * @uses bbp_get_topic_permalink() To get the topic permalink 493 492 * @uses bbp_redirect() To redirect to the url … … 495 494 function bbp_favorites_handler( $action = '' ) { 496 495 496 // Default 497 $success = false; 498 499 // Bail if favorites not active 497 500 if ( ! bbp_is_favorites_active() ) { 498 return false;501 return $success; 499 502 } 500 503 501 504 // Bail if no topic ID is passed 502 505 if ( empty( $_GET['topic_id'] ) ) { 503 return ;506 return $success; 504 507 } 505 508 … … 512 515 // Bail if actions aren't meant for this function 513 516 if ( ! in_array( $action, $possible_actions, true ) ) { 514 return ;517 return $success; 515 518 } 516 519 517 520 // What action is taking place? 518 $topic_id = intval( $_GET['topic_id'] );521 $topic_id = bbp_get_topic_id( $_GET['topic_id'] ); 519 522 $user_id = bbp_get_user_id( 0, true, true ); 520 523 … … 534 537 // Bail if errors 535 538 if ( bbp_has_errors() ) { 536 return ;539 return $success; 537 540 } 538 541 539 542 /** No errors *************************************************************/ 540 543 541 $is_favorite = bbp_is_user_favorite( $user_id, $topic_id ); 542 $success = false; 543 544 if ( true === $is_favorite && 'bbp_favorite_remove' === $action ) { 544 if ( 'bbp_favorite_remove' === $action ) { 545 545 $success = bbp_remove_user_favorite( $user_id, $topic_id ); 546 } elseif ( false === $is_favorite &&'bbp_favorite_add' === $action ) {546 } elseif ( 'bbp_favorite_add' === $action ) { 547 547 $success = bbp_add_user_favorite( $user_id, $topic_id ); 548 548 } … … 572 572 573 573 // Fail! Handle errors 574 } elseif ( true === $is_favorite &&'bbp_favorite_remove' === $action ) {574 } elseif ( 'bbp_favorite_remove' === $action ) { 575 575 bbp_add_error( 'bbp_favorite_remove', __( '<strong>ERROR</strong>: There was a problem removing that topic from favorites.', 'bbpress' ) ); 576 } elseif ( false === $is_favorite &&'bbp_favorite_add' === $action ) {576 } elseif ( 'bbp_favorite_add' === $action ) { 577 577 bbp_add_error( 'bbp_favorite_add', __( '<strong>ERROR</strong>: There was a problem favoriting that topic.', 'bbpress' ) ); 578 578 } 579 580 return (bool) $success; 579 581 } 580 582 … … 1163 1165 function bbp_forum_subscriptions_handler( $action = '' ) { 1164 1166 1167 // Default 1168 $success = false; 1169 1170 // Bail if subscriptions not active 1165 1171 if ( ! bbp_is_subscriptions_active() ) { 1166 return false;1172 return $success; 1167 1173 } 1168 1174 1169 1175 // Bail if no forum ID is passed 1170 1176 if ( empty( $_GET['forum_id'] ) ) { 1171 return ;1177 return $success; 1172 1178 } 1173 1179 … … 1180 1186 // Bail if actions aren't meant for this function 1181 1187 if ( ! in_array( $action, $possible_actions, true ) ) { 1182 return ;1188 return $success; 1183 1189 } 1184 1190 1185 1191 // Get required data 1192 $forum_id = bbp_get_forum_id( $_GET['forum_id'] ); 1186 1193 $user_id = bbp_get_user_id( 0, true, true ); 1187 $forum_id = intval( $_GET['forum_id'] );1188 1194 1189 1195 // Check for empty forum … … 1202 1208 // Bail if we have errors 1203 1209 if ( bbp_has_errors() ) { 1204 return ;1210 return $success; 1205 1211 } 1206 1212 1207 1213 /** No errors *************************************************************/ 1208 1214 1209 $is_subscription = bbp_is_user_subscribed( $user_id, $forum_id ); 1210 $success = false; 1211 1212 if ( true === $is_subscription && 'bbp_unsubscribe' === $action ) { 1215 if ( 'bbp_unsubscribe' === $action ) { 1213 1216 $success = bbp_remove_user_subscription( $user_id, $forum_id ); 1214 } elseif ( false === $is_subscription &&'bbp_subscribe' === $action ) {1217 } elseif ( 'bbp_subscribe' === $action ) { 1215 1218 $success = bbp_add_user_subscription( $user_id, $forum_id ); 1216 1219 } … … 1240 1243 1241 1244 // Fail! Handle errors 1242 } elseif ( true === $is_subscription &&'bbp_unsubscribe' === $action ) {1245 } elseif ( 'bbp_unsubscribe' === $action ) { 1243 1246 bbp_add_error( 'bbp_unsubscribe', __( '<strong>ERROR</strong>: There was a problem unsubscribing from that forum.', 'bbpress' ) ); 1244 } elseif ( false === $is_subscription &&'bbp_subscribe' === $action ) {1247 } elseif ( 'bbp_subscribe' === $action ) { 1245 1248 bbp_add_error( 'bbp_subscribe', __( '<strong>ERROR</strong>: There was a problem subscribing to that forum.', 'bbpress' ) ); 1246 1249 } 1250 1251 return (bool) $success; 1247 1252 } 1248 1253 … … 1270 1275 function bbp_subscriptions_handler( $action = '' ) { 1271 1276 1277 // Default 1278 $success = false; 1279 1280 // Bail if subscriptions not active 1272 1281 if ( ! bbp_is_subscriptions_active() ) { 1273 return false;1282 return $success; 1274 1283 } 1275 1284 1276 1285 // Bail if no topic ID is passed 1277 1286 if ( empty( $_GET['topic_id'] ) ) { 1278 return ;1287 return $success; 1279 1288 } 1280 1289 … … 1287 1296 // Bail if actions aren't meant for this function 1288 1297 if ( ! in_array( $action, $possible_actions, true ) ) { 1289 return ;1298 return $success; 1290 1299 } 1291 1300 1292 1301 // Get required data 1302 $topic_id = bbp_get_topic_id( $_GET['topic_id'] ); 1293 1303 $user_id = bbp_get_user_id( 0, true, true ); 1294 $topic_id = intval( $_GET['topic_id'] );1295 1304 1296 1305 // Check for empty topic … … 1309 1318 // Bail if we have errors 1310 1319 if ( bbp_has_errors() ) { 1311 return ;1320 return $success; 1312 1321 } 1313 1322 1314 1323 /** No errors *************************************************************/ 1315 1324 1316 $is_subscription = bbp_is_user_subscribed( $user_id, $topic_id ); 1317 $success = false; 1318 1319 if ( true === $is_subscription && 'bbp_unsubscribe' === $action ) { 1325 if ( 'bbp_unsubscribe' === $action ) { 1320 1326 $success = bbp_remove_user_subscription( $user_id, $topic_id ); 1321 } elseif ( false === $is_subscription &&'bbp_subscribe' === $action ) {1327 } elseif ( 'bbp_subscribe' === $action ) { 1322 1328 $success = bbp_add_user_subscription( $user_id, $topic_id ); 1323 1329 } … … 1347 1353 1348 1354 // Fail! Handle errors 1349 } elseif ( true === $is_subscription &&'bbp_unsubscribe' === $action ) {1355 } elseif ( 'bbp_unsubscribe' === $action ) { 1350 1356 bbp_add_error( 'bbp_unsubscribe', __( '<strong>ERROR</strong>: There was a problem unsubscribing from that topic.', 'bbpress' ) ); 1351 } elseif ( false === $is_subscription &&'bbp_subscribe' === $action ) {1357 } elseif ( 'bbp_subscribe' === $action ) { 1352 1358 bbp_add_error( 'bbp_subscribe', __( '<strong>ERROR</strong>: There was a problem subscribing to that topic.', 'bbpress' ) ); 1353 1359 } 1354 } 1360 1361 return (bool) $success; 1362 }
Note: See TracChangeset
for help on using the changeset viewer.