PageRenderTime 65ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/bbpress/includes/users/template.php

https://bitbucket.org/Thane2376/death-edge.ru
PHP | 2044 lines | 760 code | 301 blank | 983 comment | 154 complexity | 64445619ab748de5ed7426ab41582390 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-3.0, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * bbPress User Template Tags
  4. *
  5. * @package bbPress
  6. * @subpackage TemplateTags
  7. */
  8. // Exit if accessed directly
  9. if ( !defined( 'ABSPATH' ) ) exit;
  10. /** Users *********************************************************************/
  11. /**
  12. * Output a validated user id
  13. *
  14. * @since bbPress (r2729)
  15. *
  16. * @param int $user_id Optional. User id
  17. * @param bool $displayed_user_fallback Fallback on displayed user?
  18. * @param bool $current_user_fallback Fallback on current user?
  19. * @uses bbp_get_user_id() To get the user id
  20. */
  21. function bbp_user_id( $user_id = 0, $displayed_user_fallback = true, $current_user_fallback = false ) {
  22. echo bbp_get_user_id( $user_id, $displayed_user_fallback, $current_user_fallback );
  23. }
  24. /**
  25. * Return a validated user id
  26. *
  27. * @since bbPress (r2729)
  28. *
  29. * @param int $user_id Optional. User id
  30. * @param bool $displayed_user_fallback Fallback on displayed user?
  31. * @param bool $current_user_fallback Fallback on current user?
  32. * @uses get_query_var() To get the 'bbp_user_id' query var
  33. * @uses apply_filters() Calls 'bbp_get_user_id' with the user id
  34. * @return int Validated user id
  35. */
  36. function bbp_get_user_id( $user_id = 0, $displayed_user_fallback = true, $current_user_fallback = false ) {
  37. $bbp = bbpress();
  38. // Easy empty checking
  39. if ( !empty( $user_id ) && is_numeric( $user_id ) ) {
  40. $bbp_user_id = $user_id;
  41. // Currently viewing or editing a user
  42. } elseif ( ( true === $displayed_user_fallback ) && !empty( $bbp->displayed_user->ID ) ) {
  43. $bbp_user_id = $bbp->displayed_user->ID;
  44. // Maybe fallback on the current_user ID
  45. } elseif ( ( true === $current_user_fallback ) && !empty( $bbp->current_user->ID ) ) {
  46. $bbp_user_id = $bbp->current_user->ID;
  47. // Failsafe
  48. } else {
  49. $bbp_user_id = 0;
  50. }
  51. return (int) apply_filters( 'bbp_get_user_id', (int) $bbp_user_id, $displayed_user_fallback, $current_user_fallback );
  52. }
  53. /**
  54. * Output ID of current user
  55. *
  56. * @since bbPress (r2574)
  57. *
  58. * @uses bbp_get_current_user_id() To get the current user id
  59. */
  60. function bbp_current_user_id() {
  61. echo bbp_get_current_user_id();
  62. }
  63. /**
  64. * Return ID of current user
  65. *
  66. * @since bbPress (r2574)
  67. *
  68. * @uses bbp_get_user_id() To get the current user id
  69. * @uses apply_filters() Calls 'bbp_get_current_user_id' with the id
  70. * @return int Current user id
  71. */
  72. function bbp_get_current_user_id() {
  73. return apply_filters( 'bbp_get_current_user_id', bbp_get_user_id( 0, false, true ) );
  74. }
  75. /**
  76. * Output ID of displayed user
  77. *
  78. * @since bbPress (r2688)
  79. *
  80. * @uses bbp_get_displayed_user_id() To get the displayed user id
  81. */
  82. function bbp_displayed_user_id() {
  83. echo bbp_get_displayed_user_id();
  84. }
  85. /**
  86. * Return ID of displayed user
  87. *
  88. * @since bbPress (r2688)
  89. *
  90. * @uses bbp_get_user_id() To get the displayed user id
  91. * @uses apply_filters() Calls 'bbp_get_displayed_user_id' with the id
  92. * @return int Displayed user id
  93. */
  94. function bbp_get_displayed_user_id() {
  95. return apply_filters( 'bbp_get_displayed_user_id', bbp_get_user_id( 0, true, false ) );
  96. }
  97. /**
  98. * Output a sanitized user field value
  99. *
  100. * This function relies on the $filter parameter to decide how to sanitize
  101. * the field value that it finds. Since it uses the WP_User object's magic
  102. * __get() method, it can also be used to get user_meta values.
  103. *
  104. * @since bbPress (r2688)
  105. *
  106. * @param string $field Field to get
  107. * @param string $filter How to filter the field value (null|raw|db|display|edit)
  108. * @uses bbp_get_displayed_user_field() To get the field
  109. */
  110. function bbp_displayed_user_field( $field = '', $filter = 'display' ) {
  111. echo bbp_get_displayed_user_field( $field, $filter );
  112. }
  113. /**
  114. * Return a sanitized user field value
  115. *
  116. * This function relies on the $filter parameter to decide how to sanitize
  117. * the field value that it finds. Since it uses the WP_User object's magic
  118. * __get() method, it can also be used to get user_meta values.
  119. *
  120. * @since bbPress (r2688)
  121. *
  122. * @param string $field Field to get
  123. * @param string $filter How to filter the field value (null|raw|db|display|edit)
  124. * @see WP_User::__get() for more on how the value is retrieved
  125. * @see sanitize_user_field() for more on how the value is sanitized
  126. * @uses apply_filters() Calls 'bbp_get_displayed_user_field' with the value
  127. * @return string|bool Value of the field if it exists, else false
  128. */
  129. function bbp_get_displayed_user_field( $field = '', $filter = 'display' ) {
  130. // Get the displayed user
  131. $user = bbpress()->displayed_user;
  132. // Juggle the user filter property because we don't want to muck up how
  133. // other code might interact with this object.
  134. $old_filter = $user->filter;
  135. $user->filter = $filter;
  136. // Get the field value from the WP_User object. We don't need to perform
  137. // an isset() because the WP_User::__get() does it for us.
  138. $value = $user->$field;
  139. // Put back the user filter property that was previously juggled above.
  140. $user->filter = $old_filter;
  141. // Return empty
  142. return apply_filters( 'bbp_get_displayed_user_field', $value, $field, $filter );
  143. }
  144. /**
  145. * Output name of current user
  146. *
  147. * @since bbPress (r2574)
  148. *
  149. * @uses bbp_get_current_user_name() To get the current user name
  150. */
  151. function bbp_current_user_name() {
  152. echo bbp_get_current_user_name();
  153. }
  154. /**
  155. * Return name of current user
  156. *
  157. * @since bbPress (r2574)
  158. *
  159. * @uses apply_filters() Calls 'bbp_get_current_user_name' with the
  160. * current user name
  161. * @return string
  162. */
  163. function bbp_get_current_user_name() {
  164. global $user_identity;
  165. $current_user_name = is_user_logged_in() ? $user_identity : __( 'Anonymous', 'bbpress' );
  166. return apply_filters( 'bbp_get_current_user_name', $current_user_name );
  167. }
  168. /**
  169. * Output avatar of current user
  170. *
  171. * @since bbPress (r2574)
  172. *
  173. * @param int $size Size of the avatar. Defaults to 40
  174. * @uses bbp_get_current_user_avatar() To get the current user avatar
  175. */
  176. function bbp_current_user_avatar( $size = 40 ) {
  177. echo bbp_get_current_user_avatar( $size );
  178. }
  179. /**
  180. * Return avatar of current user
  181. *
  182. * @since bbPress (r2574)
  183. *
  184. * @param int $size Size of the avatar. Defaults to 40
  185. * @uses bbp_get_current_user_id() To get the current user id
  186. * @uses bbp_get_current_anonymous_user_data() To get the current
  187. * anonymous user's email
  188. * @uses get_avatar() To get the avatar
  189. * @uses apply_filters() Calls 'bbp_get_current_user_avatar' with the
  190. * avatar and size
  191. * @return string Current user avatar
  192. */
  193. function bbp_get_current_user_avatar( $size = 40 ) {
  194. $user = bbp_get_current_user_id();
  195. if ( empty( $user ) )
  196. $user = bbp_get_current_anonymous_user_data( 'email' );
  197. $avatar = get_avatar( $user, $size );
  198. return apply_filters( 'bbp_get_current_user_avatar', $avatar, $size );
  199. }
  200. /**
  201. * Output link to the profile page of a user
  202. *
  203. * @since bbPress (r2688)
  204. *
  205. * @param int $user_id Optional. User id
  206. * @uses bbp_get_user_profile_link() To get user profile link
  207. */
  208. function bbp_user_profile_link( $user_id = 0 ) {
  209. echo bbp_get_user_profile_link( $user_id );
  210. }
  211. /**
  212. * Return link to the profile page of a user
  213. *
  214. * @since bbPress (r2688)
  215. *
  216. * @param int $user_id Optional. User id
  217. * @uses bbp_get_user_id() To get user id
  218. * @uses get_userdata() To get user data
  219. * @uses bbp_get_user_profile_url() To get user profile url
  220. * @uses apply_filters() Calls 'bbp_get_user_profile_link' with the user
  221. * profile link and user id
  222. * @return string User profile link
  223. */
  224. function bbp_get_user_profile_link( $user_id = 0 ) {
  225. // Validate user id
  226. $user_id = bbp_get_user_id( $user_id );
  227. if ( empty( $user_id ) )
  228. return false;
  229. $user = get_userdata( $user_id );
  230. $user_link = '<a href="' . esc_url( bbp_get_user_profile_url( $user_id ) ) . '">' . esc_html( $user->display_name ) . '</a>';
  231. return apply_filters( 'bbp_get_user_profile_link', $user_link, $user_id );
  232. }
  233. /**
  234. * Output a users nicename to the screen
  235. *
  236. * @since bbPress (r4671)
  237. *
  238. * @param int $user_id User ID whose nicename to get
  239. * @param array $args before|after|user_id|force
  240. */
  241. function bbp_user_nicename( $user_id = 0, $args = array() ) {
  242. echo bbp_get_user_nicename( $user_id, $args );
  243. }
  244. /**
  245. * Return a users nicename to the screen
  246. *
  247. * @since bbPress (r4671)
  248. *
  249. * @param int $user_id User ID whose nicename to get
  250. * @param array $args before|after|user_id|force
  251. * @return string User nicename, maybe wrapped in before/after strings
  252. */
  253. function bbp_get_user_nicename( $user_id = 0, $args = array() ) {
  254. // Bail if no user ID passed
  255. $user_id = bbp_get_user_id( $user_id );
  256. if ( empty( $user_id ) )
  257. return false;
  258. // Parse default arguments
  259. $r = bbp_parse_args( $args, array(
  260. 'user_id' => $user_id,
  261. 'before' => '',
  262. 'after' => '',
  263. 'force' => ''
  264. ), 'get_user_nicename' );
  265. // Get the user data and nicename
  266. if ( empty( $r['force'] ) ) {
  267. $user = get_userdata( $user_id );
  268. $nicename = $user->user_nicename;
  269. // Force the nicename to something else
  270. } else {
  271. $nicename = (string) $r['force'];
  272. }
  273. // Maybe wrap the nicename
  274. $retval = !empty( $nicename ) ? ( $r['before'] . $nicename . $r['after'] ) : '';
  275. // Filter and return
  276. return (string) apply_filters( 'bbp_get_user_nicename', $retval, $user_id, $r );
  277. }
  278. /**
  279. * Output URL to the profile page of a user
  280. *
  281. * @since bbPress (r2688)
  282. *
  283. * @param int $user_id Optional. User id
  284. * @param string $user_nicename Optional. User nicename
  285. * @uses bbp_get_user_profile_url() To get user profile url
  286. */
  287. function bbp_user_profile_url( $user_id = 0, $user_nicename = '' ) {
  288. echo esc_url( bbp_get_user_profile_url( $user_id, $user_nicename ) );
  289. }
  290. /**
  291. * Return URL to the profile page of a user
  292. *
  293. * @since bbPress (r2688)
  294. *
  295. * @param int $user_id Optional. User id
  296. * @param string $user_nicename Optional. User nicename
  297. * @uses bbp_get_user_id() To get user id
  298. * @uses WP_Rewrite::using_permalinks() To check if the blog is using
  299. * permalinks
  300. * @uses add_query_arg() To add custom args to the url
  301. * @uses home_url() To get blog home url
  302. * @uses apply_filters() Calls 'bbp_get_user_profile_url' with the user
  303. * profile url, user id and user nicename
  304. * @return string User profile url
  305. */
  306. function bbp_get_user_profile_url( $user_id = 0, $user_nicename = '' ) {
  307. global $wp_rewrite;
  308. // Use displayed user ID if there is one, and one isn't requested
  309. $user_id = bbp_get_user_id( $user_id );
  310. if ( empty( $user_id ) )
  311. return false;
  312. // Allow early overriding of the profile URL to cut down on processing
  313. $early_profile_url = apply_filters( 'bbp_pre_get_user_profile_url', (int) $user_id );
  314. if ( is_string( $early_profile_url ) )
  315. return $early_profile_url;
  316. // Pretty permalinks
  317. if ( $wp_rewrite->using_permalinks() ) {
  318. $url = $wp_rewrite->root . bbp_get_user_slug() . '/%' . bbp_get_user_rewrite_id() . '%';
  319. // Get username if not passed
  320. if ( empty( $user_nicename ) ) {
  321. $user_nicename = bbp_get_user_nicename( $user_id );
  322. }
  323. $url = str_replace( '%' . bbp_get_user_rewrite_id() . '%', $user_nicename, $url );
  324. $url = home_url( user_trailingslashit( $url ) );
  325. // Unpretty permalinks
  326. } else {
  327. $url = add_query_arg( array( bbp_get_user_rewrite_id() => $user_id ), home_url( '/' ) );
  328. }
  329. return apply_filters( 'bbp_get_user_profile_url', $url, $user_id, $user_nicename );
  330. }
  331. /**
  332. * Output link to the profile edit page of a user
  333. *
  334. * @since bbPress (r2688)
  335. *
  336. * @param int $user_id Optional. User id
  337. * @uses bbp_get_user_profile_edit_link() To get user profile edit link
  338. */
  339. function bbp_user_profile_edit_link( $user_id = 0 ) {
  340. echo bbp_get_user_profile_edit_link( $user_id );
  341. }
  342. /**
  343. * Return link to the profile edit page of a user
  344. *
  345. * @since bbPress (r2688)
  346. *
  347. * @param int $user_id Optional. User id
  348. * @uses bbp_get_user_id() To get user id
  349. * @uses get_userdata() To get user data
  350. * @uses bbp_get_user_profile_edit_url() To get user profile edit url
  351. * @uses apply_filters() Calls 'bbp_get_user_profile_link' with the edit
  352. * link and user id
  353. * @return string User profile edit link
  354. */
  355. function bbp_get_user_profile_edit_link( $user_id = 0 ) {
  356. // Validate user id
  357. $user_id = bbp_get_user_id( $user_id );
  358. if ( empty( $user_id ) )
  359. return false;
  360. $user = get_userdata( $user_id );
  361. $edit_link = '<a href="' . esc_url( bbp_get_user_profile_url( $user_id ) ) . '">' . esc_html( $user->display_name ) . '</a>';
  362. return apply_filters( 'bbp_get_user_profile_edit_link', $edit_link, $user_id );
  363. }
  364. /**
  365. * Output URL to the profile edit page of a user
  366. *
  367. * @since bbPress (r2688)
  368. *
  369. * @param int $user_id Optional. User id
  370. * @param string $user_nicename Optional. User nicename
  371. * @uses bbp_get_user_profile_edit_url() To get user profile edit url
  372. */
  373. function bbp_user_profile_edit_url( $user_id = 0, $user_nicename = '' ) {
  374. echo esc_url( bbp_get_user_profile_edit_url( $user_id, $user_nicename ) );
  375. }
  376. /**
  377. * Return URL to the profile edit page of a user
  378. *
  379. * @since bbPress (r2688)
  380. *
  381. * @param int $user_id Optional. User id
  382. * @param string $user_nicename Optional. User nicename
  383. * @uses bbp_get_user_id() To get user id
  384. * @uses WP_Rewrite::using_permalinks() To check if the blog is using
  385. * permalinks
  386. * @uses add_query_arg() To add custom args to the url
  387. * @uses home_url() To get blog home url
  388. * @uses apply_filters() Calls 'bbp_get_user_edit_profile_url' with the
  389. * edit profile url, user id and user nicename
  390. * @return string
  391. */
  392. function bbp_get_user_profile_edit_url( $user_id = 0, $user_nicename = '' ) {
  393. global $wp_rewrite;
  394. $bbp = bbpress();
  395. $user_id = bbp_get_user_id( $user_id );
  396. if ( empty( $user_id ) )
  397. return false;
  398. // Pretty permalinks
  399. if ( $wp_rewrite->using_permalinks() ) {
  400. $url = $wp_rewrite->root . bbp_get_user_slug() . '/%' . $bbp->user_id . '%/' . $bbp->edit_id;
  401. // Get username if not passed
  402. if ( empty( $user_nicename ) ) {
  403. $user = get_userdata( $user_id );
  404. if ( !empty( $user->user_nicename ) ) {
  405. $user_nicename = $user->user_nicename;
  406. }
  407. }
  408. $url = str_replace( '%' . $bbp->user_id . '%', $user_nicename, $url );
  409. $url = home_url( user_trailingslashit( $url ) );
  410. // Unpretty permalinks
  411. } else {
  412. $url = add_query_arg( array( $bbp->user_id => $user_id, $bbp->edit_id => '1' ), home_url( '/' ) );
  413. }
  414. return apply_filters( 'bbp_get_user_edit_profile_url', $url, $user_id, $user_nicename );
  415. }
  416. /**
  417. * Output a user's main role for display
  418. *
  419. * @since bbPress (r3860)
  420. *
  421. * @param int $user_id
  422. * @uses bbp_get_user_display_role To get the user display role
  423. */
  424. function bbp_user_display_role( $user_id = 0 ) {
  425. echo bbp_get_user_display_role( $user_id );
  426. }
  427. /**
  428. * Return a user's main role for display
  429. *
  430. * @since bbPress (r3860)
  431. *
  432. * @param int $user_id
  433. * @uses bbp_get_user_id() to verify the user ID
  434. * @uses bbp_is_user_inactive() to check if user is inactive
  435. * @uses user_can() to check if user has special capabilities
  436. * @uses apply_filters() Calls 'bbp_get_user_display_role' with the
  437. * display role, user id, and user role
  438. * @return string
  439. */
  440. function bbp_get_user_display_role( $user_id = 0 ) {
  441. // Validate user id
  442. $user_id = bbp_get_user_id( $user_id );
  443. // User is not registered
  444. if ( empty( $user_id ) ) {
  445. $role = __( 'Guest', 'bbpress' );
  446. // User is not active
  447. } elseif ( bbp_is_user_inactive( $user_id ) ) {
  448. $role = __( 'Inactive', 'bbpress' );
  449. // User have a role
  450. } else {
  451. $role_id = bbp_get_user_role( $user_id );
  452. $role = bbp_get_dynamic_role_name( $role_id );
  453. }
  454. // No role found so default to generic "Member"
  455. if ( empty( $role ) ) {
  456. $role = __( 'Member', 'bbpress' );
  457. }
  458. return apply_filters( 'bbp_get_user_display_role', $role, $user_id );
  459. }
  460. /**
  461. * Output the link to the admin section
  462. *
  463. * @since bbPress (r2827)
  464. *
  465. * @param mixed $args Optional. See {@link bbp_get_admin_link()}
  466. * @uses bbp_get_admin_link() To get the admin link
  467. */
  468. function bbp_admin_link( $args = '' ) {
  469. echo bbp_get_admin_link( $args );
  470. }
  471. /**
  472. * Return the link to the admin section
  473. *
  474. * @since bbPress (r2827)
  475. *
  476. * @param mixed $args Optional. This function supports these arguments:
  477. * - text: The text
  478. * - before: Before the lnk
  479. * - after: After the link
  480. * @uses current_user_can() To check if the current user can moderate
  481. * @uses admin_url() To get the admin url
  482. * @uses apply_filters() Calls 'bbp_get_admin_link' with the link & args
  483. * @return The link
  484. */
  485. function bbp_get_admin_link( $args = '' ) {
  486. if ( !current_user_can( 'moderate' ) )
  487. return;
  488. if ( !empty( $args ) && is_string( $args ) && ( false === strpos( $args, '=' ) ) )
  489. $args = array( 'text' => $args );
  490. // Parse arguments against default values
  491. $r = bbp_parse_args( $args, array(
  492. 'text' => __( 'Admin', 'bbpress' ),
  493. 'before' => '',
  494. 'after' => ''
  495. ), 'get_admin_link' );
  496. $retval = $r['before'] . '<a href="' . esc_url( admin_url() ) . '">' . $r['text'] . '</a>' . $r['after'];
  497. return apply_filters( 'bbp_get_admin_link', $retval, $r );
  498. }
  499. /** User IP *******************************************************************/
  500. /**
  501. * Output the author IP address of a post
  502. *
  503. * @since bbPress (r3120)
  504. *
  505. * @param mixed $args Optional. If it is an integer, it is used as post id.
  506. * @uses bbp_get_author_ip() To get the post author link
  507. */
  508. function bbp_author_ip( $args = '' ) {
  509. echo bbp_get_author_ip( $args );
  510. }
  511. /**
  512. * Return the author IP address of a post
  513. *
  514. * @since bbPress (r3120)
  515. *
  516. * @param mixed $args Optional. If an integer, it is used as reply id.
  517. * @uses get_post_meta() To check if it's a topic page
  518. * @return string Author link of reply
  519. */
  520. function bbp_get_author_ip( $args = '' ) {
  521. // Used as post id
  522. $post_id = is_numeric( $args ) ? (int) $args : 0;
  523. // Parse arguments against default values
  524. $r = bbp_parse_args( $args, array(
  525. 'post_id' => $post_id,
  526. 'before' => '<span class="bbp-author-ip">(',
  527. 'after' => ')</span>'
  528. ), 'get_author_ip' );
  529. // Get the author IP meta value
  530. $author_ip = get_post_meta( $r['post_id'], '_bbp_author_ip', true );
  531. if ( !empty( $author_ip ) ) {
  532. $author_ip = $r['before'] . $author_ip . $r['after'];
  533. // No IP address
  534. } else {
  535. $author_ip = '';
  536. }
  537. return apply_filters( 'bbp_get_author_ip', $author_ip, $r );
  538. }
  539. /** Anonymous Fields **********************************************************/
  540. /**
  541. * Output the author disylay-name of a topic or reply.
  542. *
  543. * Convenience function to ensure proper template functions are called
  544. * and correct filters are executed. Used primarily to display topic
  545. * and reply author information in the anonymous form template-part.
  546. *
  547. * @since bbPress (r5119)
  548. *
  549. * @param int $post_id
  550. * @uses bbp_get_author_display_name() to get the author name
  551. */
  552. function bbp_author_display_name( $post_id = 0 ) {
  553. echo bbp_get_author_display_name( $post_id );
  554. }
  555. /**
  556. * Return the author name of a topic or reply.
  557. *
  558. * Convenience function to ensure proper template functions are called
  559. * and correct filters are executed. Used primarily to display topic
  560. * and reply author information in the anonymous form template-part.
  561. *
  562. * @since bbPress (r5119)
  563. *
  564. * @param int $post_id
  565. *
  566. * @uses bbp_is_topic_edit()
  567. * @uses bbp_get_topic_author_display_name()
  568. * @uses bbp_is_reply_edit()
  569. * @uses bbp_get_reply_author_display_name()
  570. * @uses bbp_current_anonymous_user_data()
  571. *
  572. * @return string The name of the author
  573. */
  574. function bbp_get_author_display_name( $post_id = 0 ) {
  575. // Define local variable(s)
  576. $retval = '';
  577. // Topic edit
  578. if ( bbp_is_topic_edit() ) {
  579. $retval = bbp_get_topic_author_display_name( $post_id );
  580. // Reply edit
  581. } elseif ( bbp_is_reply_edit() ) {
  582. $retval = bbp_get_reply_author_display_name( $post_id );
  583. // Not an edit, so rely on current user cookie data
  584. } else {
  585. $retval = bbp_current_anonymous_user_data( 'name' );
  586. }
  587. return apply_filters( 'bbp_get_author_display_name', $retval, $post_id );
  588. }
  589. /**
  590. * Output the author email of a topic or reply.
  591. *
  592. * Convenience function to ensure proper template functions are called
  593. * and correct filters are executed. Used primarily to display topic
  594. * and reply author information in the anonymous user form template-part.
  595. *
  596. * @since bbPress (r5119)
  597. *
  598. * @param int $post_id
  599. * @uses bbp_get_author_email() to get the author email
  600. */
  601. function bbp_author_email( $post_id = 0 ) {
  602. echo bbp_get_author_email( $post_id );
  603. }
  604. /**
  605. * Return the author email of a topic or reply.
  606. *
  607. * Convenience function to ensure proper template functions are called
  608. * and correct filters are executed. Used primarily to display topic
  609. * and reply author information in the anonymous user form template-part.
  610. *
  611. * @since bbPress (r5119)
  612. *
  613. * @param int $post_id
  614. *
  615. * @uses bbp_is_topic_edit()
  616. * @uses bbp_get_topic_author_email()
  617. * @uses bbp_is_reply_edit()
  618. * @uses bbp_get_reply_author_email()
  619. * @uses bbp_current_anonymous_user_data()
  620. *
  621. * @return string The email of the author
  622. */
  623. function bbp_get_author_email( $post_id = 0 ) {
  624. // Define local variable(s)
  625. $retval = '';
  626. // Topic edit
  627. if ( bbp_is_topic_edit() ) {
  628. $retval = bbp_get_topic_author_email( $post_id );
  629. // Reply edit
  630. } elseif ( bbp_is_reply_edit() ) {
  631. $retval = bbp_get_reply_author_email( $post_id );
  632. // Not an edit, so rely on current user cookie data
  633. } else {
  634. $retval = bbp_current_anonymous_user_data( 'email' );
  635. }
  636. return apply_filters( 'bbp_get_author_email', $retval, $post_id );
  637. }
  638. /**
  639. * Output the author url of a topic or reply.
  640. *
  641. * Convenience function to ensure proper template functions are called
  642. * and correct filters are executed. Used primarily to display topic
  643. * and reply author information in the anonymous user form template-part.
  644. *
  645. * @since bbPress (r5119)
  646. *
  647. * @param int $post_id
  648. * @uses bbp_get_author_url() to get the author url
  649. */
  650. function bbp_author_url( $post_id = 0 ) {
  651. echo bbp_get_author_url( $post_id );
  652. }
  653. /**
  654. * Return the author url of a topic or reply.
  655. *
  656. * Convenience function to ensure proper template functions are called
  657. * and correct filters are executed. Used primarily to display topic
  658. * and reply author information in the anonymous user form template-part.
  659. *
  660. * @since bbPress (r5119)
  661. *
  662. * @param int $post_id
  663. *
  664. * @uses bbp_is_topic_edit()
  665. * @uses bbp_get_topic_author_url()
  666. * @uses bbp_is_reply_edit()
  667. * @uses bbp_get_reply_author_url()
  668. * @uses bbp_current_anonymous_user_data()
  669. *
  670. * @return string The url of the author
  671. */
  672. function bbp_get_author_url( $post_id = 0 ) {
  673. // Define local variable(s)
  674. $retval = '';
  675. // Topic edit
  676. if ( bbp_is_topic_edit() ) {
  677. $retval = bbp_get_topic_author_url( $post_id );
  678. // Reply edit
  679. } elseif ( bbp_is_reply_edit() ) {
  680. $retval = bbp_get_reply_author_url( $post_id );
  681. // Not an edit, so rely on current user cookie data
  682. } else {
  683. $retval = bbp_current_anonymous_user_data( 'url' );
  684. }
  685. return apply_filters( 'bbp_get_author_url', $retval, $post_id );
  686. }
  687. /** Favorites *****************************************************************/
  688. /**
  689. * Output the link to the user's favorites page (profile page)
  690. *
  691. * @since bbPress (r2652)
  692. *
  693. * @param int $user_id Optional. User id
  694. * @uses bbp_get_favorites_permalink() To get the favorites permalink
  695. */
  696. function bbp_favorites_permalink( $user_id = 0 ) {
  697. echo esc_url( bbp_get_favorites_permalink( $user_id ) );
  698. }
  699. /**
  700. * Return the link to the user's favorites page (profile page)
  701. *
  702. * @since bbPress (r2652)
  703. *
  704. * @param int $user_id Optional. User id
  705. * @uses bbp_get_user_profile_url() To get the user profile url
  706. * @uses apply_filters() Calls 'bbp_get_favorites_permalink' with the
  707. * user profile url and user id
  708. * @return string Permanent link to user profile page
  709. */
  710. function bbp_get_favorites_permalink( $user_id = 0 ) {
  711. global $wp_rewrite;
  712. // Use displayed user ID if there is one, and one isn't requested
  713. $user_id = bbp_get_user_id( $user_id );
  714. if ( empty( $user_id ) )
  715. return false;
  716. // Allow early overriding of the profile URL to cut down on processing
  717. $early_profile_url = apply_filters( 'bbp_pre_get_favorites_permalink', (int) $user_id );
  718. if ( is_string( $early_profile_url ) )
  719. return $early_profile_url;
  720. // Pretty permalinks
  721. if ( $wp_rewrite->using_permalinks() ) {
  722. $url = $wp_rewrite->root . bbp_get_user_slug() . '/%' . bbp_get_user_rewrite_id() . '%/%' . bbp_get_user_favorites_rewrite_id() . '%';
  723. $user = get_userdata( $user_id );
  724. if ( ! empty( $user->user_nicename ) ) {
  725. $user_nicename = $user->user_nicename;
  726. } else {
  727. $user_nicename = $user->user_login;
  728. }
  729. $url = str_replace( '%' . bbp_get_user_rewrite_id() . '%', $user_nicename, $url );
  730. $url = str_replace( '%' . bbp_get_user_favorites_rewrite_id() . '%', bbp_get_user_favorites_slug(), $url );
  731. $url = home_url( user_trailingslashit( $url ) );
  732. // Unpretty permalinks
  733. } else {
  734. $url = add_query_arg( array(
  735. bbp_get_user_rewrite_id() => $user_id,
  736. bbp_get_user_favorites_rewrite_id() => bbp_get_user_favorites_slug(),
  737. ), home_url( '/' ) );
  738. }
  739. return apply_filters( 'bbp_get_favorites_permalink', $url, $user_id );
  740. }
  741. /**
  742. * Output the link to make a topic favorite/remove a topic from favorites
  743. *
  744. * @since bbPress (r2652)
  745. *
  746. * @param mixed $args See {@link bbp_get_user_favorites_link()}
  747. * @param int $user_id Optional. User id
  748. * @param bool $wrap Optional. If you want to wrap the link in <span id="favorite-toggle">.
  749. * @uses bbp_get_user_favorites_link() To get the user favorites link
  750. */
  751. function bbp_user_favorites_link( $args = array(), $user_id = 0, $wrap = true ) {
  752. echo bbp_get_user_favorites_link( $args, $user_id, $wrap );
  753. }
  754. /**
  755. * User favorites link
  756. *
  757. * Return the link to make a topic favorite/remove a topic from
  758. * favorites
  759. *
  760. * @since bbPress (r2652)
  761. *
  762. * @param mixed $args This function supports these arguments:
  763. * - subscribe: Favorite text
  764. * - unsubscribe: Unfavorite text
  765. * - user_id: User id
  766. * - topic_id: Topic id
  767. * - before: Before the link
  768. * - after: After the link
  769. * @param int $user_id Optional. User id
  770. * @param int $topic_id Optional. Topic id
  771. * @param bool $wrap Optional. If you want to wrap the link in <span id="favorite-toggle">. See ajax_favorite()
  772. * @uses bbp_get_user_id() To get the user id
  773. * @uses current_user_can() If the current user can edit the user
  774. * @uses bbp_get_topic_id() To get the topic id
  775. * @uses bbp_is_user_favorite() To check if the topic is user's favorite
  776. * @uses bbp_get_favorites_permalink() To get the favorites permalink
  777. * @uses bbp_get_topic_permalink() To get the topic permalink
  778. * @uses bbp_is_favorites() Is it the favorites page?
  779. * @uses apply_filters() Calls 'bbp_get_user_favorites_link' with the
  780. * html, add args, remove args, user & topic id
  781. * @return string User favorites link
  782. */
  783. function bbp_get_user_favorites_link( $args = '', $user_id = 0, $wrap = true ) {
  784. if ( ! bbp_is_favorites_active() ) {
  785. return false;
  786. }
  787. // Parse arguments against default values
  788. $r = bbp_parse_args( $args, array(
  789. 'favorite' => __( 'Favorite', 'bbpress' ),
  790. 'favorited' => __( 'Favorited', 'bbpress' ),
  791. 'user_id' => 0,
  792. 'topic_id' => 0,
  793. 'before' => '',
  794. 'after' => ''
  795. ), 'get_user_favorites_link' );
  796. // Validate user and topic ID's
  797. $user_id = bbp_get_user_id( $r['user_id'], true, true );
  798. $topic_id = bbp_get_topic_id( $r['topic_id'] );
  799. if ( empty( $user_id ) || empty( $topic_id ) ) {
  800. return false;
  801. }
  802. // No link if you can't edit yourself
  803. if ( ! current_user_can( 'edit_user', (int) $user_id ) ) {
  804. return false;
  805. }
  806. // Decide which link to show
  807. $is_fav = bbp_is_user_favorite( $user_id, $topic_id );
  808. if ( ! empty( $is_fav ) ) {
  809. $text = $r['favorited'];
  810. $query_args = array( 'action' => 'bbp_favorite_remove', 'topic_id' => $topic_id );
  811. } else {
  812. $text = $r['favorite'];
  813. $query_args = array( 'action' => 'bbp_favorite_add', 'topic_id' => $topic_id );
  814. }
  815. // Create the link based where the user is and if the topic is
  816. // already the user's favorite
  817. if ( bbp_is_favorites() ) {
  818. $permalink = bbp_get_favorites_permalink( $user_id );
  819. } elseif ( bbp_is_single_topic() || bbp_is_single_reply() ) {
  820. $permalink = bbp_get_topic_permalink( $topic_id );
  821. } else {
  822. $permalink = get_permalink();
  823. }
  824. $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-favorite_' . $topic_id ) );
  825. $sub = $is_fav ? ' class="is-favorite"' : '';
  826. $html = sprintf( '%s<span id="favorite-%d" %s><a href="%s" class="favorite-toggle" data-topic="%d">%s</a></span>%s', $r['before'], $topic_id, $sub, $url, $topic_id, $text, $r['after'] );
  827. // Initial output is wrapped in a span, ajax output is hooked to this
  828. if ( ! empty( $wrap ) ) {
  829. $html = '<span id="favorite-toggle">' . $html . '</span>';
  830. }
  831. // Return the link
  832. return apply_filters( 'bbp_get_user_favorites_link', $html, $r, $user_id, $topic_id );
  833. }
  834. /** Subscriptions *************************************************************/
  835. /**
  836. * Output the link to the user's subscriptions page (profile page)
  837. *
  838. * @since bbPress (r2688)
  839. *
  840. * @param int $user_id Optional. User id
  841. * @uses bbp_get_subscriptions_permalink() To get the subscriptions link
  842. */
  843. function bbp_subscriptions_permalink( $user_id = 0 ) {
  844. echo esc_url( bbp_get_subscriptions_permalink( $user_id ) );
  845. }
  846. /**
  847. * Return the link to the user's subscriptions page (profile page)
  848. *
  849. * @since bbPress (r2688)
  850. *
  851. * @param int $user_id Optional. User id
  852. * @uses bbp_get_user_profile_url() To get the user profile url
  853. * @uses apply_filters() Calls 'bbp_get_subscriptions_permalink' with
  854. * the user profile url and user id
  855. * @return string Permanent link to user subscriptions page
  856. */
  857. function bbp_get_subscriptions_permalink( $user_id = 0 ) {
  858. global $wp_rewrite;
  859. // Use displayed user ID if there is one, and one isn't requested
  860. $user_id = bbp_get_user_id( $user_id );
  861. if ( empty( $user_id ) )
  862. return false;
  863. // Allow early overriding of the profile URL to cut down on processing
  864. $early_profile_url = apply_filters( 'bbp_pre_get_subscriptions_permalink', (int) $user_id );
  865. if ( is_string( $early_profile_url ) )
  866. return $early_profile_url;
  867. // Pretty permalinks
  868. if ( $wp_rewrite->using_permalinks() ) {
  869. $url = $wp_rewrite->root . bbp_get_user_slug() . '/%' . bbp_get_user_rewrite_id() . '%/%' . bbp_get_user_subscriptions_rewrite_id() . '%';
  870. $user = get_userdata( $user_id );
  871. if ( ! empty( $user->user_nicename ) ) {
  872. $user_nicename = $user->user_nicename;
  873. } else {
  874. $user_nicename = $user->user_login;
  875. }
  876. $url = str_replace( '%' . bbp_get_user_rewrite_id() . '%', $user_nicename, $url );
  877. $url = str_replace( '%' . bbp_get_user_subscriptions_rewrite_id() . '%', bbp_get_user_subscriptions_slug(), $url );
  878. $url = home_url( user_trailingslashit( $url ) );
  879. // Unpretty permalinks
  880. } else {
  881. $url = add_query_arg( array(
  882. bbp_get_user_rewrite_id() => $user_id,
  883. bbp_get_user_subscriptions_rewrite_id() => bbp_get_user_subscriptions_slug(),
  884. ), home_url( '/' ) );
  885. }
  886. return apply_filters( 'bbp_get_subscriptions_permalink', $url, $user_id );
  887. }
  888. /**
  889. * Output the link to subscribe/unsubscribe from a topic
  890. *
  891. * @since bbPress (r2668)
  892. *
  893. * @param mixed $args See {@link bbp_get_user_subscribe_link()}
  894. * @param int $user_id Optional. User id
  895. * @param bool $wrap Optional. If you want to wrap the link in <span id="subscription-toggle">.
  896. * @uses bbp_get_user_subscribe_link() To get the subscribe link
  897. */
  898. function bbp_user_subscribe_link( $args = '', $user_id = 0, $wrap = true ) {
  899. echo bbp_get_user_subscribe_link( $args, $user_id, $wrap );
  900. }
  901. /**
  902. * Return the link to subscribe/unsubscribe from a forum or topic
  903. *
  904. * @since bbPress (r2668)
  905. *
  906. * @param mixed $args This function supports these arguments:
  907. * - subscribe: Subscribe text
  908. * - unsubscribe: Unsubscribe text
  909. * - user_id: User id
  910. * - topic_id: Topic id
  911. * - forum_id: Forum id
  912. * - before: Before the link
  913. * - after: After the link
  914. * @param int $user_id Optional. User id
  915. * @param bool $wrap Optional. If you want to wrap the link in <span id="subscription-toggle">.
  916. * @uses bbp_is_subscriptions_active() to check if subscriptions are active
  917. * @uses bbp_get_user_id() To get the user id
  918. * @uses bbp_get_user_id() To get the user id
  919. * @uses bbp_get_topic_id() To get the topic id
  920. * @uses bbp_get_forum_id() To get the forum id
  921. * @uses current_user_can() To check if the current user can edit user
  922. * @uses bbp_is_user_subscribed_to_forum() To check if the user is subscribed to the forum
  923. * @uses bbp_is_user_subscribed_to_topic() To check if the user is subscribed to the topic
  924. * @uses bbp_is_subscriptions() To check if it's the subscriptions page
  925. * @uses bbp_get_subscriptions_permalink() To get subscriptions link
  926. * @uses bbp_get_topic_permalink() To get topic link
  927. * @uses apply_filters() Calls 'bbp_get_user_subscribe_link' with the
  928. * link, args, user id & topic id
  929. * @return string Permanent link to topic
  930. */
  931. function bbp_get_user_subscribe_link( $args = '', $user_id = 0, $wrap = true ) {
  932. if ( ! bbp_is_subscriptions_active() ) {
  933. return;
  934. }
  935. // Parse arguments against default values
  936. $r = bbp_parse_args( $args, array(
  937. 'subscribe' => __( 'Subscribe', 'bbpress' ),
  938. 'unsubscribe' => __( 'Unsubscribe', 'bbpress' ),
  939. 'user_id' => 0,
  940. 'topic_id' => 0,
  941. 'forum_id' => 0,
  942. 'before' => '&nbsp;|&nbsp;',
  943. 'after' => ''
  944. ), 'get_user_subscribe_link' );
  945. // Validate user and object ID's
  946. $user_id = bbp_get_user_id( $r['user_id'], true, true );
  947. $topic_id = bbp_get_topic_id( $r['topic_id'] );
  948. $forum_id = bbp_get_forum_id( $r['forum_id'] );
  949. if ( empty( $user_id ) || ( empty( $topic_id ) && empty( $forum_id ) ) ) {
  950. return false;
  951. }
  952. // No link if you can't edit yourself
  953. if ( ! current_user_can( 'edit_user', (int) $user_id ) ) {
  954. return false;
  955. }
  956. // Check if viewing a single forum
  957. if ( empty( $topic_id ) && ! empty( $forum_id ) ) {
  958. // Decide which link to show
  959. $is_subscribed = bbp_is_user_subscribed_to_forum( $user_id, $forum_id );
  960. if ( ! empty( $is_subscribed ) ) {
  961. $text = $r['unsubscribe'];
  962. $query_args = array( 'action' => 'bbp_unsubscribe', 'forum_id' => $forum_id );
  963. } else {
  964. $text = $r['subscribe'];
  965. $query_args = array( 'action' => 'bbp_subscribe', 'forum_id' => $forum_id );
  966. }
  967. // Create the link based where the user is and if the user is
  968. // subscribed already
  969. if ( bbp_is_subscriptions() ) {
  970. $permalink = bbp_get_subscriptions_permalink( $user_id );
  971. } elseif ( bbp_is_single_forum() || bbp_is_single_reply() ) {
  972. $permalink = bbp_get_forum_permalink( $forum_id );
  973. } else {
  974. $permalink = get_permalink();
  975. }
  976. $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $forum_id ) );
  977. $sub = $is_subscribed ? ' class="is-subscribed"' : '';
  978. $html = sprintf( '%s<span id="subscribe-%d" %s><a href="%s" class="subscription-toggle" data-forum="%d">%s</a></span>%s', $r['before'], $forum_id, $sub, $url, $forum_id, $text, $r['after'] );
  979. // Initial output is wrapped in a span, ajax output is hooked to this
  980. if ( !empty( $wrap ) ) {
  981. $html = '<span id="subscription-toggle">' . $html . '</span>';
  982. }
  983. } else {
  984. // Decide which link to show
  985. $is_subscribed = bbp_is_user_subscribed_to_topic( $user_id, $topic_id );
  986. if ( ! empty( $is_subscribed ) ) {
  987. $text = $r['unsubscribe'];
  988. $query_args = array( 'action' => 'bbp_unsubscribe', 'topic_id' => $topic_id );
  989. } else {
  990. $text = $r['subscribe'];
  991. $query_args = array( 'action' => 'bbp_subscribe', 'topic_id' => $topic_id );
  992. }
  993. // Create the link based where the user is and if the user is
  994. // subscribed already
  995. if ( bbp_is_subscriptions() ) {
  996. $permalink = bbp_get_subscriptions_permalink( $user_id );
  997. } elseif ( bbp_is_single_topic() || bbp_is_single_reply() ) {
  998. $permalink = bbp_get_topic_permalink( $topic_id );
  999. } else {
  1000. $permalink = get_permalink();
  1001. }
  1002. $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $topic_id ) );
  1003. $sub = $is_subscribed ? ' class="is-subscribed"' : '';
  1004. $html = sprintf( '%s<span id="subscribe-%d" %s><a href="%s" class="subscription-toggle" data-topic="%d">%s</a></span>%s', $r['before'], $topic_id, $sub, $url, $topic_id, $text, $r['after'] );
  1005. // Initial output is wrapped in a span, ajax output is hooked to this
  1006. if ( !empty( $wrap ) ) {
  1007. $html = '<span id="subscription-toggle">' . $html . '</span>';
  1008. }
  1009. }
  1010. // Return the link
  1011. return apply_filters( 'bbp_get_user_subscribe_link', $html, $r, $user_id, $topic_id );
  1012. }
  1013. /** Edit User *****************************************************************/
  1014. /**
  1015. * Edit profile success message
  1016. *
  1017. * @since bbPress (r2688)
  1018. *
  1019. * @uses bbp_is_single_user() To check if it's the profile page
  1020. * @uses bbp_is_single_user_edit() To check if it's the profile edit page
  1021. */
  1022. function bbp_notice_edit_user_success() {
  1023. if ( isset( $_GET['updated'] ) && ( bbp_is_single_user() || bbp_is_single_user_edit() ) ) : ?>
  1024. <div class="bbp-template-notice updated">
  1025. <p><?php esc_html_e( 'User updated.', 'bbpress' ); ?></p>
  1026. </div>
  1027. <?php endif;
  1028. }
  1029. /**
  1030. * Super admin privileges notice
  1031. *
  1032. * @since bbPress (r2688)
  1033. *
  1034. * @uses is_multisite() To check if the blog is multisite
  1035. * @uses bbp_is_single_user() To check if it's the profile page
  1036. * @uses bbp_is_single_user_edit() To check if it's the profile edit page
  1037. * @uses current_user_can() To check if the current user can manage network
  1038. * options
  1039. * @uses bbp_get_displayed_user_id() To get the displayed user id
  1040. * @uses is_super_admin() To check if the user is super admin
  1041. * @uses bbp_is_user_home() To check if it's the user home
  1042. * @uses bbp_is_user_home_edit() To check if it's the user home edit
  1043. */
  1044. function bbp_notice_edit_user_is_super_admin() {
  1045. if ( is_multisite() && ( bbp_is_single_user() || bbp_is_single_user_edit() ) && current_user_can( 'manage_network_options' ) && is_super_admin( bbp_get_displayed_user_id() ) ) : ?>
  1046. <div class="bbp-template-notice important">
  1047. <p><?php bbp_is_user_home() || bbp_is_user_home_edit() ? esc_html_e( 'You have super admin privileges.', 'bbpress' ) : esc_html_e( 'This user has super admin privileges.', 'bbpress' ); ?></p>
  1048. </div>
  1049. <?php endif;
  1050. }
  1051. /**
  1052. * Drop down for selecting the user's display name
  1053. *
  1054. * @since bbPress (r2688)
  1055. */
  1056. function bbp_edit_user_display_name() {
  1057. $bbp = bbpress();
  1058. $public_display = array();
  1059. $public_display['display_username'] = $bbp->displayed_user->user_login;
  1060. if ( !empty( $bbp->displayed_user->nickname ) )
  1061. $public_display['display_nickname'] = $bbp->displayed_user->nickname;
  1062. if ( !empty( $bbp->displayed_user->first_name ) )
  1063. $public_display['display_firstname'] = $bbp->displayed_user->first_name;
  1064. if ( !empty( $bbp->displayed_user->last_name ) )
  1065. $public_display['display_lastname'] = $bbp->displayed_user->last_name;
  1066. if ( !empty( $bbp->displayed_user->first_name ) && !empty( $bbp->displayed_user->last_name ) ) {
  1067. $public_display['display_firstlast'] = $bbp->displayed_user->first_name . ' ' . $bbp->displayed_user->last_name;
  1068. $public_display['display_lastfirst'] = $bbp->displayed_user->last_name . ' ' . $bbp->displayed_user->first_name;
  1069. }
  1070. if ( !in_array( $bbp->displayed_user->display_name, $public_display ) ) // Only add this if it isn't duplicated elsewhere
  1071. $public_display = array( 'display_displayname' => $bbp->displayed_user->display_name ) + $public_display;
  1072. $public_display = array_map( 'trim', $public_display );
  1073. $public_display = array_unique( $public_display ); ?>
  1074. <select name="display_name" id="display_name">
  1075. <?php foreach ( $public_display as $id => $item ) : ?>
  1076. <option id="<?php echo $id; ?>" value="<?php echo esc_attr( $item ); ?>"<?php selected( $bbp->displayed_user->display_name, $item ); ?>><?php echo $item; ?></option>
  1077. <?php endforeach; ?>
  1078. </select>
  1079. <?php
  1080. }
  1081. /**
  1082. * Output blog role selector (for user edit)
  1083. *
  1084. * @since bbPress (r2688)
  1085. */
  1086. function bbp_edit_user_blog_role() {
  1087. // Return if no user is being edited
  1088. if ( ! bbp_is_single_user_edit() )
  1089. return;
  1090. // Get users current blog role
  1091. $user_role = bbp_get_user_blog_role( bbp_get_displayed_user_id() );
  1092. // Get the blog roles
  1093. $blog_roles = bbp_get_blog_roles(); ?>
  1094. <select name="role" id="role">
  1095. <option value=""><?php esc_html_e( '&mdash; No role for this site &mdash;', 'bbpress' ); ?></option>
  1096. <?php foreach ( $blog_roles as $role => $details ) : ?>
  1097. <option <?php selected( $user_role, $role ); ?> value="<?php echo esc_attr( $role ); ?>"><?php echo translate_user_role( $details['name'] ); ?></option>
  1098. <?php endforeach; ?>
  1099. </select>
  1100. <?php
  1101. }
  1102. /**
  1103. * Output forum role selector (for user edit)
  1104. *
  1105. * @since bbPress (r4284)
  1106. */
  1107. function bbp_edit_user_forums_role() {
  1108. // Return if no user is being edited
  1109. if ( ! bbp_is_single_user_edit() )
  1110. return;
  1111. // Get the user's current forum role
  1112. $user_role = bbp_get_user_role( bbp_get_displayed_user_id() );
  1113. // Get the folum roles
  1114. $dynamic_roles = bbp_get_dynamic_roles();
  1115. // Only keymasters can set other keymasters
  1116. if ( ! bbp_is_user_keymaster() )
  1117. unset( $dynamic_roles[ bbp_get_keymaster_role() ] ); ?>
  1118. <select name="bbp-forums-role" id="bbp-forums-role">
  1119. <option value=""><?php esc_html_e( '&mdash; No role for these forums &mdash;', 'bbpress' ); ?></option>
  1120. <?php foreach ( $dynamic_roles as $role => $details ) : ?>
  1121. <option <?php selected( $user_role, $role ); ?> value="<?php echo esc_attr( $role ); ?>"><?php echo translate_user_role( $details['name'] ); ?></option>
  1122. <?php endforeach; ?>
  1123. </select>
  1124. <?php
  1125. }
  1126. /**
  1127. * Return user contact methods Selectbox
  1128. *
  1129. * @since bbPress (r2688)
  1130. *
  1131. * @uses _wp_get_user_contactmethods() To get the contact methods
  1132. * @uses apply_filters() Calls 'bbp_edit_user_contact_methods' with the methods
  1133. * @return string User contact methods
  1134. */
  1135. function bbp_edit_user_contact_methods() {
  1136. // Get the core WordPress contact methods
  1137. $contact_methods = _wp_get_user_contactmethods( bbpress()->displayed_user );
  1138. return apply_filters( 'bbp_edit_user_contact_methods', $contact_methods );
  1139. }
  1140. /** Topics Created ************************************************************/
  1141. /**
  1142. * Output the link to the user's topics
  1143. *
  1144. * @since bbPress (r4225)
  1145. *
  1146. * @param int $user_id Optional. User id
  1147. * @uses bbp_get_favorites_permalink() To get the favorites permalink
  1148. */
  1149. function bbp_user_topics_created_url( $user_id = 0 ) {
  1150. echo esc_url( bbp_get_user_topics_created_url( $user_id ) );
  1151. }
  1152. /**
  1153. * Return the link to the user's topics
  1154. *
  1155. * @since bbPress (r4225)
  1156. *
  1157. * @param int $user_id Optional. User id
  1158. * @uses bbp_get_user_profile_url() To get the user profile url
  1159. * @uses apply_filters() Calls 'bbp_get_favorites_permalink' with the
  1160. * user profile url and user id
  1161. * @return string Permanent link to user profile page
  1162. */
  1163. function bbp_get_user_topics_created_url( $user_id = 0 ) {
  1164. global $wp_rewrite;
  1165. // Use displayed user ID if there is one, and one isn't requested
  1166. $user_id = bbp_get_user_id( $user_id );
  1167. if ( empty( $user_id ) )
  1168. return false;
  1169. // Allow early overriding of the profile URL to cut down on processing
  1170. $early_url = apply_filters( 'bbp_pre_get_user_topics_created_url', (int) $user_id );
  1171. if ( is_string( $early_url ) )
  1172. return $early_url;
  1173. // Pretty permalinks
  1174. if ( $wp_rewrite->using_permalinks() ) {
  1175. $url = $wp_rewrite->root . bbp_get_user_slug() . '/%' . bbp_get_user_rewrite_id() . '%/' . bbp_get_topic_archive_slug();
  1176. $user = get_userdata( $user_id );
  1177. if ( ! empty( $user->user_nicename ) ) {
  1178. $user_nicename = $user->user_nicename;
  1179. } else {
  1180. $user_nicename = $user->user_login;
  1181. }
  1182. $url = str_replace( '%' . bbp_get_user_rewrite_id() . '%', $user_nicename, $url );
  1183. $url = home_url( user_trailingslashit( $url ) );
  1184. // Unpretty permalinks
  1185. } else {
  1186. $url = add_query_arg( array(
  1187. bbp_get_user_rewrite_id() => $user_id,
  1188. bbp_get_user_topics_rewrite_id() => '1',
  1189. ), home_url( '/' ) );
  1190. }
  1191. return apply_filters( 'bbp_get_user_topics_created_url', $url, $user_id );
  1192. }
  1193. /** Topics Created ************************************************************/
  1194. /**
  1195. * Output the link to the user's replies
  1196. *
  1197. * @since bbPress (r4225)
  1198. *
  1199. * @param int $user_id Optional. User id
  1200. * @uses bbp_get_favorites_permalink() To get the favorites permalink
  1201. */
  1202. function bbp_user_replies_created_url( $user_id = 0 ) {
  1203. echo esc_url( bbp_get_user_replies_created_url( $user_id ) );
  1204. }
  1205. /**
  1206. * Return the link to the user's replies
  1207. *
  1208. * @since bbPress (r4225)
  1209. *
  1210. * @param int $user_id Optional. User id
  1211. * @uses bbp_get_user_profile_url() To get the user profile url
  1212. * @uses apply_filters() Calls 'bbp_get_favorites_permalink' with the
  1213. * user profile url and user id
  1214. * @return string Permanent link to user profile page
  1215. */
  1216. function bbp_get_user_replies_created_url( $user_id = 0 ) {
  1217. global $wp_rewrite;
  1218. // Use displayed user ID if there is one, and one isn't requested
  1219. $user_id = bbp_get_user_id( $user_id );
  1220. if ( empty( $user_id ) )
  1221. return false;
  1222. // Allow early overriding of the profile URL to cut down on processing
  1223. $early_url = apply_filters( 'bbp_pre_get_user_replies_created_url', (int) $user_id );
  1224. if ( is_string( $early_url ) )
  1225. return $early_url;
  1226. // Pretty permalinks
  1227. if ( $wp_rewrite->using_permalinks() ) {
  1228. $url = $wp_rewrite->root . bbp_get_user_slug() . '/%' . bbp_get_user_rewrite_id() . '%/' . bbp_get_reply_archive_slug();
  1229. $user = get_userdata( $user_id );
  1230. if ( ! empty( $user->user_nicename ) ) {
  1231. $user_nicename = $user->user_nicename;
  1232. } else {
  1233. $user_nicename = $user->user_login;
  1234. }
  1235. $url = str_replace( '%' . bbp_get_user_rewrite_id() . '%', $user_nicename, $url );
  1236. $url = home_url( user_trailingslashit( $url ) );
  1237. // Unpretty permalinks
  1238. } else {
  1239. $url = add_query_arg( array(
  1240. bbp_get_user_rewrite_id() => $user_id,
  1241. bbp_get_user_replies_rewrite_id() => '1',
  1242. ), home_url( '/' ) );
  1243. }
  1244. return apply_filters( 'bbp_get_user_replies_created_url', $url, $user_id );
  1245. }
  1246. /** Login *********************************************************************/
  1247. /**
  1248. * Handle the login and registration template notices
  1249. *
  1250. * @since bbPress (r2970)
  1251. *
  1252. * @uses WP_Error bbPress::errors::add() To add an error or message
  1253. */
  1254. function bbp_login_notices() {
  1255. // loggedout was passed
  1256. if ( !empty( $_GET['loggedout'] ) && ( true === $_GET['loggedout'] ) ) {
  1257. bbp_add_error( 'loggedout', __( 'You are now logged out.', 'bbpress' ), 'message' );
  1258. // registration is disabled
  1259. } elseif ( !empty( $_GET['registration'] ) && ( 'disabled' === $_GET['registration'] ) ) {
  1260. bbp_add_error( 'registerdisabled', __( 'New user registration is currently not allowed.', 'bbpress' ) );
  1261. // Prompt user to check their email
  1262. } elseif ( !empty( $_GET['checkemail'] ) && in_array( $_GET['checkemail'], array( 'confirm', 'newpass', 'registered' ) ) ) {
  1263. switch ( $_GET['checkemail'] ) {
  1264. // Email needs confirmation
  1265. case 'confirm' :
  1266. bbp_add_error( 'confirm', __( 'Check your e-mail for the confirmation link.', 'bbpress' ), 'message' );
  1267. break;
  1268. // User requested a new password
  1269. case 'newpass' :
  1270. bbp_add_error( 'newpass', __( 'Check your e-mail for your new password.', 'bbpress' ), 'message' );
  1271. break;
  1272. // User is newly registered
  1273. case 'registered' :
  1274. bbp_add_error( 'registered', __( 'Registration complete. Please check your e-mail.', 'bbpress' ), 'message' );
  1275. break;
  1276. }
  1277. }
  1278. }
  1279. /**
  1280. * Redirect a user back to their profile if they are already …

Large files files are truncated, but you can click here to view the full file