Advertisement
Guest User

Untitled

a guest
Jul 20th, 2014
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.71 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. /**
  6.  
  7. * bbPress Capabilites
  8.  
  9. *
  10.  
  11. * The functions in this file are used primarily as convenient wrappers for
  12.  
  13. * capability output in user profiles. This includes mapping capabilities and
  14.  
  15. * groups to human readable strings,
  16.  
  17. *
  18.  
  19. * @package bbPress
  20.  
  21. * @subpackage Capabilities
  22.  
  23. */
  24.  
  25.  
  26.  
  27. // Exit if accessed directly
  28.  
  29. if ( !defined( 'ABSPATH' ) ) exit;
  30.  
  31.  
  32.  
  33. /** Mapping *******************************************************************/
  34.  
  35.  
  36.  
  37. /**
  38.  
  39. * Returns an array of capabilities based on the role that is being requested.
  40.  
  41. *
  42.  
  43. * @since bbPress (r2994)
  44.  
  45. *
  46.  
  47. * @todo Map all of these and deprecate
  48.  
  49. *
  50.  
  51. * @param string $role Optional. Defaults to The role to load caps for
  52.  
  53. * @uses apply_filters() Allow return value to be filtered
  54.  
  55. *
  56.  
  57. * @return array Capabilities for $role
  58.  
  59. */
  60.  
  61. function bbp_get_caps_for_role( $role = '' ) {
  62.  
  63.  
  64.  
  65. // Which role are we looking for?
  66.  
  67. switch ( $role ) {
  68.  
  69.  
  70.  
  71. // Keymaster
  72.  
  73. case bbp_get_keymaster_role() :
  74.  
  75. $caps = array(
  76.  
  77.  
  78.  
  79. // Keymasters only
  80.  
  81. 'keep_gate' => true,
  82.  
  83.  
  84.  
  85. // Primary caps
  86.  
  87. 'spectate' => true,
  88.  
  89. 'participate' => true,
  90.  
  91. 'moderate' => true,
  92.  
  93. 'throttle' => true,
  94.  
  95. 'view_trash' => true,
  96.  
  97.  
  98.  
  99. // Forum caps
  100.  
  101. 'publish_forums' => true,
  102.  
  103. 'edit_forums' => true,
  104.  
  105. 'edit_others_forums' => true,
  106.  
  107. 'delete_forums' => true,
  108.  
  109. 'delete_others_forums' => true,
  110.  
  111. 'read_private_forums' => true,
  112.  
  113. 'read_hidden_forums' => true,
  114.  
  115.  
  116.  
  117. // Topic caps
  118.  
  119. 'publish_topics' => true,
  120.  
  121. 'edit_topics' => true,
  122.  
  123. 'edit_others_topics' => true,
  124.  
  125. 'delete_topics' => true,
  126.  
  127. 'delete_others_topics' => true,
  128.  
  129. 'read_private_topics' => true,
  130.  
  131.  
  132.  
  133. // Reply caps
  134.  
  135. 'publish_replies' => true,
  136.  
  137. 'edit_replies' => true,
  138.  
  139. 'edit_others_replies' => true,
  140.  
  141. 'delete_replies' => true,
  142.  
  143. 'delete_others_replies' => true,
  144.  
  145. 'read_private_replies' => true,
  146.  
  147.  
  148.  
  149. // Topic tag caps
  150.  
  151. 'manage_topic_tags' => true,
  152.  
  153. 'edit_topic_tags' => true,
  154.  
  155. 'delete_topic_tags' => true,
  156.  
  157. 'assign_topic_tags' => true
  158.  
  159. );
  160.  
  161.  
  162.  
  163. break;
  164.  
  165.  
  166.  
  167. // Moderator
  168.  
  169. case bbp_get_moderator_role() :
  170.  
  171. $caps = array(
  172.  
  173.  
  174.  
  175. // Primary caps
  176.  
  177. 'spectate' => true,
  178.  
  179. 'participate' => true,
  180.  
  181. 'moderate' => true,
  182.  
  183. 'throttle' => true,
  184.  
  185. 'view_trash' => true,
  186.  
  187.  
  188.  
  189. // Forum caps
  190.  
  191. 'publish_forums' => true,
  192.  
  193. 'edit_forums' => true,
  194.  
  195. 'read_private_forums' => true,
  196.  
  197. 'read_hidden_forums' => true,
  198.  
  199.  
  200.  
  201. // Topic caps
  202.  
  203. 'publish_topics' => true,
  204.  
  205. 'edit_topics' => true,
  206.  
  207. 'edit_others_topics' => true,
  208.  
  209. 'delete_topics' => true,
  210.  
  211. 'delete_others_topics' => true,
  212.  
  213. 'read_private_topics' => true,
  214.  
  215.  
  216.  
  217. // Reply caps
  218.  
  219. 'publish_replies' => true,
  220.  
  221. 'edit_replies' => true,
  222.  
  223. 'edit_others_replies' => true,
  224.  
  225. 'delete_replies' => true,
  226.  
  227. 'delete_others_replies' => true,
  228.  
  229. 'read_private_replies' => true,
  230.  
  231.  
  232.  
  233. // Topic tag caps
  234.  
  235. 'manage_topic_tags' => true,
  236.  
  237. 'edit_topic_tags' => true,
  238.  
  239. 'delete_topic_tags' => true,
  240.  
  241. 'assign_topic_tags' => true,
  242.  
  243. );
  244.  
  245.  
  246.  
  247. break;
  248.  
  249.  
  250.  
  251. // Spectators can only read
  252.  
  253. case bbp_get_spectator_role() :
  254.  
  255. $caps = array(
  256.  
  257.  
  258.  
  259. // Primary caps
  260.  
  261. 'spectate' => true,
  262.  
  263. );
  264.  
  265.  
  266.  
  267. break;
  268.  
  269.  
  270.  
  271. // Explicitly blocked
  272.  
  273. case bbp_get_blocked_role() :
  274.  
  275. $caps = array(
  276.  
  277.  
  278.  
  279. // Primary caps
  280.  
  281. 'spectate' => false,
  282.  
  283. 'participate' => false,
  284.  
  285. 'moderate' => false,
  286.  
  287. 'throttle' => false,
  288.  
  289. 'view_trash' => false,
  290.  
  291.  
  292.  
  293. // Forum caps
  294.  
  295. 'publish_forums' => false,
  296.  
  297. 'edit_forums' => false,
  298.  
  299. 'edit_others_forums' => false,
  300.  
  301. 'delete_forums' => false,
  302.  
  303. 'delete_others_forums' => false,
  304.  
  305. 'read_private_forums' => false,
  306.  
  307. 'read_hidden_forums' => false,
  308.  
  309.  
  310.  
  311. // Topic caps
  312.  
  313. 'publish_topics' => false,
  314.  
  315. 'edit_topics' => false,
  316.  
  317. 'edit_others_topics' => false,
  318.  
  319. 'delete_topics' => false,
  320.  
  321. 'delete_others_topics' => false,
  322.  
  323. 'read_private_topics' => false,
  324.  
  325.  
  326.  
  327. // Reply caps
  328.  
  329. 'publish_replies' => false,
  330.  
  331. 'edit_replies' => false,
  332.  
  333. 'edit_others_replies' => false,
  334.  
  335. 'delete_replies' => false,
  336.  
  337. 'delete_others_replies' => false,
  338.  
  339. 'read_private_replies' => false,
  340.  
  341.  
  342.  
  343. // Topic tag caps
  344.  
  345. 'manage_topic_tags' => false,
  346.  
  347. 'edit_topic_tags' => false,
  348.  
  349. 'delete_topic_tags' => false,
  350.  
  351. 'assign_topic_tags' => false,
  352.  
  353. );
  354.  
  355.  
  356.  
  357. break;
  358.  
  359.  
  360.  
  361. // Participant/Default
  362.  
  363. case bbp_get_participant_role() :
  364.  
  365. default :
  366.  
  367. $caps = array(
  368.  
  369.  
  370.  
  371. // Primary caps
  372.  
  373. 'spectate' => true,
  374.  
  375. 'participate' => true,
  376.  
  377.  
  378.  
  379. // Forum caps
  380.  
  381. 'read_private_forums' => true,
  382.  
  383.  
  384.  
  385. // Topic caps
  386.  
  387. 'publish_topics' => true,
  388.  
  389. 'edit_topics' => true,
  390.  
  391. 'delete_topics' => true,
  392.  
  393.  
  394.  
  395. // Reply caps
  396.  
  397. 'publish_replies' => true,
  398.  
  399. 'edit_replies' => true,
  400.  
  401. 'delete_replies' => true,
  402.  
  403.  
  404.  
  405. // Topic tag caps
  406.  
  407. 'assign_topic_tags' => true,
  408.  
  409. );
  410.  
  411.  
  412.  
  413. break;
  414.  
  415. }
  416.  
  417.  
  418.  
  419. return apply_filters( 'bbp_get_caps_for_role', $caps, $role );
  420.  
  421. }
  422.  
  423.  
  424. //code to add tutor role
  425.  
  426. function add_new roles( $bbp_roles )
  427. {
  428. /* Add a role called tutor */
  429. $bbp_roles['bbp_tutor'] = array(
  430. 'name' => 'Tutor',
  431. 'capabilities' => custom_capabilities( 'bbp_tutor' )
  432. );
  433.  
  434. return $bbp_roles;
  435. }
  436.  
  437. add_filter( 'bbp_get_dynamic_roles', 'add_new roles', 1 );
  438.  
  439. function add_role_caps_filter( $caps, $role )
  440. {
  441. /* Only filter for roles we are interested in! */
  442. if( $role == 'bbp_tutor' )
  443. $caps = custom_capabilities( $role );
  444.  
  445. return $caps;
  446. }
  447.  
  448. add_filter( 'bbp_get_caps_for_role', 'add_role_caps_filter', 10, 2 );
  449.  
  450. function custom_capabilities( $role )
  451. {
  452. switch ( $role )
  453. {
  454.  
  455. /* Capabilities for 'tutor' role */
  456. case 'bbp_tutor':
  457. return array(
  458. // Primary caps
  459. 'spectate' => true,
  460. 'participate' => true,
  461. 'moderate' => false,
  462. 'throttle' => false,
  463. 'view_trash' => false,
  464.  
  465. // Forum caps
  466. 'publish_forums' => false,
  467. 'edit_forums' => false,
  468. 'edit_others_forums' => false,
  469. 'delete_forums' => false,
  470. 'delete_others_forums' => false,
  471. 'read_private_forums' => true,
  472. 'read_hidden_forums' => false,
  473.  
  474. // Topic caps
  475. 'publish_topics' => true,
  476. 'edit_topics' => true,
  477. 'edit_others_topics' => false,
  478. 'delete_topics' => false,
  479. 'delete_others_topics' => false,
  480. 'read_private_topics' => true,
  481.  
  482. // Reply caps
  483. 'publish_replies' => true,
  484. 'edit_replies' => true,
  485. 'edit_others_replies' => false,
  486. 'delete_replies' => false,
  487. 'delete_others_replies' => false,
  488. 'read_private_replies' => true,
  489.  
  490. // Topic tag caps
  491. 'manage_topic_tags' => false,
  492. 'edit_topic_tags' => false,
  493. 'delete_topic_tags' => false,
  494. 'assign_topic_tags' => true,
  495. );
  496.  
  497.  
  498. break;
  499.  
  500. default :
  501. return $role;
  502. }
  503. }
  504.  
  505.  
  506.  
  507.  
  508. /**
  509.  
  510. * Adds capabilities to WordPress user roles.
  511.  
  512. *
  513.  
  514. * @since bbPress (r2608)
  515.  
  516. */
  517.  
  518. function bbp_add_caps() {
  519.  
  520.  
  521.  
  522. // Loop through available roles and add caps
  523.  
  524. foreach ( bbp_get_wp_roles()->role_objects as $role ) {
  525.  
  526. foreach ( bbp_get_caps_for_role( $role->name ) as $cap => $value ) {
  527.  
  528. $role->add_cap( $cap, $value );
  529.  
  530. }
  531.  
  532. }
  533.  
  534.  
  535.  
  536. do_action( 'bbp_add_caps' );
  537.  
  538. }
  539.  
  540.  
  541.  
  542. /**
  543.  
  544. * Removes capabilities from WordPress user roles.
  545.  
  546. *
  547.  
  548. * @since bbPress (r2608)
  549.  
  550. */
  551.  
  552. function bbp_remove_caps() {
  553.  
  554.  
  555.  
  556. // Loop through available roles and remove caps
  557.  
  558. foreach ( bbp_get_wp_roles()->role_objects as $role ) {
  559.  
  560. foreach ( array_keys( bbp_get_caps_for_role( $role->name ) ) as $cap ) {
  561.  
  562. $role->remove_cap( $cap );
  563.  
  564. }
  565.  
  566. }
  567.  
  568.  
  569.  
  570. do_action( 'bbp_remove_caps' );
  571.  
  572. }
  573.  
  574.  
  575.  
  576. /**
  577.  
  578. * Get the $wp_roles global without needing to declare it everywhere
  579.  
  580. *
  581.  
  582. * @since bbPress (r4293)
  583.  
  584. *
  585.  
  586. * @global WP_Roles $wp_roles
  587.  
  588. * @return WP_Roles
  589.  
  590. */
  591.  
  592. function bbp_get_wp_roles() {
  593.  
  594. global $wp_roles;
  595.  
  596.  
  597.  
  598. // Load roles if not set
  599.  
  600. if ( ! isset( $wp_roles ) )
  601.  
  602. $wp_roles = new WP_Roles();
  603.  
  604.  
  605.  
  606. return $wp_roles;
  607.  
  608. }
  609.  
  610.  
  611.  
  612. /**
  613.  
  614. * Get the available roles minus bbPress's dynamic roles
  615.  
  616. *
  617.  
  618. * @since bbPress (r5064)
  619.  
  620. *
  621.  
  622. * @uses bbp_get_wp_roles() To load and get the $wp_roles global
  623.  
  624. * @return array
  625.  
  626. */
  627.  
  628. function bbp_get_blog_roles() {
  629.  
  630.  
  631.  
  632. // Get WordPress's roles (returns $wp_roles global)
  633.  
  634. $wp_roles = bbp_get_wp_roles();
  635.  
  636.  
  637.  
  638. // Apply the WordPress 'editable_roles' filter to let plugins ride along.
  639.  
  640. //
  641.  
  642. // We use this internally via bbp_filter_blog_editable_roles() to remove
  643.  
  644. // any custom bbPress roles that are added to the global.
  645.  
  646. $the_roles = isset( $wp_roles->roles ) ? $wp_roles->roles : false;
  647.  
  648. $all_roles = apply_filters( 'editable_roles', $the_roles );
  649.  
  650.  
  651.  
  652. return apply_filters( 'bbp_get_blog_roles', $all_roles, $wp_roles );
  653.  
  654. }
  655.  
  656.  
  657.  
  658. /** Forum Roles ***************************************************************/
  659.  
  660.  
  661.  
  662. /**
  663.  
  664. * Add the bbPress roles to the $wp_roles global.
  665.  
  666. *
  667.  
  668. * We do this to avoid adding these values to the database.
  669.  
  670. *
  671.  
  672. * @since bbPress (r4290)
  673.  
  674. *
  675.  
  676. * @uses bbp_get_wp_roles() To load and get the $wp_roles global
  677.  
  678. * @uses bbp_get_dynamic_roles() To get and add bbPress's roles to $wp_roles
  679.  
  680. * @return WP_Roles The main $wp_roles global
  681.  
  682. */
  683.  
  684. function bbp_add_forums_roles() {
  685.  
  686. $wp_roles = bbp_get_wp_roles();
  687.  
  688.  
  689.  
  690. foreach ( bbp_get_dynamic_roles() as $role_id => $details ) {
  691.  
  692. $wp_roles->roles[$role_id] = $details;
  693.  
  694. $wp_roles->role_objects[$role_id] = new WP_Role( $role_id, $details['capabilities'] );
  695.  
  696. $wp_roles->role_names[$role_id] = $details['name'];
  697.  
  698. }
  699.  
  700.  
  701.  
  702. return $wp_roles;
  703.  
  704. }
  705.  
  706.  
  707.  
  708. /**
  709.  
  710. * Helper function to add filter to option_wp_user_roles
  711.  
  712. *
  713.  
  714. * @since bbPress (r4363)
  715.  
  716. *
  717.  
  718. * @see _bbp_reinit_dynamic_roles()
  719.  
  720. *
  721.  
  722. * @global WPDB $wpdb Used to get the database prefix
  723.  
  724. */
  725.  
  726. function bbp_filter_user_roles_option() {
  727.  
  728. global $wpdb;
  729.  
  730.  
  731.  
  732. $role_key = $wpdb->prefix . 'user_roles';
  733.  
  734.  
  735.  
  736. add_filter( 'option_' . $role_key, '_bbp_reinit_dynamic_roles' );
  737.  
  738. }
  739.  
  740.  
  741.  
  742. /**
  743.  
  744. * This is necessary because in a few places (noted below) WordPress initializes
  745.  
  746. * a blog's roles directly from the database option. When this happens, the
  747.  
  748. * $wp_roles global gets flushed, causing a user to magically lose any
  749.  
  750. * dynamically assigned roles or capabilities when $current_user in refreshed.
  751.  
  752. *
  753.  
  754. * Because dynamic multiple roles is a new concept in WordPress, we work around
  755.  
  756. * it here for now, knowing that improvements will come to WordPress core later.
  757.  
  758. *
  759.  
  760. * Also note that if using the $wp_user_roles global non-database approach,
  761.  
  762. * bbPress does not have an intercept point to add its dynamic roles.
  763.  
  764. *
  765.  
  766. * @see switch_to_blog()
  767.  
  768. * @see restore_current_blog()
  769.  
  770. * @see WP_Roles::_init()
  771.  
  772. *
  773.  
  774. * @since bbPress (r4363)
  775.  
  776. *
  777.  
  778. * @internal Used by bbPress to reinitialize dynamic roles on blog switch
  779.  
  780. *
  781.  
  782. * @param array $roles
  783.  
  784. * @return array Combined array of database roles and dynamic bbPress roles
  785.  
  786. */
  787.  
  788. function _bbp_reinit_dynamic_roles( $roles = array() ) {
  789.  
  790. foreach ( bbp_get_dynamic_roles() as $role_id => $details ) {
  791.  
  792. $roles[$role_id] = $details;
  793.  
  794. }
  795.  
  796. return $roles;
  797.  
  798. }
  799.  
  800.  
  801.  
  802. /**
  803.  
  804. * Fetch a filtered list of forum roles that the current user is
  805.  
  806. * allowed to have.
  807.  
  808. *
  809.  
  810. * Simple function who's main purpose is to allow filtering of the
  811.  
  812. * list of forum roles so that plugins can remove inappropriate ones depending
  813.  
  814. * on the situation or user making edits.
  815.  
  816. *
  817.  
  818. * Specifically because without filtering, anyone with the edit_users
  819.  
  820. * capability can edit others to be administrators, even if they are
  821.  
  822. * only editors or authors. This filter allows admins to delegate
  823.  
  824. * user management.
  825.  
  826. *
  827.  
  828. * @since bbPress (r4284)
  829.  
  830. *
  831.  
  832. * @return array
  833.  
  834. */
  835.  
  836. function bbp_get_dynamic_roles() {
  837.  
  838. return (array) apply_filters( 'bbp_get_dynamic_roles', array(
  839.  
  840.  
  841.  
  842. // Keymaster
  843.  
  844. bbp_get_keymaster_role() => array(
  845.  
  846. 'name' => __( 'Administrator', 'bbpress' ),
  847.  
  848. 'capabilities' => bbp_get_caps_for_role( bbp_get_keymaster_role() )
  849.  
  850. ),
  851.  
  852.  
  853.  
  854. // Moderator
  855.  
  856. bbp_get_moderator_role() => array(
  857.  
  858. 'name' => __( 'Global Moderator', 'bbpress' ),
  859.  
  860. 'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() )
  861.  
  862. ),
  863.  
  864. // Start of Ranks----------------------------------------------------------------------------------------------------------------
  865.  
  866. // Diamond
  867.  
  868. bbp_get_diamondmember_role() => array(
  869.  
  870. 'name' => __( 'Diamond', 'bbpress' ),
  871.  
  872. 'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() )
  873.  
  874. ),
  875.  
  876.  
  877.  
  878. // Gold
  879.  
  880. bbp_get_goldmember_role() => array(
  881.  
  882. 'name' => __( 'Gold', 'bbpress' ),
  883.  
  884. 'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() )
  885.  
  886. ),
  887.  
  888.  
  889.  
  890. // Silver
  891.  
  892. bbp_get_silvermember_role() => array(
  893.  
  894. 'name' => __( 'Silver', 'bbpress' ),
  895.  
  896. 'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() )
  897.  
  898. ),
  899.  
  900.  
  901.  
  902. // Bronze
  903.  
  904. bbp_get_bronzemember_role() => array(
  905.  
  906. 'name' => __( 'Bronze', 'bbpress' ),
  907.  
  908. 'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() )
  909.  
  910. ),
  911.  
  912.  
  913.  
  914. // Newbie
  915.  
  916. bbp_get_participant_role() => array(
  917.  
  918. 'name' => __( 'Newbie', 'bbpress' ),
  919.  
  920. 'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() )
  921.  
  922. ),
  923.  
  924. // End of Ranks-----------------------------------------------------------------------------------------------------------------
  925.  
  926.  
  927.  
  928. // Spectator
  929.  
  930. bbp_get_spectator_role() => array(
  931.  
  932. 'name' => __( 'Guest', 'bbpress' ),
  933.  
  934. 'capabilities' => bbp_get_caps_for_role( bbp_get_spectator_role() )
  935.  
  936. ),
  937.  
  938.  
  939.  
  940. // Blocked
  941.  
  942. bbp_get_blocked_role() => array(
  943.  
  944. 'name' => __( 'Banned', 'bbpress' ),
  945.  
  946. 'capabilities' => bbp_get_caps_for_role( bbp_get_blocked_role() )
  947.  
  948. )
  949.  
  950. ) );
  951.  
  952. }
  953.  
  954.  
  955.  
  956. /**
  957.  
  958. * Gets a translated role name from a role ID
  959.  
  960. *
  961.  
  962. * @since bbPress (r4792)
  963.  
  964. *
  965.  
  966. * @param string $role_id
  967.  
  968. * @return string Translated role name
  969.  
  970. */
  971.  
  972. function bbp_get_dynamic_role_name( $role_id = '' ) {
  973.  
  974. $roles = bbp_get_dynamic_roles();
  975.  
  976. $role = isset( $roles[$role_id] ) ? $roles[$role_id]['name'] : '';
  977.  
  978.  
  979.  
  980. return apply_filters( 'bbp_get_dynamic_role_name', $role, $role_id, $roles );
  981.  
  982. }
  983.  
  984.  
  985.  
  986. /**
  987.  
  988. * Removes the bbPress roles from the editable roles array
  989.  
  990. *
  991.  
  992. * This used to use array_diff_assoc() but it randomly broke before 2.2 release.
  993.  
  994. * Need to research what happened, and if there's a way to speed this up.
  995.  
  996. *
  997.  
  998. * @since bbPress (r4303)
  999.  
  1000. *
  1001.  
  1002. * @param array $all_roles All registered roles
  1003.  
  1004. * @return array
  1005.  
  1006. */
  1007.  
  1008. function bbp_filter_blog_editable_roles( $all_roles = array() ) {
  1009.  
  1010.  
  1011.  
  1012. // Loop through bbPress roles
  1013.  
  1014. foreach ( array_keys( bbp_get_dynamic_roles() ) as $bbp_role ) {
  1015.  
  1016.  
  1017.  
  1018. // Loop through WordPress roles
  1019.  
  1020. foreach ( array_keys( $all_roles ) as $wp_role ) {
  1021.  
  1022.  
  1023.  
  1024. // If keys match, unset
  1025.  
  1026. if ( $wp_role === $bbp_role ) {
  1027.  
  1028. unset( $all_roles[$wp_role] );
  1029.  
  1030. }
  1031.  
  1032. }
  1033.  
  1034. }
  1035.  
  1036.  
  1037.  
  1038. return $all_roles;
  1039.  
  1040. }
  1041.  
  1042.  
  1043.  
  1044. /**
  1045.  
  1046. * The keymaster role for bbPress users
  1047.  
  1048. *
  1049.  
  1050. * @since bbPress (r4284)
  1051.  
  1052. *
  1053.  
  1054. * @uses apply_filters() Allow override of hardcoded keymaster role
  1055.  
  1056. * @return string
  1057.  
  1058. */
  1059.  
  1060. function bbp_get_keymaster_role() {
  1061.  
  1062. return apply_filters( 'bbp_get_keymaster_role', 'bbp_keymaster' );
  1063.  
  1064. }
  1065.  
  1066.  
  1067.  
  1068. /**
  1069.  
  1070. * The moderator role for bbPress users
  1071.  
  1072. *
  1073.  
  1074. * @since bbPress (r3410)
  1075.  
  1076. *
  1077.  
  1078. * @uses apply_filters() Allow override of hardcoded moderator role
  1079.  
  1080. * @return string
  1081.  
  1082. */
  1083.  
  1084. function bbp_get_moderator_role() {
  1085.  
  1086. return apply_filters( 'bbp_get_moderator_role', 'bbp_moderator' );
  1087.  
  1088. }
  1089.  
  1090.  
  1091.  
  1092. /**
  1093.  
  1094. * The participant role for registered user that can participate in forums
  1095.  
  1096. *
  1097.  
  1098. * @since bbPress (r3410)
  1099.  
  1100. *
  1101.  
  1102. * @uses apply_filters() Allow override of hardcoded participant role
  1103.  
  1104. * @return string
  1105.  
  1106. */
  1107.  
  1108.  
  1109.  
  1110. // Start of Ranks--------------------------------------------------------------------------------------------------
  1111.  
  1112. function bbp_get_diamondmember_role() {
  1113.  
  1114. return apply_filters( 'bbp_get_participant_role', 'bbp_diamondmember' );
  1115.  
  1116. }
  1117.  
  1118. function bbp_get_goldmember_role() {
  1119.  
  1120. return apply_filters( 'bbp_get_participant_role', 'bbp_goldmember' );
  1121.  
  1122. }
  1123.  
  1124. function bbp_get_silvermember_role() {
  1125.  
  1126. return apply_filters( 'bbp_get_participant_role', 'bbp_silvermember' );
  1127.  
  1128. }
  1129.  
  1130. function bbp_get_bronzemember_role() {
  1131.  
  1132. return apply_filters( 'bbp_get_participant_role', 'bbp_bronzemember' );
  1133.  
  1134. }
  1135.  
  1136. function bbp_get_participant_role() {
  1137.  
  1138. return apply_filters( 'bbp_get_participant_role', 'bbp_participant' );
  1139.  
  1140. }
  1141.  
  1142. // End of Ranks-----------------------------------------------------------------------------------------------------
  1143.  
  1144.  
  1145.  
  1146. /**
  1147.  
  1148. * The spectator role is for registered users without any capabilities
  1149.  
  1150. *
  1151.  
  1152. * @since bbPress (r3860)
  1153.  
  1154. *
  1155.  
  1156. * @uses apply_filters() Allow override of hardcoded spectator role
  1157.  
  1158. * @return string
  1159.  
  1160. */
  1161.  
  1162. function bbp_get_spectator_role() {
  1163.  
  1164. return apply_filters( 'bbp_get_spectator_role', 'bbp_spectator' );
  1165.  
  1166. }
  1167.  
  1168.  
  1169.  
  1170. /**
  1171.  
  1172. * The blocked role is for registered users that cannot spectate or participate
  1173.  
  1174. *
  1175.  
  1176. * @since bbPress (r4284)
  1177.  
  1178. *
  1179.  
  1180. * @uses apply_filters() Allow override of hardcoded blocked role
  1181.  
  1182. * @return string
  1183.  
  1184. */
  1185.  
  1186. function bbp_get_blocked_role() {
  1187.  
  1188. return apply_filters( 'bbp_get_blocked_role', 'bbp_blocked' );
  1189.  
  1190. }
  1191.  
  1192.  
  1193.  
  1194. /** Deprecated ****************************************************************/
  1195.  
  1196.  
  1197.  
  1198. /**
  1199.  
  1200. * Adds bbPress-specific user roles.
  1201.  
  1202. *
  1203.  
  1204. * @since bbPress (r2741)
  1205.  
  1206. * @deprecated since version 2.2
  1207.  
  1208. */
  1209.  
  1210. function bbp_add_roles() {
  1211.  
  1212. _doing_it_wrong( 'bbp_add_roles', __( 'Editable forum roles no longer exist.', 'bbpress' ), '2.2' );
  1213.  
  1214. }
  1215.  
  1216.  
  1217.  
  1218. /**
  1219.  
  1220. * Removes bbPress-specific user roles.
  1221.  
  1222. *
  1223.  
  1224. * @since bbPress (r2741)
  1225.  
  1226. * @deprecated since version 2.2
  1227.  
  1228. */
  1229.  
  1230. function bbp_remove_roles() {
  1231.  
  1232.  
  1233.  
  1234. // Remove the bbPress roles
  1235.  
  1236. foreach ( array_keys( bbp_get_dynamic_roles() ) as $bbp_role ) {
  1237.  
  1238. remove_role( $bbp_role );
  1239.  
  1240. }
  1241.  
  1242.  
  1243.  
  1244. // Some early adopters may have a deprecated visitor role. It was later
  1245.  
  1246. // replaced by the Spectator role.
  1247.  
  1248. remove_role( 'bbp_visitor' );
  1249.  
  1250. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement