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