bb_map_meta_cap

Map meta capabilities to primitive capabilities.

Description

(array) bb_map_meta_cap( (array) $caps, (string) $cap, (int) $user_id, $args ); 

This does not actually compare whether the user ID has the actual capability, just what the capability or capabilities are. Meta capability list value can be delete_user,, edit_user., delete_post, delete_page, edit_post, 'edit_page', read_post, or read_page.

Returns (array)

Actual capabilities for meta capability.

Parameters (4)

0. $caps (array)
Previously existing capabilities
1. $cap (string)
Capability name.
2. $user_id (int)
The user id.
3. $args
The args.

Usage

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

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-capabilities.php  
  1. function bb_map_meta_cap( $caps, $cap, $user_id, $args ) { 
  2. // Unset the meta cap 
  3. if ( false !== $cap_pos = array_search( $cap, $caps ) ) 
  4. unset( $caps[$cap_pos] ); 
  5.  
  6. switch ( $cap ) { 
  7. case 'write_post': 
  8. $caps[] = 'write_posts'; 
  9. break; 
  10. case 'edit_post': 
  11. // edit_posts, edit_others_posts, edit_deleted, edit_closed, ignore_edit_lock 
  12. if ( !$bb_post = bb_get_post( $args[0] ) ) { 
  13. $caps[] = 'magically_provide_data_given_bad_input'; 
  14. return $caps; 
  15. if ( $user_id == $bb_post->poster_id ) 
  16. $caps[] = 'edit_posts'; 
  17. else 
  18. $caps[] = 'edit_others_posts'; 
  19. if ( $bb_post->post_status == '1' ) 
  20. $caps[] = 'edit_deleted'; 
  21. if ( !topic_is_open( $bb_post->topic_id ) ) 
  22. $caps[] = 'edit_closed'; 
  23. $post_time = bb_gmtstrtotime( $bb_post->post_time ); 
  24. $curr_time = time() + 1; 
  25. $edit_lock = bb_get_option( 'edit_lock' ); 
  26. if ( $edit_lock >= 0 && $curr_time - $post_time > $edit_lock * 60 ) 
  27. $caps[] = 'ignore_edit_lock'; 
  28. break; 
  29. case 'delete_post' : 
  30. // edit_deleted, delete_posts 
  31. if ( !$bb_post = bb_get_post( $args[0] ) ) { 
  32. $caps[] = 'magically_provide_data_given_bad_input'; 
  33. return $caps; 
  34. if ( 0 != $bb_post->post_status ) 
  35. $caps[] = 'edit_deleted'; 
  36. // NO BREAK 
  37. case 'manage_posts' : // back compat 
  38. $caps[] = 'delete_posts'; 
  39. break; 
  40. case 'write_topic': 
  41. $caps[] = 'write_topics'; 
  42. break; 
  43. case 'edit_topic': 
  44. // edit_closed, edit_deleted, edit_topics, edit_others_topics 
  45. if ( !$topic = get_topic( $args[0] ) ) { 
  46. $caps[] = 'magically_provide_data_given_bad_input'; 
  47. return $caps; 
  48. if ( !topic_is_open( $args[0]) ) 
  49. $caps[] = 'edit_closed'; 
  50. if ( '1' == $topic->topic_status ) 
  51. $caps[] = 'edit_deleted'; 
  52. if ( $user_id == $topic->topic_poster ) 
  53. $caps[] = 'edit_topics'; 
  54. else 
  55. $caps[] = 'edit_others_topics'; 
  56. break; 
  57. case 'move_topic' : 
  58. $caps[] = 'move_topics'; 
  59. break; 
  60. case 'stick_topic' : 
  61. $caps[] = 'stick_topics'; 
  62. break; 
  63. case 'close_topic' : 
  64. $caps[] = 'close_topics'; 
  65. break; 
  66. case 'delete_topic' : 
  67. $caps[] = 'delete_topics'; 
  68. if ( !$topic = get_topic( $args[0] ) ) { 
  69. $caps[] = 'magically_provide_data_given_bad_input'; 
  70. return $caps; 
  71. if ( 0 != $topic->topic_status ) 
  72. $caps[] = 'edit_deleted'; 
  73. break; 
  74. case 'manage_topics' : 
  75. // back compat 
  76. $caps[] = 'move_topics'; 
  77. $caps[] = 'stick_topics'; 
  78. $caps[] = 'close_topics'; 
  79. $caps[] = 'delete_topics'; 
  80. break; 
  81. case 'add_tag_to': 
  82. // edit_closed, edit_deleted, edit_tags; 
  83. if ( !$topic = get_topic( $args[0] ) ) { 
  84. $caps[] = 'magically_provide_data_given_bad_input'; 
  85. return $caps; 
  86. if ( !topic_is_open( $topic->topic_id ) ) 
  87. $caps[] = 'edit_closed'; 
  88. if ( '1' == $topic->topic_status ) 
  89. $caps[] = 'edit_deleted'; 
  90. $caps[] = 'edit_tags'; 
  91. break; 
  92. case 'edit_tag_by_on': 
  93. // edit_closed, edit_deleted, edit_tags, edit_others_tags 
  94. if ( !$topic = get_topic( $args[1] ) ) { 
  95. $caps[] = 'magically_provide_data_given_bad_input'; 
  96. return $caps; 
  97. if ( !topic_is_open( $topic->topic_id ) ) 
  98. $caps[] = 'edit_closed'; 
  99. if ( '1' == $topic->topic_status ) 
  100. $caps[] = 'edit_deleted'; 
  101. if ( $user_id == $args[0] ) 
  102. $caps[] = 'edit_tags'; 
  103. else 
  104. $caps[] = 'edit_others_tags'; 
  105. break; 
  106. case 'edit_user': 
  107. // edit_profile, edit_users; 
  108. if ( $user_id == $args[0] ) 
  109. $caps[] = 'edit_profile'; 
  110. else 
  111. $caps[] = 'edit_users'; 
  112. break; 
  113. case 'edit_favorites_of': 
  114. // edit_favorites, edit_others_favorites; 
  115. if ( $user_id == $args[0] ) 
  116. $caps[] = 'edit_favorites'; 
  117. else 
  118. $caps[] = 'edit_others_favorites'; 
  119. break; 
  120. case 'delete_forum': 
  121. $caps[] = 'delete_forums'; 
  122. break; 
  123. case 'change_user_password': 
  124. // change_password, edit_users 
  125. $caps[] = 'change_password'; 
  126. if ( $user_id != $args[0] ) 
  127. $caps[] = 'edit_users'; 
  128. break; 
  129. default: 
  130. // If no meta caps match, return the original cap. 
  131. $caps[] = $cap; 
  132. return $caps;