/bp-groups/bp-groups-forums.php

  1. <?php 
  2. /** 
  3. * BuddyPress Groups Forums. 
  4. * 
  5. * Action functions are exactly the same as screen functions, however they do not 
  6. * have a template screen associated with them. Usually they will send the user 
  7. * back to the default screen after execution. 
  8. * 
  9. * Note that this file is only used for the retired version of bbPress (1.x) and 
  10. * will see minimal updates as of BuddyPress 1.9.0. 
  11. * 
  12. * @package BuddyPress 
  13. * @subpackage GroupsForums 
  14. * @since 1.5.0 
  15. */ 
  16.  
  17. // Exit if accessed directly. 
  18. defined( 'ABSPATH' ) || exit; 
  19.  
  20. /** 
  21. * Creates a new forum inside a specific BuddyPress group. 
  22. * 
  23. * Uses the bundled version of bbPress packaged with BuddyPress. 
  24. * 
  25. * @since 1.0.0 
  26. * 
  27. * @param int $group_id The group ID that the new forum should be attached to. 
  28. * @param string $group_name The group name. 
  29. * @param string $group_desc The group description. 
  30. */ 
  31. function groups_new_group_forum( $group_id = 0, $group_name = '', $group_desc = '' ) { 
  32.  
  33. if ( empty( $group_id ) ) { 
  34. $group_id = bp_get_current_group_id(); 
  35.  
  36. if ( empty( $group_name ) ) { 
  37. $group_name = bp_get_current_group_name(); 
  38.  
  39. if ( empty( $group_desc ) ) { 
  40. $group_desc = bp_get_current_group_description(); 
  41.  
  42. $forum_id = bp_forums_new_forum( array( 
  43. 'forum_name' => $group_name,  
  44. 'forum_desc' => $group_desc 
  45. ) ); 
  46.  
  47. groups_update_groupmeta( $group_id, 'forum_id', $forum_id ); 
  48.  
  49. /** 
  50. * Fires after the creation of a new forum inside a specific BuddyPress group. 
  51. * 
  52. * @since 1.0.0 
  53. * 
  54. * @param int $forum_id ID of the newly created forum. 
  55. * @param int $group_id ID of the associated group. 
  56. */ 
  57. do_action( 'groups_new_group_forum', $forum_id, $group_id ); 
  58.  
  59. /** 
  60. * Update group forum metadata (title, description, slug) when the group's details are edited. 
  61. * 
  62. * @since 1.1.0 
  63. * 
  64. * @param int $group_id Group id, passed from groups_details_updated. 
  65. * @return mixed 
  66. */ 
  67. function groups_update_group_forum( $group_id ) { 
  68.  
  69. $group = groups_get_group( $group_id ); 
  70.  
  71. /** 
  72. * Bail in the following three situations: 
  73. * 1. Forums are not enabled for this group 
  74. * 2. The BP Forum component is not enabled 
  75. * 3. The built-in bbPress forums are not correctly installed (usually means they've been 
  76. * uninstalled) 
  77. */ 
  78. if ( empty( $group->enable_forum ) || !bp_is_active( 'forums' ) || ( function_exists( 'bp_forums_is_installed_correctly' ) && !bp_forums_is_installed_correctly() ) ) { 
  79. return false; 
  80.  
  81. /** 
  82. * Filters the group forum metadata value argument. 
  83. * 
  84. * @since 1.2.5 
  85. * 
  86. * @param array $value Array of metadata values to update the group forum with. 
  87. */ 
  88. bp_forums_update_forum( apply_filters( 'groups_update_group_forum', array( 
  89. 'forum_id' => groups_get_groupmeta( $group_id, 'forum_id' ),  
  90. 'forum_name' => $group->name,  
  91. 'forum_desc' => $group->description,  
  92. 'forum_slug' => $group->slug 
  93. ) ) ); 
  94. add_action( 'groups_details_updated', 'groups_update_group_forum' ); 
  95.  
  96. /** 
  97. * Create a new group forum post. 
  98. * 
  99. * Uses the bundled version of bbPress packaged with BuddyPress. 
  100. * 
  101. * @since 1.0.0 
  102. * 
  103. * @param string $post_text The text for the forum post. 
  104. * @param int $topic_id The topic ID used so we can identify where the new 
  105. * forum post should reside. 
  106. * @param mixed $page The page number where the new forum post should reside. 
  107. * Default: false. 
  108. * @return mixed The new forum post ID on success. Boolean false on failure. 
  109. */ 
  110. function groups_new_group_forum_post( $post_text, $topic_id, $page = false ) { 
  111. if ( empty( $post_text ) ) { 
  112. return false; 
  113.  
  114. /** 
  115. * Filters the text for the forum post before save. 
  116. * 
  117. * @since 1.2.0 
  118. * 
  119. * @param string $post_text Text for the forum post. 
  120. */ 
  121. $post_text = apply_filters( 'group_forum_post_text_before_save', $post_text ); 
  122.  
  123. /** 
  124. * Filters the ID for the forum post before save. 
  125. * 
  126. * @since 1.2.0 
  127. * 
  128. * @param int $topic_id ID of the topic the post will be associated with. 
  129. */ 
  130. $topic_id = apply_filters( 'group_forum_post_topic_id_before_save', $topic_id ); 
  131. $post_id = bp_forums_insert_post( array( 
  132. 'post_text' => $post_text,  
  133. 'topic_id' => $topic_id 
  134. ) ); 
  135.  
  136. if ( empty( $post_id ) ) { 
  137. return false; 
  138.  
  139. $topic = bp_forums_get_topic_details( $topic_id ); 
  140. $activity_action = sprintf( __( '%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . '">' . esc_attr( bp_get_current_group_name() ) . '</a>' ); 
  141. $activity_content = bp_create_excerpt( $post_text ); 
  142. $primary_link = bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug . '/'; 
  143.  
  144. if ( !empty( $page ) ) { 
  145. $primary_link .= "?topic_page=" . $page; 
  146.  
  147. /** 
  148. * Filters the new groups activity forum post action. 
  149. * 
  150. * @since 1.2.0 
  151. * 
  152. * @param string $activity_action Formatted action related to group activity posting. 
  153. * @param int $post_id ID of the newly created group forum post. 
  154. * @param string $post_text The text for the forum post. 
  155. * @param object $topic Object holding current topic details. Passed by reference. 
  156. */ 
  157. $action = apply_filters_ref_array( 'groups_activity_new_forum_post_action', array( $activity_action, $post_id, $post_text, &$topic ) ); 
  158.  
  159. /** 
  160. * Filters the new groups activity forum post content. 
  161. * 
  162. * @since 1.2.0 
  163. * 
  164. * @param string $activity_content Excerpt-length activity content to be posted. 
  165. * @param int $post_id ID of the newly created group forum post. 
  166. * @param string $post_text The text for the forum post. 
  167. * @param object $topic Object holding current topic details. Passed by reference. 
  168. */ 
  169. $content = apply_filters_ref_array( 'groups_activity_new_forum_post_content', array( $activity_content, $post_id, $post_text, &$topic ) ); 
  170.  
  171. /** 
  172. * Filters the new groups activity forum post primary link. 
  173. * 
  174. * @since 1.1.0 
  175. * 
  176. * @param string $value URL to the newly posted forum post. 
  177. */ 
  178. $filtered_primary_link = apply_filters( 'groups_activity_new_forum_post_primary_link', "{$primary_link}#post-{$post_id}" ); 
  179.  
  180. groups_record_activity( array( 
  181. 'action' => $action,  
  182. 'content' => $content,  
  183. 'primary_link' => $filtered_primary_link,  
  184. 'type' => 'new_forum_post',  
  185. 'item_id' => bp_get_current_group_id(),  
  186. 'secondary_item_id' => $post_id 
  187. ) ); 
  188.  
  189. /** 
  190. * Fires after the creation of a new group forum topic post. 
  191. * 
  192. * @since 1.0.0 
  193. * 
  194. * @param int $value ID of the current group. 
  195. * @param int $post_id ID of the new created forum topic post. 
  196. */ 
  197. do_action( 'groups_new_forum_topic_post', bp_get_current_group_id(), $post_id ); 
  198.  
  199. return $post_id; 
  200.  
  201. /** 
  202. * Create a new group forum topic. 
  203. * 
  204. * Uses the bundled version of bbPress packaged with BuddyPress. 
  205. * 
  206. * @since 1.0.0 
  207. * 
  208. * @param string $topic_title The title for the forum topic. 
  209. * @param string $topic_text The text for the forum topic. 
  210. * @param string $topic_tags A comma-delimited string of topic tags. 
  211. * @param int $forum_id The forum ID this forum topic resides in. 
  212. * @return mixed The new topic object on success. Boolean false on failure. 
  213. */ 
  214. function groups_new_group_forum_topic( $topic_title, $topic_text, $topic_tags, $forum_id ) { 
  215. if ( empty( $topic_title ) || empty( $topic_text ) ) 
  216. return false; 
  217.  
  218. /** 
  219. * Filters the new groups forum topic title before saving. 
  220. * 
  221. * @since 1.2.0 
  222. * 
  223. * @param string $topic_title The title for the forum topic. 
  224. */ 
  225. $topic_title = apply_filters( 'group_forum_topic_title_before_save', $topic_title ); 
  226.  
  227. /** 
  228. * Filters the new groups forum topic text before saving. 
  229. * 
  230. * @since 1.2.0 
  231. * 
  232. * @param string $topic_text The text for the forum topic. 
  233. */ 
  234. $topic_text = apply_filters( 'group_forum_topic_text_before_save', $topic_text ); 
  235.  
  236. /** 
  237. * Filters the new groups forum topic tags before saving. 
  238. * 
  239. * @since 1.2.0 
  240. * 
  241. * @param string $topic_tags A comma-delimited string of topic tags. 
  242. */ 
  243. $topic_tags = apply_filters( 'group_forum_topic_tags_before_save', $topic_tags ); 
  244.  
  245. /** 
  246. * Filters the forum ID this forum topic resides in. 
  247. * 
  248. * @since 1.2.0 
  249. * 
  250. * @param string $forum_id The forum ID this forum topic resides in. 
  251. */ 
  252. $forum_id = apply_filters( 'group_forum_topic_forum_id_before_save', $forum_id ); 
  253. $topic_id = bp_forums_new_topic( array( 
  254. 'topic_title' => $topic_title,  
  255. 'topic_text' => $topic_text,  
  256. 'topic_tags' => $topic_tags,  
  257. 'forum_id' => $forum_id 
  258. ) ); 
  259.  
  260. if ( empty( $topic_id ) ) { 
  261. return false; 
  262.  
  263. $topic = bp_forums_get_topic_details( $topic_id ); 
  264. $activity_action = sprintf( __( '%1$s started the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . '">' . esc_attr( bp_get_current_group_name() ) . '</a>' ); 
  265. $activity_content = bp_create_excerpt( $topic_text ); 
  266.  
  267. /** 
  268. * Filters the new groups activity forum topic action. 
  269. * 
  270. * @since 1.2.0 
  271. * 
  272. * @param string $activity_action Formatted action related to forum topic. 
  273. * @param string $topic_text New topic text. 
  274. * @param object $topic Object holding current topic details. Passed by reference. 
  275. */ 
  276. $action = apply_filters_ref_array( 'groups_activity_new_forum_topic_action', array( $activity_action, $topic_text, &$topic ) ); 
  277.  
  278. /** 
  279. * Filters the new groups activity forum topic content. 
  280. * 
  281. * @since 1.2.0 
  282. * 
  283. * @param string $activity_content Excerpt-length activity content to be posted. 
  284. * @param string $topic_text New topic text. 
  285. * @param object $topic Object holding current topic details. Passed by reference. 
  286. */ 
  287. $content = apply_filters_ref_array( 'groups_activity_new_forum_topic_content', array( $activity_content, $topic_text, &$topic ) ); 
  288.  
  289. /** 
  290. * Filters the new groups activity forum topic primary link. 
  291. * 
  292. * @since 1.1.0 
  293. * 
  294. * @param string $value Concatenated primary link. 
  295. */ 
  296. $primary_link = apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug . '/' ); 
  297.  
  298. groups_record_activity( array( 
  299. 'action' => $action,  
  300. 'content' => $content,  
  301. 'primary_link' => $primary_link,  
  302. 'type' => 'new_forum_topic',  
  303. 'item_id' => bp_get_current_group_id(),  
  304. 'secondary_item_id' => $topic->topic_id 
  305. ) ); 
  306.  
  307. /** 
  308. * Fires after the creation of a new group forum topic. 
  309. * 
  310. * @since 1.0.0 
  311. * 
  312. * @param int $value ID of the current group. 
  313. * @param object $topic Object holding current topic details. Passed by reference. 
  314. */ 
  315. do_action_ref_array( 'groups_new_forum_topic', array( bp_get_current_group_id(), &$topic ) ); 
  316.  
  317. return $topic; 
  318.  
  319. /** 
  320. * Update an existing group forum topic. 
  321. * 
  322. * Uses the bundled version of bbPress packaged with BuddyPress. 
  323. * 
  324. * @since 1.1.0 
  325. * 
  326. * @param int $topic_id The topic ID of the existing forum topic. 
  327. * @param string $topic_title The title for the forum topic. 
  328. * @param string $topic_text The text for the forum topic. 
  329. * @param mixed $topic_tags A comma-delimited string of topic tags. Optional. 
  330. * @return mixed The topic object on success. Boolean false on failure. 
  331. */ 
  332. function groups_update_group_forum_topic( $topic_id, $topic_title, $topic_text, $topic_tags = false ) { 
  333. $bp = buddypress(); 
  334.  
  335. /** This filter is documented in bp-groups/bp-groups-forums.php */ 
  336. $topic_title = apply_filters( 'group_forum_topic_title_before_save', $topic_title ); 
  337.  
  338. /** This filter is documented in bp-groups/bp-groups-forums.php */ 
  339. $topic_text = apply_filters( 'group_forum_topic_text_before_save', $topic_text ); 
  340. $topic = bp_forums_update_topic( array( 
  341. 'topic_title' => $topic_title,  
  342. 'topic_text' => $topic_text,  
  343. 'topic_id' => $topic_id,  
  344. 'topic_tags' => $topic_tags 
  345. ) ); 
  346.  
  347. if ( empty( $topic ) ) { 
  348. return false; 
  349.  
  350. // Get the corresponding activity item. 
  351. if ( bp_is_active( 'activity' ) ) { 
  352. $id = bp_activity_get_activity_id( array( 
  353. 'item_id' => bp_get_current_group_id(),  
  354. 'secondary_item_id' => $topic_id,  
  355. 'component' => $bp->groups->id,  
  356. 'type' => 'new_forum_topic' 
  357. ) ); 
  358.  
  359. $activity_action = sprintf( __( '%1$s edited the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( $topic->topic_poster ), '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . '">' . esc_attr( bp_get_current_group_name() ) . '</a>' ); 
  360. $activity_content = bp_create_excerpt( $topic_text ); 
  361.  
  362. /** This filter is documented in bp-groups/bp-groups-forums.php */ 
  363. $action = apply_filters_ref_array( 'groups_activity_new_forum_topic_action', array( $activity_action, $topic_text, &$topic ) ); 
  364.  
  365. /** This filter is documented in bp-groups/bp-groups-forums.php */ 
  366. $content = apply_filters_ref_array( 'groups_activity_new_forum_topic_content', array( $activity_content, $topic_text, &$topic ) ); 
  367.  
  368. /** This filter is documented in bp-groups/bp-groups-forums.php */ 
  369. $primary_link = apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug . '/' ); 
  370.  
  371. groups_record_activity( array( 
  372. 'id' => $id,  
  373. 'action' => $action,  
  374. 'content' => $content,  
  375. 'primary_link' => $primary_link,  
  376. 'type' => 'new_forum_topic',  
  377. 'item_id' => (int) bp_get_current_group_id(),  
  378. 'user_id' => (int) $topic->topic_poster,  
  379. 'secondary_item_id' => $topic->topic_id,  
  380. 'recorded_time ' => $topic->topic_time 
  381. ) ); 
  382.  
  383. /** 
  384. * Fires after the update of a group forum topic. 
  385. * 
  386. * @since 1.1.0 
  387. * 
  388. * @param object $topic Object holding current topic being updated. Passed by reference. 
  389. */ 
  390. do_action_ref_array( 'groups_update_group_forum_topic', array( &$topic ) ); 
  391.  
  392. return $topic; 
  393.  
  394. /** 
  395. * Update an existing group forum post. 
  396. * 
  397. * Uses the bundled version of bbPress packaged with BuddyPress. 
  398. * 
  399. * @since 1.1.0 
  400. * 
  401. * @param int $post_id The post ID of the existing forum post. 
  402. * @param string $post_text The text for the forum post. 
  403. * @param int $topic_id The topic ID of the existing forum topic. 
  404. * @param mixed $page The page number where the new forum post should reside. Optional. 
  405. * @return mixed The forum post ID on success. Boolean false on failure. 
  406. */ 
  407. function groups_update_group_forum_post( $post_id, $post_text, $topic_id, $page = false ) { 
  408. $bp = buddypress(); 
  409.  
  410. /** This filter is documented in bp-groups/bp-groups-forums.php */ 
  411. $post_text = apply_filters( 'group_forum_post_text_before_save', $post_text ); 
  412.  
  413. /** This filter is documented in bp-groups/bp-groups-forums.php */ 
  414. $topic_id = apply_filters( 'group_forum_post_topic_id_before_save', $topic_id ); 
  415. $post = bp_forums_get_post( $post_id ); 
  416. $post_id = bp_forums_insert_post( array( 
  417. 'post_id' => $post_id,  
  418. 'post_text' => $post_text,  
  419. 'post_time' => $post->post_time,  
  420. 'topic_id' => $topic_id,  
  421. 'poster_id' => $post->poster_id 
  422. ) ); 
  423.  
  424. if ( empty( $post_id ) ) { 
  425. return false; 
  426.  
  427. $topic = bp_forums_get_topic_details( $topic_id ); 
  428. $activity_action = sprintf( __( '%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( $post->poster_id ), '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug .'">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . '">' . esc_attr( bp_get_current_group_name() ) . '</a>' ); 
  429. $activity_content = bp_create_excerpt( $post_text ); 
  430. $primary_link = bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug . '/'; 
  431.  
  432. if ( !empty( $page ) ) { 
  433. $primary_link .= "?topic_page=" . $page; 
  434.  
  435. // Get the corresponding activity item. 
  436. if ( bp_is_active( 'activity' ) ) { 
  437. $id = bp_activity_get_activity_id( array( 
  438. 'user_id' => $post->poster_id,  
  439. 'component' => $bp->groups->id,  
  440. 'type' => 'new_forum_post',  
  441. 'item_id' => bp_get_current_group_id(),  
  442. 'secondary_item_id' => $post_id 
  443. ) ); 
  444.  
  445. /** This filter is documented in bp-groups/bp-groups-forums.php */ 
  446. $action = apply_filters_ref_array( 'groups_activity_new_forum_post_action', array( $activity_action, $post_text, &$topic, &$topic ) ); 
  447.  
  448. /** This filter is documented in bp-groups/bp-groups-forums.php */ 
  449. $content = apply_filters_ref_array( 'groups_activity_new_forum_post_content', array( $activity_content, $post_text, &$topic, &$topic ) ); 
  450.  
  451. /** This filter is documented in bp-groups/bp-groups-forums.php */ 
  452. $filtered_primary_link = apply_filters( 'groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id ); 
  453.  
  454. groups_record_activity( array( 
  455. 'id' => $id,  
  456. 'action' => $action,  
  457. 'content' => $content,  
  458. 'primary_link' => $filtered_primary_link,  
  459. 'type' => 'new_forum_post',  
  460. 'item_id' => (int) bp_get_current_group_id(),  
  461. 'user_id' => (int) $post->poster_id,  
  462. 'secondary_item_id' => $post_id,  
  463. 'recorded_time' => $post->post_time 
  464. ) ); 
  465.  
  466. /** 
  467. * Fires after the update of a group forum post. 
  468. * 
  469. * @since 1.1.0 
  470. * 
  471. * @param object $post Object holding current post being updated. 
  472. * @param object $topic Object holding current topic details. Passed by reference. 
  473. */ 
  474. do_action_ref_array( 'groups_update_group_forum_post', array( $post, &$topic ) ); 
  475.  
  476. return $post_id; 
  477.  
  478. /** 
  479. * Delete a group forum topic and also any corresponding activity items. 
  480. * 
  481. * Uses the bundled version of bbPress packaged with BuddyPress. 
  482. * 
  483. * @since 1.1.0 
  484. * 
  485. * @param int $topic_id The ID of the topic to be deleted. 
  486. * @return bool True if the delete routine went through properly. 
  487. */ 
  488. function groups_delete_group_forum_topic( $topic_id ) { 
  489. $bp = buddypress(); 
  490.  
  491. // Before deleting the thread, get the post ids so that their activity items can be deleted. 
  492. $posts = bp_forums_get_topic_posts( array( 'topic_id' => $topic_id, 'per_page' => -1 ) ); 
  493. $action = bp_forums_delete_topic( array( 'topic_id' => $topic_id ) ); 
  494.  
  495. if ( !empty( $action ) ) { 
  496.  
  497. /** 
  498. * Fires before the deletion of a group forum topic. 
  499. * 
  500. * @since 1.2.9 
  501. * 
  502. * @param int $topic_id ID of the topic to be deleted. 
  503. */ 
  504. do_action( 'groups_before_delete_group_forum_topic', $topic_id ); 
  505.  
  506. // Delete the corresponding activity stream items. 
  507. if ( bp_is_active( 'activity' ) ) { 
  508.  
  509. // The activity item for the initial topic. 
  510. bp_activity_delete( array( 
  511. 'item_id' => bp_get_current_group_id(),  
  512. 'secondary_item_id' => $topic_id,  
  513. 'component' => $bp->groups->id,  
  514. 'type' => 'new_forum_topic' 
  515. ) ); 
  516.  
  517. // The activity item for each post. 
  518. foreach ( (array) $posts as $post ) { 
  519. bp_activity_delete( array( 
  520. 'item_id' => bp_get_current_group_id(),  
  521. 'secondary_item_id' => $post->post_id,  
  522. 'component' => $bp->groups->id,  
  523. 'type' => 'new_forum_post' 
  524. ) ); 
  525.  
  526. /** 
  527. * Fires after the deletion of a group forum topic. 
  528. * 
  529. * @since 1.1.0 
  530. * 
  531. * @param int $topic_id ID of the topic that was deleted. 
  532. */ 
  533. do_action( 'groups_delete_group_forum_topic', $topic_id ); 
  534.  
  535. return (bool) $action; 
  536.  
  537. /** 
  538. * Delete a group forum post and its corresponding activity item. 
  539. * 
  540. * Uses the bundled version of bbPress packaged with BuddyPress. 
  541. * 
  542. * @since 1.1.0 
  543. * 
  544. * @param int $post_id The ID of the post you want to delete. 
  545. * @param int|bool $topic_id Optional. The topic to which the post belongs. This 
  546. * value isn't used in the function but is passed along 
  547. * to do_action() hooks. 
  548. * @return bool True on success. 
  549. */ 
  550. function groups_delete_group_forum_post( $post_id, $topic_id = false ) { 
  551.  
  552. $action = bp_forums_delete_post( array( 'post_id' => $post_id ) ); 
  553.  
  554. if ( !empty( $action ) ) { 
  555.  
  556. /** 
  557. * Fires before the deletion of a group forum post. 
  558. * 
  559. * @since 1.5.0 
  560. * 
  561. * @param int $post_id ID of the post to be deleted. 
  562. * @param int $topic_id ID of the associated topic. 
  563. */ 
  564. do_action( 'groups_before_delete_group_forum_post', $post_id, $topic_id ); 
  565.  
  566. // Delete the corresponding activity stream item. 
  567. if ( bp_is_active( 'activity' ) ) { 
  568. bp_activity_delete( array( 
  569. 'item_id' => bp_get_current_group_id(),  
  570. 'secondary_item_id' => $post_id,  
  571. 'component' => buddypress()->groups->id,  
  572. 'type' => 'new_forum_post' 
  573. ) ); 
  574.  
  575. /** 
  576. * Fires after the deletion of a group forum post. 
  577. * 
  578. * @since 1.1.0 
  579. * 
  580. * @param int $post_id ID of the post that was deleted. 
  581. * @param int $topic_id ID of the associated topic. 
  582. */ 
  583. do_action( 'groups_delete_group_forum_post', $post_id, $topic_id ); 
  584.  
  585. return (bool) $action; 
  586.  
  587. /** 
  588. * Get a total count of all public topics of a given type, across groups/forums. 
  589. * 
  590. * @since 1.5.0 
  591. * 
  592. * @param string $type Either 'newest', 'popular', 'unreplied', 'tags'. 
  593. * Default: 'newest'. 
  594. * @return int The topic count. 
  595. */ 
  596. function groups_total_public_forum_topic_count( $type = 'newest' ) { 
  597.  
  598. /** 
  599. * Filters the total count of all public topics of a given type, across groups/forums. 
  600. * 
  601. * @since 1.1.0 
  602. * 
  603. * @param int $value Total count of all public topics. 
  604. */ 
  605. return apply_filters( 'groups_total_public_forum_topic_count', BP_Groups_Group::get_global_forum_topic_count( $type ) ); 
  606.  
  607. /** 
  608. * Get a total count of all topics of a given status, across groups/forums. 
  609. * 
  610. * @since 1.5.0 
  611. * 
  612. * @param string $status Which groups to count. 'public', 'private', 'hidden',  
  613. * 'all'. Default: 'public'. 
  614. * @param string|bool $search_terms Optional. Limit by a search term. 
  615. * @return int The topic count. 
  616. */ 
  617. function groups_total_forum_topic_count( $status = 'public', $search_terms = false ) { 
  618.  
  619. /** 
  620. * Filters the total count of all topics of a given status, across groups/forums. 
  621. * 
  622. * @since 1.5.0 
  623. * 
  624. * @param int $value Total count of all topics. 
  625. */ 
  626. return apply_filters( 'groups_total_forum_topic_count', BP_Groups_Group::get_global_topic_count( $status, $search_terms ) ); 
.