bbp_map_reply_meta_caps

Maps topic capabilities.

Description

(array) bbp_map_reply_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_reply_meta_caps' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/replies/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_reply_meta_caps($caps, $cap, $user_id, $args); 
  18.  

Defined (1)

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

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