bbp_map_forum_meta_caps

Maps forum capabilities.

Description

(array) bbp_map_forum_meta_caps( (array) $caps = array(), (string) $cap = '', (int) $user_id = 0, (array) $args = array() ); 

Returns (array)

Actual capabilities for meta capability

Parameters (4)

0. $caps — Optional. (array) => array()
Capabilities for meta capability
1. $cap — Optional. (string) => ''
Capability name
2. $user_id — Optional. (int)
The user id.
3. $args — Optional. (array) => array()
The args.

Usage

  1. if ( !function_exists( 'bbp_map_forum_meta_caps' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/forums/capabilities.php'; 
  3.  
  4. // Capabilities for meta capability 
  5. $caps = array(); 
  6.  
  7. // Capability name 
  8. $cap = ''; 
  9.  
  10. // The user id. 
  11. $user_id = -1; 
  12.  
  13. // The args. 
  14. $args = array(); 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = bbp_map_forum_meta_caps($caps, $cap, $user_id, $args); 
  18.  

Defined (1)

The function is defined in the following location(s).

/includes/forums/capabilities.php  
  1. function bbp_map_forum_meta_caps( $caps = array(), $cap = '', $user_id = 0, $args = array() ) { 
  2.  
  3. // What capability is being checked? 
  4. switch ( $cap ) { 
  5.  
  6. /** Reading ***********************************************************/ 
  7.  
  8. case 'read_private_forums' : 
  9. case 'read_hidden_forums' : 
  10.  
  11. // Moderators can always read private/hidden forums 
  12. if ( user_can( $user_id, 'moderate' ) ) { 
  13. $caps = array( 'moderate' ); 
  14.  
  15. break; 
  16.  
  17. case 'read_forum' : 
  18.  
  19. // User cannot spectate 
  20. if ( ! user_can( $user_id, 'spectate' ) ) { 
  21. $caps = array( 'do_not_allow' ); 
  22.  
  23. // Do some post ID based logic 
  24. } else { 
  25.  
  26. // Get the post 
  27. $_post = get_post( $args[0] ); 
  28. if ( !empty( $_post ) ) { 
  29.  
  30. // Get caps for post type object 
  31. $post_type = get_post_type_object( $_post->post_type ); 
  32.  
  33. // Post is public 
  34. if ( bbp_get_public_status_id() === $_post->post_status ) { 
  35. $caps = array( 'spectate' ); 
  36.  
  37. // User is author so allow read 
  38. } elseif ( (int) $user_id === (int) $_post->post_author ) { 
  39. $caps = array( 'spectate' ); 
  40.  
  41. // Unknown so map to private posts 
  42. } else { 
  43. $caps = array( $post_type->cap->read_private_posts ); 
  44.  
  45. break; 
  46.  
  47. /** Publishing ********************************************************/ 
  48.  
  49. case 'publish_forums' : 
  50.  
  51. // Moderators can always edit 
  52. if ( user_can( $user_id, 'moderate' ) ) { 
  53. $caps = array( 'moderate' ); 
  54.  
  55. break; 
  56.  
  57. /** Editing ***********************************************************/ 
  58.  
  59. // Used primarily in wp-admin 
  60. case 'edit_forums' : 
  61. case 'edit_others_forums' : 
  62.  
  63. // Moderators can always edit 
  64. if ( user_can( $user_id, 'keep_gate' ) ) { 
  65. $caps = array( 'keep_gate' ); 
  66.  
  67. // Otherwise, block 
  68. } else { 
  69. $caps = array( 'do_not_allow' ); 
  70.  
  71. break; 
  72.  
  73. // Used everywhere 
  74. case 'edit_forum' : 
  75.  
  76. // Get the post 
  77. $_post = get_post( $args[0] ); 
  78. if ( !empty( $_post ) ) { 
  79.  
  80. // Get caps for post type object 
  81. $post_type = get_post_type_object( $_post->post_type ); 
  82. $caps = array(); 
  83.  
  84. // Add 'do_not_allow' cap if user is spam or deleted 
  85. if ( bbp_is_user_inactive( $user_id ) ) { 
  86. $caps[] = 'do_not_allow'; 
  87.  
  88. // User is author so allow edit if not in admin 
  89. } elseif ( !is_admin() && ( (int) $user_id === (int) $_post->post_author ) ) { 
  90. $caps[] = $post_type->cap->edit_posts; 
  91.  
  92. // Unknown, so map to edit_others_posts 
  93. } else { 
  94. $caps[] = $post_type->cap->edit_others_posts; 
  95.  
  96. break; 
  97.  
  98. /** Deleting **********************************************************/ 
  99.  
  100. // Allow forum authors to delete forums (for BuddyPress groups, etc) 
  101. case 'delete_forum' : 
  102.  
  103. // Get the post 
  104. $_post = get_post( $args[0] ); 
  105. if ( !empty( $_post ) ) { 
  106.  
  107. // Get caps for post type object 
  108. $post_type = get_post_type_object( $_post->post_type ); 
  109. $caps = array(); 
  110.  
  111. // Add 'do_not_allow' cap if user is spam or deleted 
  112. if ( bbp_is_user_inactive( $user_id ) ) { 
  113. $caps[] = 'do_not_allow'; 
  114.  
  115. // User is author so allow to delete 
  116. } elseif ( (int) $user_id === (int) $_post->post_author ) { 
  117. $caps[] = $post_type->cap->delete_posts; 
  118.  
  119. // Unknown so map to delete_others_posts 
  120. } else { 
  121. $caps[] = $post_type->cap->delete_others_posts; 
  122.  
  123. break; 
  124.  
  125. /** Admin *************************************************************/ 
  126.  
  127. case bbp_forums_admin : 
  128. $caps = array( 'keep_gate' ); 
  129. break; 
  130.  
  131. return apply_filters( 'bbp_map_forum_meta_caps', $caps, $cap, $user_id, $args );