/bp-groups/bp-groups-screens.php

  1. <?php 
  2. /** 
  3. * BuddyPress Groups Screen Functions 
  4. * 
  5. * Screen functions are the controllers of BuddyPress. They will execute when 
  6. * their specific URL is caught. They will first save or manipulate data using 
  7. * business functions, then pass on the user to a template file. 
  8. * 
  9. * @package BuddyPress 
  10. * @subpackage GroupsScreens 
  11. * @since 1.5.0 
  12. */ 
  13.  
  14. // Exit if accessed directly. 
  15. defined( 'ABSPATH' ) || exit; 
  16.  
  17. if ( ! buddypress()->do_autoload ) { 
  18. require dirname( __FILE__ ) . '/classes/class-bp-groups-theme-compat.php'; 
  19.  
  20. /** 
  21. * Handle the display of the Groups directory index. 
  22. * 
  23. * @since 1.0.0 
  24. */ 
  25. function groups_directory_groups_setup() { 
  26. if ( bp_is_groups_directory() ) { 
  27. // Set group type if available. 
  28. if ( bp_is_current_action( bp_get_groups_group_type_base() ) && bp_action_variable() ) { 
  29. $matched_types = bp_groups_get_group_types( array( 
  30. 'has_directory' => true,  
  31. 'directory_slug' => bp_action_variable(),  
  32. ) ); 
  33.  
  34. // Redirect back to group directory if no match. 
  35. if ( empty( $matched_types ) ) { 
  36. bp_core_redirect( bp_get_groups_directory_permalink() ); 
  37.  
  38. // Set our global variable. 
  39. buddypress()->groups->current_directory_type = reset( $matched_types ); 
  40.  
  41. bp_update_is_directory( true, 'groups' ); 
  42.  
  43. /** 
  44. * Fires before the loading of the Groups directory index. 
  45. * 
  46. * @since 1.1.0 
  47. */ 
  48. do_action( 'groups_directory_groups_setup' ); 
  49.  
  50. /** 
  51. * Filters the template to load for the Groups directory index. 
  52. * 
  53. * @since 1.0.0 
  54. * 
  55. * @param string $value Path to the groups directory index template to load. 
  56. */ 
  57. bp_core_load_template( apply_filters( 'groups_template_directory_groups', 'groups/index' ) ); 
  58. add_action( 'bp_screens', 'groups_directory_groups_setup', 2 ); 
  59.  
  60. /** 
  61. * Handle the loading of the My Groups page. 
  62. * 
  63. * @since 1.0.0 
  64. */ 
  65. function groups_screen_my_groups() { 
  66.  
  67. /** 
  68. * Fires before the loading of the My Groups page. 
  69. * 
  70. * @since 1.1.0 
  71. */ 
  72. do_action( 'groups_screen_my_groups' ); 
  73.  
  74. /** 
  75. * Filters the template to load for the My Groups page. 
  76. * 
  77. * @since 1.0.0 
  78. * 
  79. * @param string $value Path to the My Groups page template to load. 
  80. */ 
  81. bp_core_load_template( apply_filters( 'groups_template_my_groups', 'members/single/home' ) ); 
  82.  
  83. /** 
  84. * Handle the loading of a user's Groups > Invites page. 
  85. * 
  86. * @since 1.0.0 
  87. */ 
  88. function groups_screen_group_invites() { 
  89. $group_id = (int)bp_action_variable( 1 ); 
  90.  
  91. if ( bp_is_action_variable( 'accept' ) && is_numeric( $group_id ) ) { 
  92. // Check the nonce. 
  93. if ( !check_admin_referer( 'groups_accept_invite' ) ) 
  94. return false; 
  95.  
  96. if ( !groups_accept_invite( bp_loggedin_user_id(), $group_id ) ) { 
  97. bp_core_add_message( __('Group invite could not be accepted', 'buddypress'), 'error' ); 
  98. } else { 
  99. bp_core_add_message( __('Group invite accepted', 'buddypress') ); 
  100.  
  101. // Record this in activity streams. 
  102. $group = groups_get_group( $group_id ); 
  103.  
  104. groups_record_activity( array( 
  105. 'type' => 'joined_group',  
  106. 'item_id' => $group->id 
  107. ) ); 
  108.  
  109. if ( isset( $_GET['redirect_to'] ) ) { 
  110. $redirect_to = urldecode( $_GET['redirect_to'] ); 
  111. } else { 
  112. $redirect_to = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action() ); 
  113.  
  114. bp_core_redirect( $redirect_to ); 
  115.  
  116. } elseif ( bp_is_action_variable( 'reject' ) && is_numeric( $group_id ) ) { 
  117. // Check the nonce. 
  118. if ( !check_admin_referer( 'groups_reject_invite' ) ) 
  119. return false; 
  120.  
  121. if ( !groups_reject_invite( bp_loggedin_user_id(), $group_id ) ) { 
  122. bp_core_add_message( __( 'Group invite could not be rejected', 'buddypress' ), 'error' ); 
  123. } else { 
  124. bp_core_add_message( __( 'Group invite rejected', 'buddypress' ) ); 
  125.  
  126. if ( isset( $_GET['redirect_to'] ) ) { 
  127. $redirect_to = urldecode( $_GET['redirect_to'] ); 
  128. } else { 
  129. $redirect_to = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action() ); 
  130.  
  131. bp_core_redirect( $redirect_to ); 
  132.  
  133. /** 
  134. * Fires before the loading of a users Groups > Invites template. 
  135. * 
  136. * @since 1.0.0 
  137. * 
  138. * @param int $group_id ID of the group being displayed 
  139. */ 
  140. do_action( 'groups_screen_group_invites', $group_id ); 
  141.  
  142. /** 
  143. * Filters the template to load for a users Groups > Invites page. 
  144. * 
  145. * @since 1.0.0 
  146. * 
  147. * @param string $value Path to a users Groups > Invites page template. 
  148. */ 
  149. bp_core_load_template( apply_filters( 'groups_template_group_invites', 'members/single/home' ) ); 
  150.  
  151. /** 
  152. * Handle the loading of a single group's page. 
  153. * 
  154. * @since 1.0.0 
  155. */ 
  156. function groups_screen_group_home() { 
  157.  
  158. if ( ! bp_is_single_item() ) { 
  159. return false; 
  160.  
  161. /** 
  162. * Fires before the loading of a single group's page. 
  163. * 
  164. * @since 1.0.0 
  165. */ 
  166. do_action( 'groups_screen_group_home' ); 
  167.  
  168. /** 
  169. * Filters the template to load for a single group's page. 
  170. * 
  171. * @since 1.0.0 
  172. * 
  173. * @param string $value Path to a single group's template to load. 
  174. */ 
  175. bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) ); 
  176.  
  177. /** 
  178. * This screen function handles actions related to group forums. 
  179. * 
  180. * @since 1.0.0 
  181. */ 
  182. function groups_screen_group_forum() { 
  183.  
  184. if ( !bp_is_active( 'forums' ) || !bp_forums_is_installed_correctly() ) 
  185. return false; 
  186.  
  187. if ( bp_action_variable( 0 ) && !bp_is_action_variable( 'topic', 0 ) ) { 
  188. bp_do_404(); 
  189. return; 
  190.  
  191. $bp = buddypress(); 
  192.  
  193. if ( !$bp->groups->current_group->user_has_access ) { 
  194. bp_core_no_access(); 
  195. return; 
  196.  
  197. if ( ! bp_is_single_item() ) 
  198. return false; 
  199.  
  200. // Fetch the details we need. 
  201. $topic_slug = (string)bp_action_variable( 1 ); 
  202. $topic_id = bp_forums_get_topic_id_from_slug( $topic_slug ); 
  203. $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ); 
  204. $user_is_banned = false; 
  205.  
  206. if ( !bp_current_user_can( 'bp_moderate' ) && groups_is_user_banned( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) 
  207. $user_is_banned = true; 
  208.  
  209. if ( !empty( $topic_slug ) && !empty( $topic_id ) ) { 
  210.  
  211. // Posting a reply. 
  212. if ( !$user_is_banned && !bp_action_variable( 2 ) && isset( $_POST['submit_reply'] ) ) { 
  213. // Check the nonce. 
  214. check_admin_referer( 'bp_forums_new_reply' ); 
  215.  
  216. // Auto join this user if they are not yet a member of this group. 
  217. if ( bp_groups_auto_join() && !bp_current_user_can( 'bp_moderate' ) && 'public' == $bp->groups->current_group->status && !groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) { 
  218. groups_join_group( $bp->groups->current_group->id, bp_loggedin_user_id() ); 
  219.  
  220. $topic_page = isset( $_GET['topic_page'] ) ? $_GET['topic_page'] : false; 
  221.  
  222. // Don't allow reply flooding. 
  223. if ( bp_forums_reply_exists( $_POST['reply_text'], $topic_id, bp_loggedin_user_id() ) ) { 
  224. bp_core_add_message( __( 'It looks like you\'ve already said that!', 'buddypress' ), 'error' ); 
  225. } else { 
  226. if ( !$post_id = groups_new_group_forum_post( $_POST['reply_text'], $topic_id, $topic_page ) ) { 
  227. bp_core_add_message( __( 'There was an error when replying to that topic', 'buddypress'), 'error' ); 
  228. } else { 
  229. bp_core_add_message( __( 'Your reply was posted successfully', 'buddypress') ); 
  230.  
  231. $query_vars = isset( $_SERVER['QUERY_STRING'] ) ? '?' . $_SERVER['QUERY_STRING'] : ''; 
  232.  
  233. $redirect = bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic_slug . '/' . $query_vars; 
  234.  
  235. if ( !empty( $post_id ) ) { 
  236. $redirect .= '#post-' . $post_id; 
  237.  
  238. bp_core_redirect( $redirect ); 
  239.  
  240. // Sticky a topic. 
  241. elseif ( bp_is_action_variable( 'stick', 2 ) && ( bp_is_item_admin() || bp_is_item_mod() ) ) { 
  242. // Check the nonce. 
  243. check_admin_referer( 'bp_forums_stick_topic' ); 
  244.  
  245. if ( !bp_forums_sticky_topic( array( 'topic_id' => $topic_id ) ) ) { 
  246. bp_core_add_message( __( 'There was an error when making that topic a sticky', 'buddypress' ), 'error' ); 
  247. } else { 
  248. bp_core_add_message( __( 'The topic was made sticky successfully', 'buddypress' ) ); 
  249.  
  250. /** 
  251. * Fires after a group forum topic has been stickied. 
  252. * 
  253. * @since 1.1.0 
  254. * 
  255. * @param int $topic_id ID of the topic being stickied. 
  256. */ 
  257. do_action( 'groups_stick_forum_topic', $topic_id ); 
  258. bp_core_redirect( wp_get_referer() ); 
  259.  
  260. // Un-Sticky a topic. 
  261. elseif ( bp_is_action_variable( 'unstick', 2 ) && ( bp_is_item_admin() || bp_is_item_mod() ) ) { 
  262. // Check the nonce. 
  263. check_admin_referer( 'bp_forums_unstick_topic' ); 
  264.  
  265. if ( !bp_forums_sticky_topic( array( 'topic_id' => $topic_id, 'mode' => 'unstick' ) ) ) { 
  266. bp_core_add_message( __( 'There was an error when unsticking that topic', 'buddypress'), 'error' ); 
  267. } else { 
  268. bp_core_add_message( __( 'The topic was unstuck successfully', 'buddypress') ); 
  269.  
  270. /** 
  271. * Fires after a group forum topic has been un-stickied. 
  272. * 
  273. * @since 1.1.0 
  274. * 
  275. * @param int $topic_id ID of the topic being un-stickied. 
  276. */ 
  277. do_action( 'groups_unstick_forum_topic', $topic_id ); 
  278. bp_core_redirect( wp_get_referer() ); 
  279.  
  280. // Close a topic. 
  281. elseif ( bp_is_action_variable( 'close', 2 ) && ( bp_is_item_admin() || bp_is_item_mod() ) ) { 
  282. // Check the nonce. 
  283. check_admin_referer( 'bp_forums_close_topic' ); 
  284.  
  285. if ( !bp_forums_openclose_topic( array( 'topic_id' => $topic_id ) ) ) { 
  286. bp_core_add_message( __( 'There was an error when closing that topic', 'buddypress'), 'error' ); 
  287. } else { 
  288. bp_core_add_message( __( 'The topic was closed successfully', 'buddypress') ); 
  289.  
  290. /** 
  291. * Fires after a group forum topic has been closed. 
  292. * 
  293. * @since 1.1.0 
  294. * 
  295. * @param int $topic_id ID of the topic being closed. 
  296. */ 
  297. do_action( 'groups_close_forum_topic', $topic_id ); 
  298. bp_core_redirect( wp_get_referer() ); 
  299.  
  300. // Open a topic. 
  301. elseif ( bp_is_action_variable( 'open', 2 ) && ( bp_is_item_admin() || bp_is_item_mod() ) ) { 
  302. // Check the nonce. 
  303. check_admin_referer( 'bp_forums_open_topic' ); 
  304.  
  305. if ( !bp_forums_openclose_topic( array( 'topic_id' => $topic_id, 'mode' => 'open' ) ) ) { 
  306. bp_core_add_message( __( 'There was an error when opening that topic', 'buddypress'), 'error' ); 
  307. } else { 
  308. bp_core_add_message( __( 'The topic was opened successfully', 'buddypress') ); 
  309.  
  310. /** 
  311. * Fires after a group forum topic has been opened. 
  312. * 
  313. * @since 1.1.0 
  314. * 
  315. * @param int $topic_id ID of the topic being opened. 
  316. */ 
  317. do_action( 'groups_open_forum_topic', $topic_id ); 
  318. bp_core_redirect( wp_get_referer() ); 
  319.  
  320. // Delete a topic. 
  321. elseif ( empty( $user_is_banned ) && bp_is_action_variable( 'delete', 2 ) && !bp_action_variable( 3 ) ) { 
  322. // Fetch the topic. 
  323. $topic = bp_forums_get_topic_details( $topic_id ); 
  324.  
  325. /** Check the logged in user can delete this topic */ 
  326. if ( ! bp_is_item_admin() && ! bp_is_item_mod() && ( (int) bp_loggedin_user_id() != (int) $topic->topic_poster ) ) { 
  327. bp_core_redirect( wp_get_referer() ); 
  328.  
  329. // Check the nonce. 
  330. check_admin_referer( 'bp_forums_delete_topic' ); 
  331.  
  332. /** 
  333. * Fires before a group forum topic is deleted. 
  334. * 
  335. * @since 1.5.0 
  336. * 
  337. * @param int $topic_id ID of the topic being deleted. 
  338. */ 
  339. do_action( 'groups_before_delete_forum_topic', $topic_id ); 
  340.  
  341. if ( !groups_delete_group_forum_topic( $topic_id ) ) { 
  342. bp_core_add_message( __( 'There was an error deleting the topic', 'buddypress' ), 'error' ); 
  343. } else { 
  344. bp_core_add_message( __( 'The topic was deleted successfully', 'buddypress' ) ); 
  345.  
  346. /** 
  347. * Fires after a group forum topic has been deleted. 
  348. * 
  349. * @since 1.5.0 
  350. * 
  351. * @param int $topic_id ID of the topic being deleted. 
  352. */ 
  353. do_action( 'groups_delete_forum_topic', $topic_id ); 
  354. bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'forum/' ); 
  355.  
  356. // Editing a topic. 
  357. elseif ( empty( $user_is_banned ) && bp_is_action_variable( 'edit', 2 ) && !bp_action_variable( 3 ) ) { 
  358. // Fetch the topic. 
  359. $topic = bp_forums_get_topic_details( $topic_id ); 
  360.  
  361. // Check the logged in user can edit this topic. 
  362. if ( ! bp_is_item_admin() && ! bp_is_item_mod() && ( (int) bp_loggedin_user_id() != (int) $topic->topic_poster ) ) { 
  363. bp_core_redirect( wp_get_referer() ); 
  364.  
  365. if ( isset( $_POST['save_changes'] ) ) { 
  366. // Check the nonce. 
  367. check_admin_referer( 'bp_forums_edit_topic' ); 
  368.  
  369. $topic_tags = !empty( $_POST['topic_tags'] ) ? $_POST['topic_tags'] : false; 
  370.  
  371. if ( !groups_update_group_forum_topic( $topic_id, $_POST['topic_title'], $_POST['topic_text'], $topic_tags ) ) { 
  372. bp_core_add_message( __( 'There was an error when editing that topic', 'buddypress'), 'error' ); 
  373. } else { 
  374. bp_core_add_message( __( 'The topic was edited successfully', 'buddypress') ); 
  375.  
  376. /** 
  377. * Fires after a group forum topic has been edited. 
  378. * 
  379. * @since 1.1.0 
  380. * 
  381. * @param int $topic_id ID of the topic being edited. 
  382. */ 
  383. do_action( 'groups_edit_forum_topic', $topic_id ); 
  384. bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic_slug . '/' ); 
  385.  
  386. /** 
  387. * Filters the template to load for a topic edit page. 
  388. * 
  389. * @since 1.1.0 
  390. * 
  391. * @param string $value Path to a topic edit template. 
  392. */ 
  393. bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/home' ) ); 
  394.  
  395. // Delete a post. 
  396. } elseif ( empty( $user_is_banned ) && bp_is_action_variable( 'delete', 2 ) && $post_id = bp_action_variable( 4 ) ) { 
  397. // Fetch the post. 
  398. $post = bp_forums_get_post( $post_id ); 
  399.  
  400. // Check the logged in user can edit this topic. 
  401. if ( ! bp_is_item_admin() && ! bp_is_item_mod() && ( (int) bp_loggedin_user_id() != (int) $post->poster_id ) ) { 
  402. bp_core_redirect( wp_get_referer() ); 
  403.  
  404. // Check the nonce. 
  405. check_admin_referer( 'bp_forums_delete_post' ); 
  406.  
  407. /** 
  408. * Fires before the deletion of a group forum post. 
  409. * 
  410. * @since 1.5.0 
  411. * 
  412. * @param int $post_id ID of the forum post being deleted. 
  413. */ 
  414. do_action( 'groups_before_delete_forum_post', $post_id ); 
  415.  
  416. if ( !groups_delete_group_forum_post( $post_id ) ) { 
  417. bp_core_add_message( __( 'There was an error deleting that post', 'buddypress'), 'error' ); 
  418. } else { 
  419. bp_core_add_message( __( 'The post was deleted successfully', 'buddypress') ); 
  420.  
  421. /** 
  422. * Fires after the deletion of a group forum post. 
  423. * 
  424. * @since 1.1.0 
  425. * 
  426. * @param int $post_id ID of the forum post being deleted. 
  427. */ 
  428. do_action( 'groups_delete_forum_post', $post_id ); 
  429. bp_core_redirect( wp_get_referer() ); 
  430.  
  431. // Editing a post. 
  432. } elseif ( empty( $user_is_banned ) && bp_is_action_variable( 'edit', 2 ) && $post_id = bp_action_variable( 4 ) ) { 
  433.  
  434. // Fetch the post. 
  435. $post = bp_forums_get_post( $post_id ); 
  436.  
  437. // Check the logged in user can edit this topic. 
  438. if ( ! bp_is_item_admin() && ! bp_is_item_mod() && ( (int) bp_loggedin_user_id() != (int) $post->poster_id ) ) { 
  439. bp_core_redirect( wp_get_referer() ); 
  440.  
  441. if ( isset( $_POST['save_changes'] ) ) { 
  442. // Check the nonce. 
  443. check_admin_referer( 'bp_forums_edit_post' ); 
  444.  
  445. $topic_page = isset( $_GET['topic_page'] ) ? $_GET['topic_page'] : false; 
  446.  
  447. if ( !$post_id = groups_update_group_forum_post( $post_id, $_POST['post_text'], $topic_id, $topic_page ) ) { 
  448. bp_core_add_message( __( 'There was an error when editing that post', 'buddypress'), 'error' ); 
  449. } else { 
  450. bp_core_add_message( __( 'The post was edited successfully', 'buddypress') ); 
  451.  
  452. if ( $_SERVER['QUERY_STRING'] ) { 
  453. $query_vars = '?' . $_SERVER['QUERY_STRING']; 
  454.  
  455. /** 
  456. * Fires after the editing of a group forum post. 
  457. * 
  458. * @since 1.1.0 
  459. * 
  460. * @param int $post_id ID of the forum post being edited. 
  461. */ 
  462. do_action( 'groups_edit_forum_post', $post_id ); 
  463. bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic_slug . '/' . $query_vars . '#post-' . $post_id ); 
  464.  
  465. /** This filter is documented in bp-groups/bp-groups-screens.php */ 
  466. bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/home' ) ); 
  467.  
  468. // Standard topic display. 
  469. } else { 
  470. if ( !empty( $user_is_banned ) ) { 
  471. bp_core_add_message( __( "You have been banned from this group.", 'buddypress' ) ); 
  472.  
  473. /** 
  474. * Filters the template to load for a topic page. 
  475. * 
  476. * @since 1.1.0 
  477. * 
  478. * @param string $value Path to a topic template. 
  479. */ 
  480. bp_core_load_template( apply_filters( 'groups_template_group_forum_topic', 'groups/single/home' ) ); 
  481.  
  482. // Forum topic does not exist. 
  483. } elseif ( !empty( $topic_slug ) && empty( $topic_id ) ) { 
  484. bp_do_404(); 
  485. return; 
  486.  
  487. } else { 
  488. // Posting a topic. 
  489. if ( isset( $_POST['submit_topic'] ) && bp_is_active( 'forums' ) ) { 
  490.  
  491. // Check the nonce. 
  492. check_admin_referer( 'bp_forums_new_topic' ); 
  493.  
  494. if ( $user_is_banned ) { 
  495. $error_message = __( "You have been banned from this group.", 'buddypress' ); 
  496.  
  497. } elseif ( bp_groups_auto_join() && !bp_current_user_can( 'bp_moderate' ) && 'public' == $bp->groups->current_group->status && !groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) { 
  498. // Auto join this user if they are not yet a member of this group. 
  499. groups_join_group( $bp->groups->current_group->id, bp_loggedin_user_id() ); 
  500.  
  501. if ( empty( $_POST['topic_title'] ) ) { 
  502. $error_message = __( 'Please provide a title for your forum topic.', 'buddypress' ); 
  503. } elseif ( empty( $_POST['topic_text'] ) ) { 
  504. $error_message = __( 'Forum posts cannot be empty. Please enter some text.', 'buddypress' ); 
  505.  
  506. if ( empty( $forum_id ) ) { 
  507. $error_message = __( 'This group does not have a forum setup yet.', 'buddypress' ); 
  508.  
  509. if ( isset( $error_message ) ) { 
  510. bp_core_add_message( $error_message, 'error' ); 
  511. $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum'; 
  512. } else { 
  513. if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) ) { 
  514. bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' ); 
  515. $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum'; 
  516. } else { 
  517. bp_core_add_message( __( 'The topic was created successfully', 'buddypress') ); 
  518. $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/'; 
  519.  
  520. bp_core_redirect( $redirect ); 
  521.  
  522. /** 
  523. * Fires at the end of the group forum screen loading process. 
  524. * 
  525. * @since 1.0.0 
  526. * 
  527. * @param int $topic_id ID of the topic being displayed. 
  528. * @param int $forum_id ID of the forum being displayed. 
  529. */ 
  530. do_action( 'groups_screen_group_forum', $topic_id, $forum_id ); 
  531.  
  532. /** 
  533. * Filters the template to load for a group forum page. 
  534. * 
  535. * @since 1.0.0 
  536. * 
  537. * @param string $value Path to a group forum template. 
  538. */ 
  539. bp_core_load_template( apply_filters( 'groups_template_group_forum', 'groups/single/home' ) ); 
  540.  
  541. /** 
  542. * Handle the display of a group's Members page. 
  543. * 
  544. * @since 1.0.0 
  545. */ 
  546. function groups_screen_group_members() { 
  547.  
  548. if ( !bp_is_single_item() ) 
  549. return false; 
  550.  
  551. $bp = buddypress(); 
  552.  
  553. // Refresh the group member count meta. 
  554. groups_update_groupmeta( $bp->groups->current_group->id, 'total_member_count', groups_get_total_member_count( $bp->groups->current_group->id ) ); 
  555.  
  556. /** 
  557. * Fires before the loading of a group's Members page. 
  558. * 
  559. * @since 1.0.0 
  560. * 
  561. * @param int $id ID of the group whose members are being displayed. 
  562. */ 
  563. do_action( 'groups_screen_group_members', $bp->groups->current_group->id ); 
  564.  
  565. /** 
  566. * Filters the template to load for a group's Members page. 
  567. * 
  568. * @since 1.0.0 
  569. * 
  570. * @param string $value Path to a group's Members template. 
  571. */ 
  572. bp_core_load_template( apply_filters( 'groups_template_group_members', 'groups/single/home' ) ); 
  573.  
  574. /** 
  575. * Handle the display of a group's Send Invites page. 
  576. * 
  577. * @since 1.0.0 
  578. */ 
  579. function groups_screen_group_invite() { 
  580.  
  581. if ( !bp_is_single_item() ) 
  582. return false; 
  583.  
  584. $bp = buddypress(); 
  585.  
  586. if ( bp_is_action_variable( 'send', 0 ) ) { 
  587.  
  588. if ( !check_admin_referer( 'groups_send_invites', '_wpnonce_send_invites' ) ) 
  589. return false; 
  590.  
  591. if ( !empty( $_POST['friends'] ) ) { 
  592. foreach( (array) $_POST['friends'] as $friend ) { 
  593. groups_invite_user( array( 'user_id' => $friend, 'group_id' => $bp->groups->current_group->id ) ); 
  594.  
  595. // Send the invites. 
  596. groups_send_invites( bp_loggedin_user_id(), $bp->groups->current_group->id ); 
  597. bp_core_add_message( __('Group invites sent.', 'buddypress') ); 
  598.  
  599. /** 
  600. * Fires after the sending of a group invite inside the group's Send Invites page. 
  601. * 
  602. * @since 1.0.0 
  603. * 
  604. * @param int $id ID of the group whose members are being displayed. 
  605. */ 
  606. do_action( 'groups_screen_group_invite', $bp->groups->current_group->id ); 
  607. bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) ); 
  608.  
  609. } elseif ( !bp_action_variable( 0 ) ) { 
  610.  
  611. /** 
  612. * Filters the template to load for a group's Send Invites page. 
  613. * 
  614. * @since 1.0.0 
  615. * 
  616. * @param string $value Path to a group's Send Invites template. 
  617. */ 
  618. bp_core_load_template( apply_filters( 'groups_template_group_invite', 'groups/single/home' ) ); 
  619.  
  620. } else { 
  621. bp_do_404(); 
  622.  
  623. /** 
  624. * Process group invitation removal requests. 
  625. * 
  626. * Note that this function is only used when JS is disabled. Normally, clicking 
  627. * Remove Invite removes the invitation via AJAX. 
  628. * 
  629. * @since 2.0.0 
  630. */ 
  631. function groups_remove_group_invite() { 
  632. if ( ! bp_is_group_invites() ) { 
  633. return; 
  634.  
  635. if ( ! bp_is_action_variable( 'remove', 0 ) || ! is_numeric( bp_action_variable( 1 ) ) ) { 
  636. return; 
  637.  
  638. if ( ! check_admin_referer( 'groups_invite_uninvite_user' ) ) { 
  639. return false; 
  640.  
  641. $friend_id = intval( bp_action_variable( 1 ) ); 
  642. $group_id = bp_get_current_group_id(); 
  643. $message = __( 'Invite successfully removed', 'buddypress' ); 
  644. $redirect = wp_get_referer(); 
  645. $error = false; 
  646.  
  647. if ( ! bp_groups_user_can_send_invites( $group_id ) ) { 
  648. $message = __( 'You are not allowed to send or remove invites', 'buddypress' ); 
  649. $error = 'error'; 
  650. } elseif ( groups_check_for_membership_request( $friend_id, $group_id ) ) { 
  651. $message = __( 'The member requested to join the group', 'buddypress' ); 
  652. $error = 'error'; 
  653. } elseif ( ! groups_uninvite_user( $friend_id, $group_id ) ) { 
  654. $message = __( 'There was an error removing the invite', 'buddypress' ); 
  655. $error = 'error'; 
  656.  
  657. bp_core_add_message( $message, $error ); 
  658. bp_core_redirect( $redirect ); 
  659. add_action( 'bp_screens', 'groups_remove_group_invite' ); 
  660.  
  661. /** 
  662. * Handle the display of a group's Request Membership page. 
  663. * 
  664. * @since 1.0.0 
  665. */ 
  666. function groups_screen_group_request_membership() { 
  667.  
  668. if ( !is_user_logged_in() ) 
  669. return false; 
  670.  
  671. $bp = buddypress(); 
  672.  
  673. if ( 'private' != $bp->groups->current_group->status ) 
  674. return false; 
  675.  
  676. // If the user is already invited, accept invitation. 
  677. if ( groups_check_user_has_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) { 
  678. if ( groups_accept_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) 
  679. bp_core_add_message( __( 'Group invite accepted', 'buddypress' ) ); 
  680. else 
  681. bp_core_add_message( __( 'There was an error accepting the group invitation. Please try again.', 'buddypress' ), 'error' ); 
  682. bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) ); 
  683.  
  684. // If the user has submitted a request, send it. 
  685. if ( isset( $_POST['group-request-send']) ) { 
  686.  
  687. // Check the nonce. 
  688. if ( !check_admin_referer( 'groups_request_membership' ) ) 
  689. return false; 
  690.  
  691. if ( !groups_send_membership_request( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) { 
  692. bp_core_add_message( __( 'There was an error sending your group membership request. Please try again.', 'buddypress' ), 'error' ); 
  693. } else { 
  694. bp_core_add_message( __( 'Your membership request was sent to the group administrator successfully. You will be notified when the group administrator responds to your request.', 'buddypress' ) ); 
  695. bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) ); 
  696.  
  697. /** 
  698. * Fires before the loading of a group's Request Memebership page. 
  699. * 
  700. * @since 1.0.0 
  701. * 
  702. * @param int $id ID of the group currently being displayed. 
  703. */ 
  704. do_action( 'groups_screen_group_request_membership', $bp->groups->current_group->id ); 
  705.  
  706. /** 
  707. * Filters the template to load for a group's Request Membership page. 
  708. * 
  709. * @since 1.0.0 
  710. * 
  711. * @param string $value Path to a group's Request Membership template. 
  712. */ 
  713. bp_core_load_template( apply_filters( 'groups_template_group_request_membership', 'groups/single/home' ) ); 
  714.  
  715. /** 
  716. * Handle the loading of a single group's activity. 
  717. * 
  718. * @since 2.4.0 
  719. */ 
  720. function groups_screen_group_activity() { 
  721.  
  722. if ( ! bp_is_single_item() ) { 
  723. return false; 
  724.  
  725. /** 
  726. * Fires before the loading of a single group's activity page. 
  727. * 
  728. * @since 2.4.0 
  729. */ 
  730. do_action( 'groups_screen_group_activity' ); 
  731.  
  732. /** 
  733. * Filters the template to load for a single group's activity page. 
  734. * 
  735. * @since 2.4.0 
  736. * 
  737. * @param string $value Path to a single group's template to load. 
  738. */ 
  739. bp_core_load_template( apply_filters( 'groups_screen_group_activity', 'groups/single/activity' ) ); 
  740.  
  741. /** 
  742. * Handle the display of a single group activity item. 
  743. * 
  744. * @since 1.2.0 
  745. */ 
  746. function groups_screen_group_activity_permalink() { 
  747.  
  748. if ( !bp_is_groups_component() || !bp_is_active( 'activity' ) || ( bp_is_active( 'activity' ) && !bp_is_current_action( bp_get_activity_slug() ) ) || !bp_action_variable( 0 ) ) 
  749. return false; 
  750.  
  751. buddypress()->is_single_item = true; 
  752.  
  753. /** This filter is documented in bp-groups/bp-groups-screens.php */ 
  754. bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) ); 
  755. add_action( 'bp_screens', 'groups_screen_group_activity_permalink' ); 
  756.  
  757. /** 
  758. * Handle the display of a group's Admin pages. 
  759. * 
  760. * @since 1.0.0 
  761. */ 
  762. function groups_screen_group_admin() { 
  763. if ( !bp_is_groups_component() || !bp_is_current_action( 'admin' ) ) 
  764. return false; 
  765.  
  766. if ( bp_action_variables() ) 
  767. return false; 
  768.  
  769. bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/edit-details/' ); 
  770.  
  771. /** 
  772. * Handle the display of a group's admin/edit-details page. 
  773. * 
  774. * @since 1.0.0 
  775. */ 
  776. function groups_screen_group_admin_edit_details() { 
  777.  
  778. if ( 'edit-details' != bp_get_group_current_admin_tab() ) 
  779. return false; 
  780.  
  781. if ( bp_is_item_admin() ) { 
  782.  
  783. $bp = buddypress(); 
  784.  
  785. // If the edit form has been submitted, save the edited details. 
  786. if ( isset( $_POST['save'] ) ) { 
  787. // Check the nonce. 
  788. if ( !check_admin_referer( 'groups_edit_group_details' ) ) 
  789. return false; 
  790.  
  791. $group_notify_members = isset( $_POST['group-notify-members'] ) ? (int) $_POST['group-notify-members'] : 0; 
  792.  
  793. if ( !groups_edit_base_group_details( $_POST['group-id'], $_POST['group-name'], $_POST['group-desc'], $group_notify_members ) ) { 
  794. bp_core_add_message( __( 'There was an error updating group details. Please try again.', 'buddypress' ), 'error' ); 
  795. } else { 
  796. bp_core_add_message( __( 'Group details were successfully updated.', 'buddypress' ) ); 
  797.  
  798. /** 
  799. * Fires before the redirect if a group details has been edited and saved. 
  800. * 
  801. * @since 1.0.0 
  802. * 
  803. * @param int $id ID of the group that was edited. 
  804. */ 
  805. do_action( 'groups_group_details_edited', $bp->groups->current_group->id ); 
  806.  
  807. bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/edit-details/' ); 
  808.  
  809. /** 
  810. * Fires before the loading of the group admin/edit-details page template. 
  811. * 
  812. * @since 1.0.0 
  813. * 
  814. * @param int $id ID of the group that is being displayed. 
  815. */ 
  816. do_action( 'groups_screen_group_admin_edit_details', $bp->groups->current_group->id ); 
  817.  
  818. /** 
  819. * Filters the template to load for a group's admin/edit-details page. 
  820. * 
  821. * @since 1.0.0 
  822. * 
  823. * @param string $value Path to a group's admin/edit-details template. 
  824. */ 
  825. bp_core_load_template( apply_filters( 'groups_template_group_admin', 'groups/single/home' ) ); 
  826. add_action( 'bp_screens', 'groups_screen_group_admin_edit_details' ); 
  827.  
  828. /** 
  829. * Handle the display of a group's admin/group-settings page. 
  830. * 
  831. * @since 1.0.0 
  832. */ 
  833. function groups_screen_group_admin_settings() { 
  834.  
  835. if ( 'group-settings' != bp_get_group_current_admin_tab() ) 
  836. return false; 
  837.  
  838. if ( ! bp_is_item_admin() ) 
  839. return false; 
  840.  
  841. $bp = buddypress(); 
  842.  
  843. // If the edit form has been submitted, save the edited details. 
  844. if ( isset( $_POST['save'] ) ) { 
  845. $enable_forum = ( isset($_POST['group-show-forum'] ) ) ? 1 : 0; 
  846.  
  847. // Checked against a whitelist for security. 
  848. /** This filter is documented in bp-groups/bp-groups-admin.php */ 
  849. $allowed_status = apply_filters( 'groups_allowed_status', array( 'public', 'private', 'hidden' ) ); 
  850. $status = ( in_array( $_POST['group-status'], (array) $allowed_status ) ) ? $_POST['group-status'] : 'public'; 
  851.  
  852. // Checked against a whitelist for security. 
  853. /** This filter is documented in bp-groups/bp-groups-admin.php */ 
  854. $allowed_invite_status = apply_filters( 'groups_allowed_invite_status', array( 'members', 'mods', 'admins' ) ); 
  855. $invite_status = isset( $_POST['group-invite-status'] ) && in_array( $_POST['group-invite-status'], (array) $allowed_invite_status ) ? $_POST['group-invite-status'] : 'members'; 
  856.  
  857. // Check the nonce. 
  858. if ( !check_admin_referer( 'groups_edit_group_settings' ) ) 
  859. return false; 
  860.  
  861. /** 
  862. * Save group types. 
  863. * 
  864. * Ensure we keep types that have 'show_in_create_screen' set to false. 
  865. */ 
  866. $current_types = bp_groups_get_group_type( bp_get_current_group_id(), false ); 
  867. $current_types = array_intersect( bp_groups_get_group_types( array( 'show_in_create_screen' => false ) ), (array) $current_types ); 
  868. if ( isset( $_POST['group-types'] ) ) { 
  869. $current_types = array_merge( $current_types, $_POST['group-types'] ); 
  870.  
  871. // Set group types. 
  872. bp_groups_set_group_type( bp_get_current_group_id(), $current_types ); 
  873.  
  874. // No group types checked, so this means we want to wipe out all group types. 
  875. } else { 
  876. /** 
  877. * Passing a blank string will wipe out all types for the group. 
  878. * 
  879. * Ensure we keep types that have 'show_in_create_screen' set to false. 
  880. */ 
  881. $current_types = empty( $current_types ) ? '' : $current_types; 
  882.  
  883. // Set group types. 
  884. bp_groups_set_group_type( bp_get_current_group_id(), $current_types ); 
  885.  
  886. if ( !groups_edit_group_settings( $_POST['group-id'], $enable_forum, $status, $invite_status ) ) { 
  887. bp_core_add_message( __( 'There was an error updating group settings. Please try again.', 'buddypress' ), 'error' ); 
  888. } else { 
  889. bp_core_add_message( __( 'Group settings were successfully updated.', 'buddypress' ) ); 
  890.  
  891. /** 
  892. * Fires before the redirect if a group settings has been edited and saved. 
  893. * 
  894. * @since 1.0.0 
  895. * 
  896. * @param int $id ID of the group that was edited. 
  897. */ 
  898. do_action( 'groups_group_settings_edited', $bp->groups->current_group->id ); 
  899.  
  900. bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/group-settings/' ); 
  901.  
  902. /** 
  903. * Fires before the loading of the group admin/group-settings page template. 
  904. * 
  905. * @since 1.0.0 
  906. * 
  907. * @param int $id ID of the group that is being displayed. 
  908. */ 
  909. do_action( 'groups_screen_group_admin_settings', $bp->groups->current_group->id ); 
  910.  
  911. /** 
  912. * Filters the template to load for a group's admin/group-settings page. 
  913. * 
  914. * @since 1.0.0 
  915. * 
  916. * @param string $value Path to a group's admin/group-settings template. 
  917. */ 
  918. bp_core_load_template( apply_filters( 'groups_template_group_admin_settings', 'groups/single/home' ) ); 
  919. add_action( 'bp_screens', 'groups_screen_group_admin_settings' ); 
  920.  
  921. /** 
  922. * Handle the display of a group's Change Avatar page. 
  923. * 
  924. * @since 1.0.0 
  925. */ 
  926. function groups_screen_group_admin_avatar() { 
  927.  
  928. if ( 'group-avatar' != bp_get_group_current_admin_tab() ) 
  929. return false; 
  930.  
  931. // If the logged-in user doesn't have permission or if avatar uploads are disabled, then stop here. 
  932. if ( ! bp_is_item_admin() || bp_disable_group_avatar_uploads() || ! buddypress()->avatar->show_avatars ) 
  933. return false; 
  934.  
  935. $bp = buddypress(); 
  936.  
  937. // If the group admin has deleted the admin avatar. 
  938. if ( bp_is_action_variable( 'delete', 1 ) ) { 
  939.  
  940. // Check the nonce. 
  941. check_admin_referer( 'bp_group_avatar_delete' ); 
  942.  
  943. if ( bp_core_delete_existing_avatar( array( 'item_id' => $bp->groups->current_group->id, 'object' => 'group' ) ) ) { 
  944. bp_core_add_message( __( 'The group profile photo was deleted successfully!', 'buddypress' ) ); 
  945. } else { 
  946. bp_core_add_message( __( 'There was a problem deleting the group profile photo. Please try again.', 'buddypress' ), 'error' ); 
  947.  
  948. if ( ! isset( $bp->avatar_admin ) ) { 
  949. $bp->avatar_admin = new stdClass(); 
  950.  
  951. $bp->avatar_admin->step = 'upload-image'; 
  952.  
  953. if ( !empty( $_FILES ) ) { 
  954.  
  955. // Check the nonce. 
  956. check_admin_referer( 'bp_avatar_upload' ); 
  957.  
  958. // Pass the file to the avatar upload handler. 
  959. if ( bp_core_avatar_handle_upload( $_FILES, 'groups_avatar_upload_dir' ) ) { 
  960. $bp->avatar_admin->step = 'crop-image'; 
  961.  
  962. // Make sure we include the jQuery jCrop file for image cropping. 
  963. add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' ); 
  964.  
  965.  
  966. // If the image cropping is done, crop the image and save a full/thumb version. 
  967. if ( isset( $_POST['avatar-crop-submit'] ) ) { 
  968.  
  969. // Check the nonce. 
  970. check_admin_referer( 'bp_avatar_cropstore' ); 
  971.  
  972. $args = array( 
  973. 'object' => 'group',  
  974. 'avatar_dir' => 'group-avatars',  
  975. 'item_id' => $bp->groups->current_group->id,  
  976. 'original_file' => $_POST['image_src'],  
  977. 'crop_x' => $_POST['x'],  
  978. 'crop_y' => $_POST['y'],  
  979. 'crop_w' => $_POST['w'],  
  980. 'crop_h' => $_POST['h'] 
  981. ); 
  982.  
  983. if ( !bp_core_avatar_handle_crop( $args ) ) { 
  984. bp_core_add_message( __( 'There was a problem cropping the group profile photo.', 'buddypress' ), 'error' ); 
  985. } else { 
  986. bp_core_add_message( __( 'The new group profile photo was uploaded successfully.', 'buddypress' ) ); 
  987.  
  988. /** 
  989. * Fires before the loading of the group Change Avatar page template. 
  990. * 
  991. * @since 1.0.0 
  992. * 
  993. * @param int $id ID of the group that is being displayed. 
  994. */ 
  995. do_action( 'groups_screen_group_admin_avatar', $bp->groups->current_group->id ); 
  996.  
  997. /** 
  998. * Filters the template to load for a group's Change Avatar page. 
  999. * 
  1000. * @since 1.0.0 
  1001. * 
  1002. * @param string $value Path to a group's Change Avatar template. 
  1003. */ 
  1004. bp_core_load_template( apply_filters( 'groups_template_group_admin_avatar', 'groups/single/home' ) ); 
  1005. add_action( 'bp_screens', 'groups_screen_group_admin_avatar' ); 
  1006.  
  1007. /** 
  1008. * Handle the display of a group's Change cover image page. 
  1009. * 
  1010. * @since 2.4.0 
  1011. */ 
  1012. function groups_screen_group_admin_cover_image() { 
  1013. if ( 'group-cover-image' != bp_get_group_current_admin_tab() ) { 
  1014. return false; 
  1015.  
  1016. // If the logged-in user doesn't have permission or if cover image uploads are disabled, then stop here. 
  1017. if ( ! bp_is_item_admin() || ! bp_group_use_cover_image_header() ) { 
  1018. return false; 
  1019.  
  1020. /** 
  1021. * Fires before the loading of the group Change cover image page template. 
  1022. * 
  1023. * @since 2.4.0 
  1024. * 
  1025. * @param int $id ID of the group that is being displayed. 
  1026. */ 
  1027. do_action( 'groups_screen_group_admin_cover_image', bp_get_current_group_id() ); 
  1028.  
  1029. /** 
  1030. * Filters the template to load for a group's Change cover image page. 
  1031. * 
  1032. * @since 2.4.0 
  1033. * 
  1034. * @param string $value Path to a group's Change cover image template. 
  1035. */ 
  1036. bp_core_load_template( apply_filters( 'groups_template_group_admin_cover_image', 'groups/single/home' ) ); 
  1037. add_action( 'bp_screens', 'groups_screen_group_admin_cover_image' ); 
  1038.  
  1039. /** 
  1040. * This function handles actions related to member management on the group admin. 
  1041. * 
  1042. * @since 1.0.0 
  1043. */ 
  1044. function groups_screen_group_admin_manage_members() { 
  1045.  
  1046. if ( 'manage-members' != bp_get_group_current_admin_tab() ) 
  1047. return false; 
  1048.  
  1049. if ( ! bp_is_item_admin() ) 
  1050. return false; 
  1051.  
  1052. $bp = buddypress(); 
  1053.  
  1054. if ( bp_action_variable( 1 ) && bp_action_variable( 2 ) && bp_action_variable( 3 ) ) { 
  1055. if ( bp_is_action_variable( 'promote', 1 ) && ( bp_is_action_variable( 'mod', 2 ) || bp_is_action_variable( 'admin', 2 ) ) && is_numeric( bp_action_variable( 3 ) ) ) { 
  1056. $user_id = bp_action_variable( 3 ); 
  1057. $status = bp_action_variable( 2 ); 
  1058.  
  1059. // Check the nonce first. 
  1060. if ( !check_admin_referer( 'groups_promote_member' ) ) 
  1061. return false; 
  1062.  
  1063. // Promote a user. 
  1064. if ( !groups_promote_member( $user_id, $bp->groups->current_group->id, $status ) ) 
  1065. bp_core_add_message( __( 'There was an error when promoting that user. Please try again.', 'buddypress' ), 'error' ); 
  1066. else 
  1067. bp_core_add_message( __( 'User promoted successfully', 'buddypress' ) ); 
  1068.  
  1069. /** 
  1070. * Fires before the redirect after a group member has been promoted. 
  1071. * 
  1072. * @since 1.0.0 
  1073. * 
  1074. * @param int $user_id ID of the user being promoted. 
  1075. * @param int $id ID of the group user is promoted within. 
  1076. */ 
  1077. do_action( 'groups_promoted_member', $user_id, $bp->groups->current_group->id ); 
  1078.  
  1079. bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' ); 
  1080.  
  1081. if ( bp_action_variable( 1 ) && bp_action_variable( 2 ) ) { 
  1082. if ( bp_is_action_variable( 'demote', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) { 
  1083. $user_id = bp_action_variable( 2 ); 
  1084.  
  1085. // Check the nonce first. 
  1086. if ( !check_admin_referer( 'groups_demote_member' ) ) 
  1087. return false; 
  1088.  
  1089. // Stop sole admins from abandoning their group. 
  1090. $group_admins = groups_get_group_admins( $bp->groups->current_group->id ); 
  1091. if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == $user_id ) 
  1092. bp_core_add_message( __( 'This group must have at least one admin', 'buddypress' ), 'error' ); 
  1093.  
  1094. // Demote a user. 
  1095. elseif ( !groups_demote_member( $user_id, $bp->groups->current_group->id ) ) 
  1096. bp_core_add_message( __( 'There was an error when demoting that user. Please try again.', 'buddypress' ), 'error' ); 
  1097. else 
  1098. bp_core_add_message( __( 'User demoted successfully', 'buddypress' ) ); 
  1099.  
  1100. /** 
  1101. * Fires before the redirect after a group member has been demoted. 
  1102. * 
  1103. * @since 1.0.0 
  1104. * 
  1105. * @param int $user_id ID of the user being demoted. 
  1106. * @param int $id ID of the group user is demoted within. 
  1107. */ 
  1108. do_action( 'groups_demoted_member', $user_id, $bp->groups->current_group->id ); 
  1109.  
  1110. bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' ); 
  1111.  
  1112. if ( bp_is_action_variable( 'ban', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) { 
  1113. $user_id = bp_action_variable( 2 ); 
  1114.  
  1115. // Check the nonce first. 
  1116. if ( !check_admin_referer( 'groups_ban_member' ) ) 
  1117. return false; 
  1118.  
  1119. // Ban a user. 
  1120. if ( !groups_ban_member( $user_id, $bp->groups->current_group->id ) ) 
  1121. bp_core_add_message( __( 'There was an error when banning that user. Please try again.', 'buddypress' ), 'error' ); 
  1122. else 
  1123. bp_core_add_message( __( 'User banned successfully', 'buddypress' ) ); 
  1124.  
  1125. /** 
  1126. * Fires before the redirect after a group member has been banned. 
  1127. * 
  1128. * @since 1.0.0 
  1129. * 
  1130. * @param int $user_id ID of the user being banned. 
  1131. * @param int $id ID of the group user is banned from. 
  1132. */ 
  1133. do_action( 'groups_banned_member', $user_id, $bp->groups->current_group->id ); 
  1134.  
  1135. bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' ); 
  1136.  
  1137. if ( bp_is_action_variable( 'unban', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) { 
  1138. $user_id = bp_action_variable( 2 ); 
  1139.  
  1140. // Check the nonce first. 
  1141. if ( !check_admin_referer( 'groups_unban_member' ) ) 
  1142. return false; 
  1143.  
  1144. // Remove a ban for user. 
  1145. if ( !groups_unban_member( $user_id, $bp->groups->current_group->id ) ) 
  1146. bp_core_add_message( __( 'There was an error when unbanning that user. Please try again.', 'buddypress' ), 'error' ); 
  1147. else 
  1148. bp_core_add_message( __( 'User ban removed successfully', 'buddypress' ) ); 
  1149.  
  1150. /** 
  1151. * Fires before the redirect after a group member has been unbanned. 
  1152. * 
  1153. * @since 1.0.0 
  1154. * 
  1155. * @param int $user_id ID of the user being unbanned. 
  1156. * @param int $id ID of the group user is unbanned from. 
  1157. */ 
  1158. do_action( 'groups_unbanned_member', $user_id, $bp->groups->current_group->id ); 
  1159.  
  1160. bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' ); 
  1161.  
  1162. if ( bp_is_action_variable( 'remove', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) { 
  1163. $user_id = bp_action_variable( 2 ); 
  1164.  
  1165. // Check the nonce first. 
  1166. if ( !check_admin_referer( 'groups_remove_member' ) ) 
  1167. return false; 
  1168.  
  1169. // Remove a user. 
  1170. if ( !groups_remove_member( $user_id, $bp->groups->current_group->id ) ) 
  1171. bp_core_add_message( __( 'There was an error removing that user from the group. Please try again.', 'buddypress' ), 'error' ); 
  1172. else 
  1173. bp_core_add_message( __( 'User removed successfully', 'buddypress' ) ); 
  1174.  
  1175. /** 
  1176. * Fires before the redirect after a group member has been removed. 
  1177. * 
  1178. * @since 1.2.6 
  1179. * 
  1180. * @param int $user_id ID of the user being removed. 
  1181. * @param int $id ID of the group the user is removed from. 
  1182. */ 
  1183. do_action( 'groups_removed_member', $user_id, $bp->groups->current_group->id ); 
  1184.  
  1185. bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' ); 
  1186.  
  1187. /** 
  1188. * Fires before the loading of a group's manage members template. 
  1189. * 
  1190. * @since 1.0.0 
  1191. * 
  1192. * @param int $id ID of the group whose manage members page is being displayed. 
  1193. */ 
  1194. do_action( 'groups_screen_group_admin_manage_members', $bp->groups->current_group->id ); 
  1195.  
  1196. /** 
  1197. * Filters the template to load for a group's manage members page. 
  1198. * 
  1199. * @since 1.0.0 
  1200. * 
  1201. * @param string $value Path to a group's manage members template. 
  1202. */ 
  1203. bp_core_load_template( apply_filters( 'groups_template_group_admin_manage_members', 'groups/single/home' ) ); 
  1204. add_action( 'bp_screens', 'groups_screen_group_admin_manage_members' ); 
  1205.  
  1206. /** 
  1207. * Handle the display of Admin > Membership Requests. 
  1208. * 
  1209. * @since 1.0.0 
  1210. */ 
  1211. function groups_screen_group_admin_requests() { 
  1212. $bp = buddypress(); 
  1213.  
  1214. if ( 'membership-requests' != bp_get_group_current_admin_tab() ) { 
  1215. return false; 
  1216.  
  1217. if ( ! bp_is_item_admin() || ( 'public' == $bp->groups->current_group->status ) ) { 
  1218. return false; 
  1219.  
  1220. $request_action = (string) bp_action_variable( 1 ); 
  1221. $membership_id = (int) bp_action_variable( 2 ); 
  1222.  
  1223. if ( !empty( $request_action ) && !empty( $membership_id ) ) { 
  1224. if ( 'accept' == $request_action && is_numeric( $membership_id ) ) { 
  1225.  
  1226. // Check the nonce first. 
  1227. if ( !check_admin_referer( 'groups_accept_membership_request' ) ) 
  1228. return false; 
  1229.  
  1230. // Accept the membership request. 
  1231. if ( !groups_accept_membership_request( $membership_id ) ) 
  1232. bp_core_add_message( __( 'There was an error accepting the membership request. Please try again.', 'buddypress' ), 'error' ); 
  1233. else 
  1234. bp_core_add_message( __( 'Group membership request accepted', 'buddypress' ) ); 
  1235.  
  1236. } elseif ( 'reject' == $request_action && is_numeric( $membership_id ) ) { 
  1237. /** Check the nonce first. */ 
  1238. if ( !check_admin_referer( 'groups_reject_membership_request' ) ) 
  1239. return false; 
  1240.  
  1241. // Reject the membership request. 
  1242. if ( !groups_reject_membership_request( $membership_id ) ) 
  1243. bp_core_add_message( __( 'There was an error rejecting the membership request. Please try again.', 'buddypress' ), 'error' ); 
  1244. else 
  1245. bp_core_add_message( __( 'Group membership request rejected', 'buddypress' ) ); 
  1246.  
  1247. /** 
  1248. * Fires before the redirect if a group membership request has been handled. 
  1249. * 
  1250. * @since 1.0.0 
  1251. * 
  1252. * @param int $id ID of the group that was edited. 
  1253. * @param string $request_action Membership request action being performed. 
  1254. * @param int $membership_id The key of the action_variables array that you want. 
  1255. */ 
  1256. do_action( 'groups_group_request_managed', $bp->groups->current_group->id, $request_action, $membership_id ); 
  1257. bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/membership-requests/' ); 
  1258.  
  1259. /** 
  1260. * Fires before the loading of the group membership request page template. 
  1261. * 
  1262. * @since 1.0.0 
  1263. * 
  1264. * @param int $id ID of the group that is being displayed. 
  1265. */ 
  1266. do_action( 'groups_screen_group_admin_requests', $bp->groups->current_group->id ); 
  1267.  
  1268. /** 
  1269. * Filters the template to load for a group's membership request page. 
  1270. * 
  1271. * @since 1.0.0 
  1272. * 
  1273. * @param string $value Path to a group's membership request template. 
  1274. */ 
  1275. bp_core_load_template( apply_filters( 'groups_template_group_admin_requests', 'groups/single/home' ) ); 
  1276. add_action( 'bp_screens', 'groups_screen_group_admin_requests' ); 
  1277.  
  1278. /** 
  1279. * Handle the display of the Delete Group page. 
  1280. * 
  1281. * @since 1.0.0 
  1282. */ 
  1283. function groups_screen_group_admin_delete_group() { 
  1284.  
  1285. if ( 'delete-group' != bp_get_group_current_admin_tab() ) 
  1286. return false; 
  1287.  
  1288. if ( ! bp_is_item_admin() && !bp_current_user_can( 'bp_moderate' ) ) 
  1289. return false; 
  1290.  
  1291. $bp = buddypress(); 
  1292.  
  1293. if ( isset( $_REQUEST['delete-group-button'] ) && isset( $_REQUEST['delete-group-understand'] ) ) { 
  1294.  
  1295. // Check the nonce first. 
  1296. if ( !check_admin_referer( 'groups_delete_group' ) ) { 
  1297. return false; 
  1298.  
  1299. /** 
  1300. * Fires before the deletion of a group from the Delete Group page. 
  1301. * 
  1302. * @since 1.5.0 
  1303. * 
  1304. * @param int $id ID of the group being deleted. 
  1305. */ 
  1306. do_action( 'groups_before_group_deleted', $bp->groups->current_group->id ); 
  1307.  
  1308. // Group admin has deleted the group, now do it. 
  1309. if ( !groups_delete_group( $bp->groups->current_group->id ) ) { 
  1310. bp_core_add_message( __( 'There was an error deleting the group. Please try again.', 'buddypress' ), 'error' ); 
  1311. } else { 
  1312. bp_core_add_message( __( 'The group was deleted successfully.', 'buddypress' ) ); 
  1313.  
  1314. /** 
  1315. * Fires after the deletion of a group from the Delete Group page. 
  1316. * 
  1317. * @since 1.0.0 
  1318. * 
  1319. * @param int $id ID of the group being deleted. 
  1320. */ 
  1321. do_action( 'groups_group_deleted', $bp->groups->current_group->id ); 
  1322.  
  1323. bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) ); 
  1324.  
  1325. bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) ); 
  1326.  
  1327. /** 
  1328. * Fires before the loading of the Delete Group page template. 
  1329. * 
  1330. * @since 1.0.0 
  1331. * 
  1332. * @param int $id ID of the group that is being displayed. 
  1333. */ 
  1334. do_action( 'groups_screen_group_admin_delete_group', $bp->groups->current_group->id ); 
  1335.  
  1336. /** 
  1337. * Filters the template to load for the Delete Group page. 
  1338. * 
  1339. * @since 1.0.0 
  1340. * 
  1341. * @param string $value Path to the Delete Group template. 
  1342. */ 
  1343. bp_core_load_template( apply_filters( 'groups_template_group_admin_delete_group', 'groups/single/home' ) ); 
  1344. add_action( 'bp_screens', 'groups_screen_group_admin_delete_group' ); 
  1345.  
  1346. /** 
  1347. * Render the group settings fields on the Notification Settings page. 
  1348. * 
  1349. * @since 1.0.0 
  1350. */ 
  1351. function groups_screen_notification_settings() { 
  1352.  
  1353. if ( !$group_invite = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_invite', true ) ) 
  1354. $group_invite = 'yes'; 
  1355.  
  1356. if ( !$group_update = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_group_updated', true ) ) 
  1357. $group_update = 'yes'; 
  1358.  
  1359. if ( !$group_promo = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_admin_promotion', true ) ) 
  1360. $group_promo = 'yes'; 
  1361.  
  1362. if ( !$group_request = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_membership_request', true ) ) 
  1363. $group_request = 'yes'; 
  1364.  
  1365. if ( ! $group_request_completed = bp_get_user_meta( bp_displayed_user_id(), 'notification_membership_request_completed', true ) ) { 
  1366. $group_request_completed = 'yes'; 
  1367. ?> 
  1368.  
  1369. <table class="notification-settings" id="groups-notification-settings"> 
  1370. <thead> 
  1371. <tr> 
  1372. <th class="icon"></th> 
  1373. <th class="title"><?php _ex( 'Groups', 'Group settings on notification settings page', 'buddypress' ) ?></th> 
  1374. <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th> 
  1375. <th class="no"><?php _e( 'No', 'buddypress' )?></th> 
  1376. </tr> 
  1377. </thead> 
  1378.  
  1379. <tbody> 
  1380. <tr id="groups-notification-settings-invitation"> 
  1381. <td></td> 
  1382. <td><?php _ex( 'A member invites you to join a group', 'group settings on notification settings page', 'buddypress' ) ?></td> 
  1383. <td class="yes"><input type="radio" name="notifications[notification_groups_invite]" id="notification-groups-invite-yes" value="yes" <?php checked( $group_invite, 'yes', true ) ?>/><label for="notification-groups-invite-yes" class="bp-screen-reader-text"><?php 
  1384. /** translators: accessibility text */ 
  1385. _e( 'Yes, send email', 'buddypress' ); 
  1386. ?></label></td> 
  1387. <td class="no"><input type="radio" name="notifications[notification_groups_invite]" id="notification-groups-invite-no" value="no" <?php checked( $group_invite, 'no', true ) ?>/><label for="notification-groups-invite-no" class="bp-screen-reader-text"><?php 
  1388. /** translators: accessibility text */ 
  1389. _e( 'No, do not send email', 'buddypress' ); 
  1390. ?></label></td> 
  1391. </tr> 
  1392. <tr id="groups-notification-settings-info-updated"> 
  1393. <td></td> 
  1394. <td><?php _ex( 'Group information is updated', 'group settings on notification settings page', 'buddypress' ) ?></td> 
  1395. <td class="yes"><input type="radio" name="notifications[notification_groups_group_updated]" id="notification-groups-group-updated-yes" value="yes" <?php checked( $group_update, 'yes', true ) ?>/><label for="notification-groups-group-updated-yes" class="bp-screen-reader-text"><?php 
  1396. /** translators: accessibility text */ 
  1397. _e( 'Yes, send email', 'buddypress' ); 
  1398. ?></label></td> 
  1399. <td class="no"><input type="radio" name="notifications[notification_groups_group_updated]" id="notification-groups-group-updated-no" value="no" <?php checked( $group_update, 'no', true ) ?>/><label for="notification-groups-group-updated-no" class="bp-screen-reader-text"><?php 
  1400. /** translators: accessibility text */ 
  1401. _e( 'No, do not send email', 'buddypress' ); 
  1402. ?></label></td> 
  1403. </tr> 
  1404. <tr id="groups-notification-settings-promoted"> 
  1405. <td></td> 
  1406. <td><?php _ex( 'You are promoted to a group administrator or moderator', 'group settings on notification settings page', 'buddypress' ) ?></td> 
  1407. <td class="yes"><input type="radio" name="notifications[notification_groups_admin_promotion]" id="notification-groups-admin-promotion-yes" value="yes" <?php checked( $group_promo, 'yes', true ) ?>/><label for="notification-groups-admin-promotion-yes" class="bp-screen-reader-text"><?php 
  1408. /** translators: accessibility text */ 
  1409. _e( 'Yes, send email', 'buddypress' ); 
  1410. ?></label></td> 
  1411. <td class="no"><input type="radio" name="notifications[notification_groups_admin_promotion]" id="notification-groups-admin-promotion-no" value="no" <?php checked( $group_promo, 'no', true ) ?>/><label for="notification-groups-admin-promotion-no" class="bp-screen-reader-text"><?php 
  1412. /** translators: accessibility text */ 
  1413. _e( 'No, do not send email', 'buddypress' ); 
  1414. ?></label></td> 
  1415. </tr> 
  1416. <tr id="groups-notification-settings-request"> 
  1417. <td></td> 
  1418. <td><?php _ex( 'A member requests to join a private group for which you are an admin', 'group settings on notification settings page', 'buddypress' ) ?></td> 
  1419. <td class="yes"><input type="radio" name="notifications[notification_groups_membership_request]" id="notification-groups-membership-request-yes" value="yes" <?php checked( $group_request, 'yes', true ) ?>/><label for="notification-groups-membership-request-yes" class="bp-screen-reader-text"><?php 
  1420. /** translators: accessibility text */ 
  1421. _e( 'Yes, send email', 'buddypress' ); 
  1422. ?></label></td> 
  1423. <td class="no"><input type="radio" name="notifications[notification_groups_membership_request]" id="notification-groups-membership-request-no" value="no" <?php checked( $group_request, 'no', true ) ?>/><label for="notification-groups-membership-request-no" class="bp-screen-reader-text"><?php 
  1424. /** translators: accessibility text */ 
  1425. _e( 'No, do not send email', 'buddypress' ); 
  1426. ?></label></td> 
  1427. </tr> 
  1428. <tr id="groups-notification-settings-request-completed"> 
  1429. <td></td> 
  1430. <td><?php _ex( 'Your request to join a group has been approved or denied', 'group settings on notification settings page', 'buddypress' ) ?></td> 
  1431. <td class="yes"><input type="radio" name="notifications[notification_membership_request_completed]" id="notification-groups-membership-request-completed-yes" value="yes" <?php checked( $group_request_completed, 'yes', true ) ?>/><label for="notification-groups-membership-request-completed-yes" class="bp-screen-reader-text"><?php 
  1432. /** translators: accessibility text */ 
  1433. _e( 'Yes, send email', 'buddypress' ); 
  1434. ?></label></td> 
  1435. <td class="no"><input type="radio" name="notifications[notification_membership_request_completed]" id="notification-groups-membership-request-completed-no" value="no" <?php checked( $group_request_completed, 'no', true ) ?>/><label for="notification-groups-membership-request-completed-no" class="bp-screen-reader-text"><?php 
  1436. /** translators: accessibility text */ 
  1437. _e( 'No, do not send email', 'buddypress' ); 
  1438. ?></label></td> 
  1439. </tr> 
  1440.  
  1441. <?php 
  1442.  
  1443. /** 
  1444. * Fires at the end of the available group settings fields on Notification Settings page. 
  1445. * 
  1446. * @since 1.0.0 
  1447. */ 
  1448. do_action( 'groups_screen_notification_settings' ); ?> 
  1449.  
  1450. </tbody> 
  1451. </table> 
  1452.  
  1453. <?php 
  1454. add_action( 'bp_notification_settings', 'groups_screen_notification_settings' ); 
  1455.  
  1456. /** Theme Compatibility *******************************************************/ 
  1457.  
  1458. new BP_Groups_Theme_Compat(); 
.