Advertisement
Guest User

paste

a guest
Jul 22nd, 2014
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.94 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. /**
  6.  
  7. * bbPress Core Functions
  8.  
  9. *
  10.  
  11. * @package bbPress
  12.  
  13. * @subpackage Functions
  14.  
  15. */
  16.  
  17.  
  18.  
  19. // Exit if accessed directly
  20.  
  21. if ( !defined( 'ABSPATH' ) ) exit;
  22.  
  23.  
  24.  
  25. /** Versions ******************************************************************/
  26.  
  27.  
  28.  
  29. /**
  30.  
  31. * Output the bbPress version
  32.  
  33. *
  34.  
  35. * @since bbPress (r3468)
  36.  
  37. * @uses bbp_get_version() To get the bbPress version
  38.  
  39. */
  40.  
  41. function bbp_version() {
  42.  
  43. echo bbp_get_version();
  44.  
  45. }
  46.  
  47. /**
  48.  
  49. * Return the bbPress version
  50.  
  51. *
  52.  
  53. * @since bbPress (r3468)
  54.  
  55. * @retrun string The bbPress version
  56.  
  57. */
  58.  
  59. function bbp_get_version() {
  60.  
  61. return bbpress()->version;
  62.  
  63. }
  64.  
  65.  
  66.  
  67. /**
  68.  
  69. * Output the bbPress database version
  70.  
  71. *
  72.  
  73. * @since bbPress (r3468)
  74.  
  75. * @uses bbp_get_version() To get the bbPress version
  76.  
  77. */
  78.  
  79. function bbp_db_version() {
  80.  
  81. echo bbp_get_db_version();
  82.  
  83. }
  84.  
  85. /**
  86.  
  87. * Return the bbPress database version
  88.  
  89. *
  90.  
  91. * @since bbPress (r3468)
  92.  
  93. * @retrun string The bbPress version
  94.  
  95. */
  96.  
  97. function bbp_get_db_version() {
  98.  
  99. return bbpress()->db_version;
  100.  
  101. }
  102.  
  103.  
  104.  
  105. /**
  106.  
  107. * Output the bbPress database version directly from the database
  108.  
  109. *
  110.  
  111. * @since bbPress (r3468)
  112.  
  113. * @uses bbp_get_version() To get the current bbPress version
  114.  
  115. */
  116.  
  117. function bbp_db_version_raw() {
  118.  
  119. echo bbp_get_db_version_raw();
  120.  
  121. }
  122.  
  123. /**
  124.  
  125. * Return the bbPress database version directly from the database
  126.  
  127. *
  128.  
  129. * @since bbPress (r3468)
  130.  
  131. * @retrun string The current bbPress version
  132.  
  133. */
  134.  
  135. function bbp_get_db_version_raw() {
  136.  
  137. return get_option( '_bbp_db_version', '' );
  138.  
  139. }
  140.  
  141.  
  142.  
  143. /** Post Meta *****************************************************************/
  144.  
  145.  
  146.  
  147. /**
  148.  
  149. * Update a posts forum meta ID
  150.  
  151. *
  152.  
  153. * @since bbPress (r3181)
  154.  
  155. *
  156.  
  157. * @param int $post_id The post to update
  158.  
  159. * @param int $forum_id The forum
  160.  
  161. */
  162.  
  163.  
  164.  
  165.  
  166. //code to add tutor role
  167.  
  168. function add_new roles( $bbp_roles )
  169. {
  170. /* Add a role called tutor */
  171. $bbp_roles['bbp_tutor'] = array(
  172. 'name' => 'Tutor',
  173. 'capabilities' => custom_capabilities( 'bbp_tutor' )
  174. );
  175.  
  176. return $bbp_roles;
  177. }
  178.  
  179. add_filter( 'bbp_get_dynamic_roles', 'add_new roles', 1 );
  180.  
  181. function add_role_caps_filter( $caps, $role )
  182. {
  183. /* Only filter for roles we are interested in! */
  184. if( $role == 'bbp_tutor' )
  185. $caps = custom_capabilities( $role );
  186.  
  187. return $caps;
  188. }
  189.  
  190. add_filter( 'bbp_get_caps_for_role', 'add_role_caps_filter', 10, 2 );
  191.  
  192. function custom_capabilities( $role )
  193. {
  194. switch ( $role )
  195. {
  196.  
  197. /* Capabilities for 'tutor' role */
  198. case 'bbp_tutor':
  199. return array(
  200. // Primary caps
  201. 'spectate' => true,
  202. 'participate' => true,
  203. 'moderate' => false,
  204. 'throttle' => false,
  205. 'view_trash' => false,
  206.  
  207. // Forum caps
  208. 'publish_forums' => false,
  209. 'edit_forums' => false,
  210. 'edit_others_forums' => false,
  211. 'delete_forums' => false,
  212. 'delete_others_forums' => false,
  213. 'read_private_forums' => true,
  214. 'read_hidden_forums' => false,
  215.  
  216. // Topic caps
  217. 'publish_topics' => true,
  218. 'edit_topics' => true,
  219. 'edit_others_topics' => false,
  220. 'delete_topics' => false,
  221. 'delete_others_topics' => false,
  222. 'read_private_topics' => true,
  223.  
  224. // Reply caps
  225. 'publish_replies' => true,
  226. 'edit_replies' => true,
  227. 'edit_others_replies' => false,
  228. 'delete_replies' => false,
  229. 'delete_others_replies' => false,
  230. 'read_private_replies' => true,
  231.  
  232. // Topic tag caps
  233. 'manage_topic_tags' => false,
  234. 'edit_topic_tags' => false,
  235. 'delete_topic_tags' => false,
  236. 'assign_topic_tags' => true,
  237. );
  238.  
  239.  
  240. break;
  241.  
  242. default :
  243. return $role;
  244. }
  245. }
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253. function bbp_update_forum_id( $post_id, $forum_id ) {
  254.  
  255.  
  256.  
  257. // Allow the forum ID to be updated 'just in time' before save
  258.  
  259. $forum_id = apply_filters( 'bbp_update_forum_id', $forum_id, $post_id );
  260.  
  261.  
  262.  
  263. // Update the post meta forum ID
  264.  
  265. update_post_meta( $post_id, '_bbp_forum_id', (int) $forum_id );
  266.  
  267. }
  268.  
  269.  
  270.  
  271. /**
  272.  
  273. * Update a posts topic meta ID
  274.  
  275. *
  276.  
  277. * @since bbPress (r3181)
  278.  
  279. *
  280.  
  281. * @param int $post_id The post to update
  282.  
  283. * @param int $forum_id The forum
  284.  
  285. */
  286.  
  287. function bbp_update_topic_id( $post_id, $topic_id ) {
  288.  
  289.  
  290.  
  291. // Allow the topic ID to be updated 'just in time' before save
  292.  
  293. $topic_id = apply_filters( 'bbp_update_topic_id', $topic_id, $post_id );
  294.  
  295.  
  296.  
  297. // Update the post meta topic ID
  298.  
  299. update_post_meta( $post_id, '_bbp_topic_id', (int) $topic_id );
  300.  
  301. }
  302.  
  303.  
  304.  
  305. /**
  306.  
  307. * Update a posts reply meta ID
  308.  
  309. *
  310.  
  311. * @since bbPress (r3181)
  312.  
  313. *
  314.  
  315. * @param int $post_id The post to update
  316.  
  317. * @param int $forum_id The forum
  318.  
  319. */
  320.  
  321. function bbp_update_reply_id( $post_id, $reply_id ) {
  322.  
  323.  
  324.  
  325. // Allow the reply ID to be updated 'just in time' before save
  326.  
  327. $reply_id = apply_filters( 'bbp_update_reply_id', $reply_id, $post_id );
  328.  
  329.  
  330.  
  331. // Update the post meta reply ID
  332.  
  333. update_post_meta( $post_id, '_bbp_reply_id',(int) $reply_id );
  334.  
  335. }
  336.  
  337.  
  338.  
  339. /** Views *********************************************************************/
  340.  
  341.  
  342.  
  343. /**
  344.  
  345. * Get the registered views
  346.  
  347. *
  348.  
  349. * Does nothing much other than return the {@link $bbp->views} variable
  350.  
  351. *
  352.  
  353. * @since bbPress (r2789)
  354.  
  355. *
  356.  
  357. * @return array Views
  358.  
  359. */
  360.  
  361. function bbp_get_views() {
  362.  
  363. return bbpress()->views;
  364.  
  365. }
  366.  
  367.  
  368.  
  369. /**
  370.  
  371. * Register a bbPress view
  372.  
  373. *
  374.  
  375. * @todo Implement feeds - See {@link http://trac.bbpress.org/ticket/1422}
  376.  
  377. *
  378.  
  379. * @since bbPress (r2789)
  380.  
  381. *
  382.  
  383. * @param string $view View name
  384.  
  385. * @param string $title View title
  386.  
  387. * @param mixed $query_args {@link bbp_has_topics()} arguments.
  388.  
  389. * @param bool $feed Have a feed for the view? Defaults to true. NOT IMPLEMENTED
  390.  
  391. * @param string $capability Capability that the current user must have
  392.  
  393. * @uses sanitize_title() To sanitize the view name
  394.  
  395. * @uses esc_html() To sanitize the view title
  396.  
  397. * @return array The just registered (but processed) view
  398.  
  399. */
  400.  
  401. function bbp_register_view( $view, $title, $query_args = '', $feed = true, $capability = '' ) {
  402.  
  403.  
  404.  
  405. // Bail if user does not have capability
  406.  
  407. if ( ! empty( $capability ) && ! current_user_can( $capability ) )
  408.  
  409. return false;
  410.  
  411.  
  412.  
  413. $bbp = bbpress();
  414.  
  415. $view = sanitize_title( $view );
  416.  
  417. $title = esc_html( $title );
  418.  
  419.  
  420.  
  421. if ( empty( $view ) || empty( $title ) )
  422.  
  423. return false;
  424.  
  425.  
  426.  
  427. $query_args = bbp_parse_args( $query_args, '', 'register_view' );
  428.  
  429.  
  430.  
  431. // Set show_stickies to false if it wasn't supplied
  432.  
  433. if ( !isset( $query_args['show_stickies'] ) )
  434.  
  435. $query_args['show_stickies'] = false;
  436.  
  437.  
  438.  
  439. $bbp->views[$view] = array(
  440.  
  441. 'title' => $title,
  442.  
  443. 'query' => $query_args,
  444.  
  445. 'feed' => $feed
  446.  
  447. );
  448.  
  449.  
  450.  
  451. return $bbp->views[$view];
  452.  
  453. }
  454.  
  455.  
  456.  
  457. /**
  458.  
  459. * Deregister a bbPress view
  460.  
  461. *
  462.  
  463. * @since bbPress (r2789)
  464.  
  465. *
  466.  
  467. * @param string $view View name
  468.  
  469. * @uses sanitize_title() To sanitize the view name
  470.  
  471. * @return bool False if the view doesn't exist, true on success
  472.  
  473. */
  474.  
  475. function bbp_deregister_view( $view ) {
  476.  
  477. $bbp = bbpress();
  478.  
  479. $view = sanitize_title( $view );
  480.  
  481.  
  482.  
  483. if ( !isset( $bbp->views[$view] ) )
  484.  
  485. return false;
  486.  
  487.  
  488.  
  489. unset( $bbp->views[$view] );
  490.  
  491.  
  492.  
  493. return true;
  494.  
  495. }
  496.  
  497.  
  498.  
  499. /**
  500.  
  501. * Run the view's query
  502.  
  503. *
  504.  
  505. * @since bbPress (r2789)
  506.  
  507. *
  508.  
  509. * @param string $view Optional. View id
  510.  
  511. * @param mixed $new_args New arguments. See {@link bbp_has_topics()}
  512.  
  513. * @uses bbp_get_view_id() To get the view id
  514.  
  515. * @uses bbp_get_view_query_args() To get the view query args
  516.  
  517. * @uses sanitize_title() To sanitize the view name
  518.  
  519. * @uses bbp_has_topics() To make the topics query
  520.  
  521. * @return bool False if the view doesn't exist, otherwise if topics are there
  522.  
  523. */
  524.  
  525. function bbp_view_query( $view = '', $new_args = '' ) {
  526.  
  527.  
  528.  
  529. $view = bbp_get_view_id( $view );
  530.  
  531. if ( empty( $view ) )
  532.  
  533. return false;
  534.  
  535.  
  536.  
  537. $query_args = bbp_get_view_query_args( $view );
  538.  
  539.  
  540.  
  541. if ( !empty( $new_args ) ) {
  542.  
  543. $new_args = bbp_parse_args( $new_args, '', 'view_query' );
  544.  
  545. $query_args = array_merge( $query_args, $new_args );
  546.  
  547. }
  548.  
  549.  
  550.  
  551. return bbp_has_topics( $query_args );
  552.  
  553. }
  554.  
  555.  
  556.  
  557. /**
  558.  
  559. * Return the view's query arguments
  560.  
  561. *
  562.  
  563. * @since bbPress (r2789)
  564.  
  565. *
  566.  
  567. * @param string $view View name
  568.  
  569. * @uses bbp_get_view_id() To get the view id
  570.  
  571. * @return array Query arguments
  572.  
  573. */
  574.  
  575. function bbp_get_view_query_args( $view ) {
  576.  
  577. $view = bbp_get_view_id( $view );
  578.  
  579. $retval = !empty( $view ) ? bbpress()->views[$view]['query'] : false;
  580.  
  581.  
  582.  
  583. return apply_filters( 'bbp_get_view_query_args', $retval, $view );
  584.  
  585. }
  586.  
  587.  
  588.  
  589. /** Errors ********************************************************************/
  590.  
  591.  
  592.  
  593. /**
  594.  
  595. * Adds an error message to later be output in the theme
  596.  
  597. *
  598.  
  599. * @since bbPress (r3381)
  600.  
  601. *
  602.  
  603. * @see WP_Error()
  604.  
  605. * @uses WP_Error::add();
  606.  
  607. *
  608.  
  609. * @param string $code Unique code for the error message
  610.  
  611. * @param string $message Translated error message
  612.  
  613. * @param string $data Any additional data passed with the error message
  614.  
  615. */
  616.  
  617. function bbp_add_error( $code = '', $message = '', $data = '' ) {
  618.  
  619. bbpress()->errors->add( $code, $message, $data );
  620.  
  621. }
  622.  
  623.  
  624.  
  625. /**
  626.  
  627. * Check if error messages exist in queue
  628.  
  629. *
  630.  
  631. * @since bbPress (r3381)
  632.  
  633. *
  634.  
  635. * @see WP_Error()
  636.  
  637. *
  638.  
  639. * @uses is_wp_error()
  640.  
  641. * @usese WP_Error::get_error_codes()
  642.  
  643. */
  644.  
  645. function bbp_has_errors() {
  646.  
  647. $has_errors = bbpress()->errors->get_error_codes() ? true : false;
  648.  
  649.  
  650.  
  651. return apply_filters( 'bbp_has_errors', $has_errors, bbpress()->errors );
  652.  
  653. }
  654.  
  655.  
  656.  
  657. /** Mentions ******************************************************************/
  658.  
  659.  
  660.  
  661. /**
  662.  
  663. * Set the pattern used for matching usernames for mentions.
  664.  
  665. *
  666.  
  667. * Moved into its own function to allow filtering of the regex pattern
  668.  
  669. * anywhere mentions might be used.
  670.  
  671. *
  672.  
  673. * @since bbPress (r4997)
  674.  
  675. * @return string Pattern to match usernames with
  676.  
  677. */
  678.  
  679. function bbp_find_mentions_pattern() {
  680.  
  681. return apply_filters( 'bbp_find_mentions_pattern', '/[@]+([A-Za-z0-9-_\.@]+)\b/' );
  682.  
  683. }
  684.  
  685.  
  686.  
  687. /**
  688.  
  689. * Searches through the content to locate usernames, designated by an @ sign.
  690.  
  691. *
  692.  
  693. * @since bbPress (r4323)
  694.  
  695. *
  696.  
  697. * @param string $content The content
  698.  
  699. * @return bool|array $usernames Existing usernames. False if no matches.
  700.  
  701. */
  702.  
  703. function bbp_find_mentions( $content = '' ) {
  704.  
  705. $pattern = bbp_find_mentions_pattern();
  706.  
  707. preg_match_all( $pattern, $content, $usernames );
  708.  
  709. $usernames = array_unique( array_filter( $usernames[1] ) );
  710.  
  711.  
  712.  
  713. // Bail if no usernames
  714.  
  715. if ( empty( $usernames ) ) {
  716.  
  717. $usernames = false;
  718.  
  719. }
  720.  
  721.  
  722.  
  723. return apply_filters( 'bbp_find_mentions', $usernames, $pattern, $content );
  724.  
  725. }
  726.  
  727.  
  728.  
  729. /**
  730.  
  731. * Finds and links @-mentioned users in the content
  732.  
  733. *
  734.  
  735. * @since bbPress (r4323)
  736.  
  737. *
  738.  
  739. * @uses bbp_find_mentions() To get usernames in content areas
  740.  
  741. * @return string $content Content filtered for mentions
  742.  
  743. */
  744.  
  745. function bbp_mention_filter( $content = '' ) {
  746.  
  747.  
  748.  
  749. // Get Usernames and bail if none exist
  750.  
  751. $usernames = bbp_find_mentions( $content );
  752.  
  753. if ( empty( $usernames ) )
  754.  
  755. return $content;
  756.  
  757.  
  758.  
  759. // Loop through usernames and link to profiles
  760.  
  761. foreach ( (array) $usernames as $username ) {
  762.  
  763.  
  764.  
  765. // Skip if username does not exist or user is not active
  766.  
  767. $user = get_user_by( 'slug', $username );
  768.  
  769. if ( empty( $user->ID ) || bbp_is_user_inactive( $user->ID ) )
  770.  
  771. continue;
  772.  
  773.  
  774.  
  775. // Replace name in content
  776.  
  777. $content = preg_replace( '/(@' . $username . '\b)/', sprintf( '<a href="%1$s" rel="nofollow">@%2$s</a>', bbp_get_user_profile_url( $user->ID ), $username ), $content );
  778.  
  779. }
  780.  
  781.  
  782.  
  783. // Return modified content
  784.  
  785. return $content;
  786.  
  787. }
  788.  
  789.  
  790.  
  791. /** Post Statuses *************************************************************/
  792.  
  793.  
  794.  
  795. /**
  796.  
  797. * Return the public post status ID
  798.  
  799. *
  800.  
  801. * @since bbPress (r3504)
  802.  
  803. *
  804.  
  805. * @return string
  806.  
  807. */
  808.  
  809. function bbp_get_public_status_id() {
  810.  
  811. return bbpress()->public_status_id;
  812.  
  813. }
  814.  
  815.  
  816.  
  817. /**
  818.  
  819. * Return the pending post status ID
  820.  
  821. *
  822.  
  823. * @since bbPress (r3581)
  824.  
  825. *
  826.  
  827. * @return string
  828.  
  829. */
  830.  
  831. function bbp_get_pending_status_id() {
  832.  
  833. return bbpress()->pending_status_id;
  834.  
  835. }
  836.  
  837.  
  838.  
  839. /**
  840.  
  841. * Return the private post status ID
  842.  
  843. *
  844.  
  845. * @since bbPress (r3504)
  846.  
  847. *
  848.  
  849. * @return string
  850.  
  851. */
  852.  
  853. function bbp_get_private_status_id() {
  854.  
  855. return bbpress()->private_status_id;
  856.  
  857. }
  858.  
  859.  
  860.  
  861. /**
  862.  
  863. * Return the hidden post status ID
  864.  
  865. *
  866.  
  867. * @since bbPress (r3504)
  868.  
  869. *
  870.  
  871. * @return string
  872.  
  873. */
  874.  
  875. function bbp_get_hidden_status_id() {
  876.  
  877. return bbpress()->hidden_status_id;
  878.  
  879. }
  880.  
  881.  
  882.  
  883. /**
  884.  
  885. * Return the closed post status ID
  886.  
  887. *
  888.  
  889. * @since bbPress (r3504)
  890.  
  891. *
  892.  
  893. * @return string
  894.  
  895. */
  896.  
  897. function bbp_get_closed_status_id() {
  898.  
  899. return bbpress()->closed_status_id;
  900.  
  901. }
  902.  
  903.  
  904.  
  905. /**
  906.  
  907. * Return the spam post status ID
  908.  
  909. *
  910.  
  911. * @since bbPress (r3504)
  912.  
  913. *
  914.  
  915. * @return string
  916.  
  917. */
  918.  
  919. function bbp_get_spam_status_id() {
  920.  
  921. return bbpress()->spam_status_id;
  922.  
  923. }
  924.  
  925.  
  926.  
  927. /**
  928.  
  929. * Return the trash post status ID
  930.  
  931. *
  932.  
  933. * @since bbPress (r3504)
  934.  
  935. *
  936.  
  937. * @return string
  938.  
  939. */
  940.  
  941. function bbp_get_trash_status_id() {
  942.  
  943. return bbpress()->trash_status_id;
  944.  
  945. }
  946.  
  947.  
  948.  
  949. /**
  950.  
  951. * Return the orphan post status ID
  952.  
  953. *
  954.  
  955. * @since bbPress (r3504)
  956.  
  957. *
  958.  
  959. * @return string
  960.  
  961. */
  962.  
  963. function bbp_get_orphan_status_id() {
  964.  
  965. return bbpress()->orphan_status_id;
  966.  
  967. }
  968.  
  969.  
  970.  
  971. /** Rewrite IDs ***************************************************************/
  972.  
  973.  
  974.  
  975. /**
  976.  
  977. * Return the unique ID for user profile rewrite rules
  978.  
  979. *
  980.  
  981. * @since bbPress (r3762)
  982.  
  983. * @return string
  984.  
  985. */
  986.  
  987. function bbp_get_user_rewrite_id() {
  988.  
  989. return bbpress()->user_id;
  990.  
  991. }
  992.  
  993.  
  994.  
  995. /**
  996.  
  997. * Return the unique ID for all edit rewrite rules (forum|topic|reply|tag|user)
  998.  
  999. *
  1000.  
  1001. * @since bbPress (r3762)
  1002.  
  1003. * @return string
  1004.  
  1005. */
  1006.  
  1007. function bbp_get_edit_rewrite_id() {
  1008.  
  1009. return bbpress()->edit_id;
  1010.  
  1011. }
  1012.  
  1013.  
  1014.  
  1015. /**
  1016.  
  1017. * Return the unique ID for all search rewrite rules
  1018.  
  1019. *
  1020.  
  1021. * @since bbPress (r4579)
  1022.  
  1023. *
  1024.  
  1025. * @return string
  1026.  
  1027. */
  1028.  
  1029. function bbp_get_search_rewrite_id() {
  1030.  
  1031. return bbpress()->search_id;
  1032.  
  1033. }
  1034.  
  1035.  
  1036.  
  1037. /**
  1038.  
  1039. * Return the unique ID for user topics rewrite rules
  1040.  
  1041. *
  1042.  
  1043. * @since bbPress (r4321)
  1044.  
  1045. * @return string
  1046.  
  1047. */
  1048.  
  1049. function bbp_get_user_topics_rewrite_id() {
  1050.  
  1051. return bbpress()->tops_id;
  1052.  
  1053. }
  1054.  
  1055.  
  1056.  
  1057. /**
  1058.  
  1059. * Return the unique ID for user replies rewrite rules
  1060.  
  1061. *
  1062.  
  1063. * @since bbPress (r4321)
  1064.  
  1065. * @return string
  1066.  
  1067. */
  1068.  
  1069. function bbp_get_user_replies_rewrite_id() {
  1070.  
  1071. return bbpress()->reps_id;
  1072.  
  1073. }
  1074.  
  1075.  
  1076.  
  1077. /**
  1078.  
  1079. * Return the unique ID for user caps rewrite rules
  1080.  
  1081. *
  1082.  
  1083. * @since bbPress (r4181)
  1084.  
  1085. * @return string
  1086.  
  1087. */
  1088.  
  1089. function bbp_get_user_favorites_rewrite_id() {
  1090.  
  1091. return bbpress()->favs_id;
  1092.  
  1093. }
  1094.  
  1095.  
  1096.  
  1097. /**
  1098.  
  1099. * Return the unique ID for user caps rewrite rules
  1100.  
  1101. *
  1102.  
  1103. * @since bbPress (r4181)
  1104.  
  1105. * @return string
  1106.  
  1107. */
  1108.  
  1109. function bbp_get_user_subscriptions_rewrite_id() {
  1110.  
  1111. return bbpress()->subs_id;
  1112.  
  1113. }
  1114.  
  1115.  
  1116.  
  1117. /**
  1118.  
  1119. * Return the unique ID for topic view rewrite rules
  1120.  
  1121. *
  1122.  
  1123. * @since bbPress (r3762)
  1124.  
  1125. * @return string
  1126.  
  1127. */
  1128.  
  1129. function bbp_get_view_rewrite_id() {
  1130.  
  1131. return bbpress()->view_id;
  1132.  
  1133. }
  1134.  
  1135.  
  1136.  
  1137. /** Rewrite Extras ************************************************************/
  1138.  
  1139.  
  1140.  
  1141. /**
  1142.  
  1143. * Get the id used for paginated requests
  1144.  
  1145. *
  1146.  
  1147. * @since bbPress (r4926)
  1148.  
  1149. * @return string
  1150.  
  1151. */
  1152.  
  1153. function bbp_get_paged_rewrite_id() {
  1154.  
  1155. return bbpress()->paged_id;
  1156.  
  1157. }
  1158.  
  1159.  
  1160.  
  1161. /**
  1162.  
  1163. * Get the slug used for paginated requests
  1164.  
  1165. *
  1166.  
  1167. * @since bbPress (r4926)
  1168.  
  1169. * @global object $wp_rewrite The WP_Rewrite object
  1170.  
  1171. * @return string
  1172.  
  1173. */
  1174.  
  1175. function bbp_get_paged_slug() {
  1176.  
  1177. global $wp_rewrite;
  1178.  
  1179. return $wp_rewrite->pagination_base;
  1180.  
  1181. }
  1182.  
  1183.  
  1184.  
  1185. /**
  1186.  
  1187. * Delete a blogs rewrite rules, so that they are automatically rebuilt on
  1188.  
  1189. * the subsequent page load.
  1190.  
  1191. *
  1192.  
  1193. * @since bbPress (r4198)
  1194.  
  1195. */
  1196.  
  1197. function bbp_delete_rewrite_rules() {
  1198.  
  1199. delete_option( 'rewrite_rules' );
  1200.  
  1201. }
  1202.  
  1203.  
  1204.  
  1205. /** Requests ******************************************************************/
  1206.  
  1207.  
  1208.  
  1209. /**
  1210.  
  1211. * Return true|false if this is a POST request
  1212.  
  1213. *
  1214.  
  1215. * @since bbPress (r4790)
  1216.  
  1217. * @return bool
  1218.  
  1219. */
  1220.  
  1221. function bbp_is_post_request() {
  1222.  
  1223. return (bool) ( 'POST' === strtoupper( $_SERVER['REQUEST_METHOD'] ) );
  1224.  
  1225. }
  1226.  
  1227.  
  1228.  
  1229. /**
  1230.  
  1231. * Return true|false if this is a GET request
  1232.  
  1233. *
  1234.  
  1235. * @since bbPress (r4790)
  1236.  
  1237. * @return bool
  1238.  
  1239. */
  1240.  
  1241. function bbp_is_get_request() {
  1242.  
  1243. return (bool) ( 'GET' === strtoupper( $_SERVER['REQUEST_METHOD'] ) );
  1244.  
  1245. }
  1246.  
  1247.  
  1248.  
  1249. /**
  1250.  
  1251. * Add @mentionname after bbpress forum author details
  1252.  
  1253. */
  1254.  
  1255.  
  1256.  
  1257. add_action( 'bbp_theme_after_reply_author_details', 'mentionname_to_bbpress' );
  1258.  
  1259. function mentionname_to_bbpress () {
  1260.  
  1261. $user = get_userdata( bbp_get_reply_author_id() );
  1262.  
  1263. if ( !empty( $user->user_nicename ) ) {
  1264.  
  1265. $user_nicename = $user->user_nicename;
  1266.  
  1267. echo '<b><font color="#888">' ;
  1268.  
  1269. echo "@".$user_nicename.'</font></b>' ;
  1270.  
  1271. }
  1272.  
  1273. }
  1274.  
  1275.  
  1276.  
  1277. //take away the role display
  1278.  
  1279. function hide_role ($args) {
  1280.  
  1281. $args['show_role'] = false ;
  1282.  
  1283. Return $args ;
  1284.  
  1285. }
  1286.  
  1287. add_filter ('bbp_before_get_reply_author_link_parse_args', 'hide_role') ;
  1288.  
  1289.  
  1290.  
  1291. //add role badge
  1292.  
  1293. add_action( 'bbp_theme_after_reply_author_details', 'add_image' );
  1294.  
  1295. function add_image () {
  1296.  
  1297. $role = bbp_get_user_display_role( bbp_get_reply_author_id( $reply_id ) );
  1298.  
  1299. if ($role == 'Administrator') {
  1300.  
  1301. echo "<img src='/wp-content/plugins/bbpress/includes/core/badge_staff.png' title='Staff' alt='Staff' />";
  1302.  
  1303. }
  1304.  
  1305. if ($role == 'Global Moderator') {
  1306.  
  1307. echo "<img src='/wp-content/plugins/bbpress/includes/core/badge_staff.png' title='Staff' alt='Staff' />";
  1308.  
  1309. }
  1310.  
  1311. if ($role == 'Diamond') {
  1312.  
  1313. echo "<img src='/wp-content/plugins/bbpress/includes/core/badge_diamond.png' title='Diamond' alt='Diamond' />";
  1314.  
  1315. }
  1316.  
  1317. if ($role == 'Gold') {
  1318.  
  1319. echo "<img src='/wp-content/plugins/bbpress/includes/core/badge_gold.png' title='Gold' alt='Gold' />";
  1320.  
  1321. }
  1322.  
  1323. if ($role == 'Silver') {
  1324.  
  1325. echo "<img src='/wp-content/plugins/bbpress/includes/core/badge_silver.png' title='Silver' alt=Silver' />";
  1326.  
  1327. }
  1328.  
  1329. if ($role == 'Bronze') {
  1330.  
  1331. echo "<img src='/wp-content/plugins/bbpress/includes/core/badge_bronze.png' title='Bronze' alt='Bronze' />";
  1332.  
  1333. }
  1334.  
  1335. if ($role == 'Newbie') {
  1336.  
  1337. echo "<img src='/wp-content/plugins/bbpress/includes/core/badge_member.png' title='Member' alt='Member' />";
  1338.  
  1339. }
  1340.  
  1341. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement