PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/forums/site/filters.php

https://gitlab.com/clusterpress/clusterpress-sites-forum
PHP | 737 lines | 360 code | 104 blank | 273 comment | 92 complexity | 13adf0279d3d3c8a64189491d8ef4cf2 MD5 | raw file
  1. <?php
  2. /**
  3. * Filters
  4. *
  5. * @since 1.0.0
  6. *
  7. * @package ClusterPress Sites Forum\forums\site
  8. * @subpackage filters
  9. */
  10. // Exit if accessed directly
  11. defined( 'ABSPATH' ) || exit;
  12. /**
  13. * Redirects the user to the Site's discovery page in case bbPress objects are linked to a site.
  14. *
  15. * @since 1.0.0
  16. *
  17. * @param string $url The redirect url.
  18. * @return string The edited redirect url.
  19. */
  20. function cpsf_site_redirect_canonical( $url = '' ) {
  21. // Viewing a single forum
  22. if ( bbp_is_single_forum() ) {
  23. $url = cpsf_get_site_forum_permalink( '', get_the_ID() );
  24. // Viewing a single topic
  25. } elseif ( bbp_is_single_topic() ) {
  26. $url = cpsf_get_site_topic_permalink( '', get_the_ID() );
  27. }
  28. return $url;
  29. }
  30. add_filter( 'cpsf_redirect_canonical', 'cpsf_site_redirect_canonical', 10, 1 );
  31. /**
  32. * Filters the displayed site's navigation to remove the forum nav if no forum are linked to the site
  33. *
  34. * @since 1.0.0
  35. *
  36. * @param array $nodes The list of the site's nav items.
  37. * @param WP_Site $site The Site object.
  38. * @return array The edited list of the site's nav items.
  39. */
  40. function cpsf_site_edit_toolbar( $nodes, $site = null ) {
  41. if ( empty( $site->blog_id ) ) {
  42. return;
  43. }
  44. // Get ClusterPress instance
  45. $cp = clusterpress();
  46. $forum_id = (int) cp_sites_get_meta( $site->blog_id, '_cpsf_forum_id', true );
  47. // Remove the Forum node if no forum is attached to the site
  48. if ( ! $forum_id ) {
  49. // Remove the node
  50. $cp->site->toolbar->remove_node( 'cp_site_forum' );
  51. // Make sure to get a 404 if the url is accessed directly
  52. unset( $nodes['cp_site_forum'] );
  53. // Else add the Forum ID to the Site's global
  54. } else {
  55. clusterpress()->cluster->displayed_object->forum_id = $forum_id;
  56. }
  57. clusterpress()->cluster->displayed_object->forum_parent_id = get_network_option( 0, '_clusterpress_sites_forum_parent_id', 0 );
  58. return $nodes;
  59. }
  60. add_filter( 'cp_site_cluster_get_toolbar_urls', 'cpsf_site_edit_toolbar', 10, 2 );
  61. /**
  62. * Get the permalink to a Site's forum
  63. *
  64. * @since 1.0.0
  65. *
  66. * @param string $permalink The permalink of the forum.
  67. * @param int $forum_id The forum ID.
  68. * @return string The permalink to the site's forum (if needed).
  69. */
  70. function cpsf_get_site_forum_permalink( $permalink = '', $forum_id = 0 ) {
  71. if ( empty( $forum_id ) ) {
  72. return $permalink;
  73. }
  74. // Then get the site_id
  75. $site_id = (int) get_post_meta( $forum_id, '_cpsf_site_id', true );
  76. if ( ! $site_id ) {
  77. return $permalink;
  78. }
  79. // Are we on a site ?
  80. $site = cp_displayed_site();
  81. // We are on site, but if the forum is not attached to it, reset the site
  82. if ( empty( $site->forum_id ) || (int) $site->forum_id !== (int) $forum_id ) {
  83. $site = null;
  84. }
  85. $forum_url = cp_site_get_url( array(
  86. 'rewrite_id' => 'cp_site_forum',
  87. 'slug' => cpsf_get_site_topics_archive_slug(),
  88. 'site_id' => $site_id,
  89. ), $site );
  90. if ( $forum_url ) {
  91. $old_permalink = $permalink;
  92. $permalink = $forum_url;
  93. }
  94. /**
  95. * Filter here to edit the site forum permalink.
  96. *
  97. * @since 1.0.0
  98. *
  99. * @param string $permalink The permalink of the forum.
  100. * @param string $old_permalink The original bbPress permalink of the forum.
  101. * @param int $forum_id The forum ID.
  102. * @param int $site_id The Site ID.
  103. */
  104. return apply_filters( 'cpsf_get_site_forum_permalink', $permalink, $old_permalink, $forum_id, $site_id );
  105. }
  106. add_filter( 'bbp_get_forum_permalink', 'cpsf_get_site_forum_permalink', 10, 2 );
  107. /**
  108. * Get the permalink of a topic belonging to a site's forum.
  109. *
  110. * @since 1.0.0
  111. *
  112. * @param string $permalink The permalink of the topic.
  113. * @param int $topic_id The topic ID.
  114. * @return string The permalink to the site's topic (if needed).
  115. */
  116. function cpsf_get_site_topic_permalink( $permalink = '', $topic_id = 0 ) {
  117. if ( empty( $topic_id ) ) {
  118. return $permalink;
  119. }
  120. // First get the forum id
  121. $forum_id = bbp_get_topic_forum_id( $topic_id );
  122. if ( ! $forum_id ) {
  123. return $permalink;
  124. }
  125. $forum_permalink = cpsf_get_site_forum_permalink( '', $forum_id );
  126. if ( ! $forum_permalink ) {
  127. return $permalink;
  128. }
  129. $topic_slug = get_post_field( 'post_name', $topic_id );
  130. $topic_status = get_post_status( $topic_id );
  131. $old_permalink = $permalink;
  132. if ( ! clusterpress()->permalink_structure ) {
  133. $permalink = esc_url_raw( add_query_arg( 'cpsf_topic', $topic_slug, $forum_permalink ) );
  134. } else {
  135. $permalink = trailingslashit( $forum_permalink ) . cpsf_get_site_forum_topic_slug() . '/' . trailingslashit( $topic_slug );
  136. }
  137. // Handle specific cases when a topic is trashed or spammed.
  138. if ( 'publish' !== $topic_status && ! empty( $_GET['action'] ) ) {
  139. if ( 'bbp_toggle_topic_trash' === $_GET['action'] ) {
  140. $reditect_args = array( 'updated' => 'site[forum-13]' );
  141. } elseif ( 'bbp_toggle_topic_spam' === $_GET['action'] ) {
  142. $reditect_args = array( 'updated' => 'site[forum-14]' );
  143. } elseif ( 'bbp_toggle_topic_close' === $_GET['action'] ) {
  144. $reditect_args = array( 'updated' => 'site[forum-15]' );
  145. } else {
  146. $reditect_args = array( 'error' => 'site[forum-16]' );
  147. }
  148. $permalink = esc_url_raw( add_query_arg( $reditect_args, $permalink ) );
  149. }
  150. /**
  151. * Filter here to edit the site topic permalink.
  152. *
  153. * @since 1.0.0
  154. *
  155. * @param string $permalink The permalink of the topic.
  156. * @param string $old_permalink The original bbPress permalink of the topic.
  157. * @param int $topic_id The Topic ID.
  158. * @param int $forum_id The forum ID.
  159. */
  160. return apply_filters( 'cpsf_get_site_topic_permalink', $permalink, $old_permalink, $topic_id, $forum_id );
  161. }
  162. add_filter( 'bbp_get_topic_permalink', 'cpsf_get_site_topic_permalink', 10, 2 );
  163. /**
  164. * Get the edit url of a site's topic.
  165. *
  166. * @since 1.0.0
  167. *
  168. * @param string $permalink The topic edit url.
  169. * @param int $topic_id The topic ID.
  170. * @return string The edit url of the site's topic (if needed).
  171. */
  172. function cpsf_get_site_topic_edit_url( $permalink = '', $topic_id = 0 ) {
  173. if ( empty( $topic_id ) || clusterpress()->permalink_structure ) {
  174. return $permalink;
  175. }
  176. $topic_link = cpsf_get_site_topic_permalink( '', $topic_id );
  177. if ( ! $topic_link ) {
  178. return $permalink;
  179. }
  180. $old_permalink = $permalink;
  181. $permalink = add_query_arg( 'cpsf_edit', 1, $topic_link );
  182. /**
  183. * Filter here to edit the site topic edit url.
  184. *
  185. * @since 1.0.0
  186. *
  187. * @param string $permalink The edit url of the topic.
  188. * @param string $old_permalink The original bbPress edit url of the topic.
  189. * @param int $topic_id The Topic ID.
  190. */
  191. return apply_filters( 'cpsf_get_site_topic_edit_url', $permalink, $old_permalink, $topic_id );
  192. }
  193. add_filter( 'bbp_get_topic_edit_url', 'cpsf_get_site_topic_edit_url', 10, 2 );
  194. /**
  195. * Get the permalink of a reply belonging to a site's forum.
  196. *
  197. * @since 1.0.0
  198. *
  199. * @param string $permalink The permalink of the reply.
  200. * @param int $reply_id The reply ID.
  201. * @return string The permalink to the site's reply (if needed).
  202. */
  203. function cpsf_get_site_reply_permalink( $permalink = '', $reply_id = 0 ) {
  204. if ( empty( $reply_id ) ) {
  205. return $permalink;
  206. }
  207. $forum_id = bbp_get_reply_forum_id( $reply_id );
  208. if ( ! $forum_id ) {
  209. return $permalink;
  210. }
  211. $forum_permalink = cpsf_get_site_forum_permalink( '', $forum_id );
  212. if ( ! $forum_permalink ) {
  213. return $permalink;
  214. }
  215. $old_permalink = $permalink;
  216. if ( ! clusterpress()->permalink_structure ) {
  217. $permalink = esc_url_raw( add_query_arg( 'cpsf_reply', $reply_id, $forum_permalink ) );
  218. } else {
  219. $permalink = trailingslashit( $forum_permalink ) . cpsf_get_site_forum_reply_slug() . '/' . trailingslashit( $reply_id );
  220. }
  221. /**
  222. * Filter here to edit the site topic reply url.
  223. *
  224. * @since 1.0.0
  225. *
  226. * @param string $permalink The permalink of the reply.
  227. * @param string $old_permalink The original bbPress permalink of the reply.
  228. * @param int $reply_id The Reply ID.
  229. * @param int $forum_id The forum ID.
  230. */
  231. return apply_filters( 'cpsf_get_site_reply_permalink', $permalink, $old_permalink, $reply_id, $forum_id );
  232. }
  233. add_filter( 'bbp_get_reply_permalink', 'cpsf_get_site_reply_permalink', 10, 2 );
  234. /**
  235. * Get the edit url of a site's reply.
  236. *
  237. * @since 1.0.0
  238. *
  239. * @param string $permalink The reply edit url.
  240. * @param int $reply_id The reply ID.
  241. * @return string The edit url of the site's reply (if needed).
  242. */
  243. function cpsf_get_site_reply_edit_url( $permalink = '', $reply_id = 0 ) {
  244. if ( empty( $reply_id ) || clusterpress()->permalink_structure ) {
  245. return $permalink;
  246. }
  247. $reply_link = cpsf_get_site_reply_permalink( '', $reply_id );
  248. if ( ! $reply_link ) {
  249. return $permalink;
  250. }
  251. $old_permalink = $permalink;
  252. $permalink = add_query_arg( 'cpsf_edit', 1, $reply_link );
  253. /**
  254. * Filter here to edit the site topic reply edit url.
  255. *
  256. * @since 1.0.0
  257. *
  258. * @param string $permalink The edit url of the reply.
  259. * @param string $old_permalink The original bbPress edit url of the reply.
  260. * @param int $reply_id The Reply ID.
  261. */
  262. return apply_filters( 'cpsf_get_site_reply_edit_url', $permalink, $old_permalink, $reply_id );
  263. }
  264. add_filter( 'bbp_get_reply_edit_url', 'cpsf_get_site_reply_edit_url', 10, 2 );
  265. /**
  266. * Neutralize the Super Stickies on sites.
  267. *
  268. * @since 1.0.0
  269. *
  270. * @param string $retval The Sticky links.
  271. * @return string The Sticky links.
  272. */
  273. function cpsf_get_topic_stick_link( $retval ) {
  274. if ( ! cp_is_site() ) {
  275. return $retval;
  276. }
  277. preg_match_all( '/<a\s[^>]*>(.*)<\/a>/siU', $retval, $as );
  278. if ( ! empty( $as[0][0] ) ) {
  279. $retval = $as[0][0];
  280. }
  281. return $retval;
  282. }
  283. add_filter( 'bbp_get_topic_stick_link', 'cpsf_get_topic_stick_link', 10, 1 );
  284. /**
  285. * Get the permalink of a topic tag belonging to a site's forum.
  286. *
  287. * @since 1.0.0
  288. *
  289. * @param string $tag_link The permalink of the topic tag.
  290. * @param WP_Term $tag The term object.
  291. * @param string $taxonomy The taxonomy ID.
  292. * @return string The permalink to the site's topic tag (if needed).
  293. */
  294. function cpsf_get_topic_tag_link( $tag_link = '', $tag = null, $taxonomy = '' ) {
  295. if ( empty( $tag->slug ) || empty( $taxonomy ) || bbp_get_topic_tag_tax_id() !== $taxonomy ) {
  296. return $tag_link;
  297. }
  298. $site = cp_displayed_site();
  299. if ( ! $site ) {
  300. return $tag_link;
  301. }
  302. $old_permalink = $tag_link;
  303. $forum_permalink = cp_site_get_url( array(
  304. 'rewrite_id' => 'cp_site_forum',
  305. 'slug' => cpsf_get_site_topics_archive_slug(),
  306. ), $site );
  307. if ( ! clusterpress()->permalink_structure ) {
  308. $permalink = esc_url_raw( add_query_arg( 'cpsf_topic_tag', $tag->slug, $forum_permalink ) );
  309. } else {
  310. $permalink = trailingslashit( $forum_permalink ) . cpsf_get_site_forum_tag_slug() . '/' . trailingslashit( $tag->slug );
  311. }
  312. return apply_filters( 'cpsf_get_topic_tag_link', $permalink, $old_permalink );
  313. }
  314. add_filter( 'term_link', 'cpsf_get_topic_tag_link', 10, 3 );
  315. /**
  316. * Makes sure the Topic Tags are pre populated the reply form.
  317. *
  318. * @since 1.0.0
  319. *
  320. * @param string $topic_tags The comma separated value of Tags.
  321. * @return string The comma separated value of Tags.
  322. */
  323. function cpsf_get_form_topic_tags( $topic_tags = '' ) {
  324. if ( ! empty( $topic_tags ) || ! cpsf_is_single_topic() ) {
  325. return $topic_tags;
  326. }
  327. $topic_id = bbp_get_topic_id();
  328. if ( empty( $topic_id ) ) {
  329. return $topic_tags;
  330. }
  331. // Topic is spammed so display pre-spam terms
  332. if ( bbp_is_topic_spam( $topic_id ) ) {
  333. // Get pre-spam terms
  334. $spam_terms = get_post_meta( $topic_id, '_bbp_spam_topic_tags', true );
  335. $topic_tags = ( ! empty( $spam_terms ) ) ? join( ', ', $spam_terms ) : '';
  336. // Topic is not spam so get real terms
  337. } else {
  338. $topic_tags = bbp_get_topic_tag_names( $topic_id );
  339. }
  340. /**
  341. * Filter here to edit the topic tags to output in the form.
  342. *
  343. * @since 1.0.0
  344. *
  345. * @param string $topic_tags The comma separated value of Tags.
  346. * @param int $topic_id The Topic ID.
  347. */
  348. return apply_filters( 'cpsf_get_form_topic_tags', $topic_tags, $topic_id );
  349. }
  350. add_filter( 'bbp_get_form_topic_tags', 'cpsf_get_form_topic_tags', 10, 1 );
  351. /**
  352. * Filters for the output contents.
  353. */
  354. add_filter( 'cpsf_site_forum_content', 'cpsf_kses' );
  355. add_filter( 'cpsf_site_forum_content', 'wp_unslash' );
  356. add_filter( 'cpsf_site_forum_content', 'wptexturize' );
  357. add_filter( 'cpsf_site_forum_content', 'convert_smilies', 20 );
  358. add_filter( 'cpsf_site_forum_content', 'wpautop' );
  359. add_filter( 'cpsf_site_forum_content', 'do_shortcode', 11 );
  360. add_filter( 'cpsf_site_forum_content', 'shortcode_unautop' );
  361. add_filter( 'cpsf_site_forum_content', 'prepend_attachment' );
  362. add_filter( 'cpsf_site_forum_content', 'wp_make_content_images_responsive' );
  363. add_filter( 'cpsf_get_topic_tag_description', 'cpsf_kses' );
  364. add_filter( 'cpsf_get_topic_tag_description', 'wp_unslash' );
  365. add_filter( 'cpsf_get_topic_tag_description', 'wptexturize' );
  366. add_filter( 'cpsf_get_topic_tag_description', 'convert_smilies', 20 );
  367. /**
  368. * Map forum caps for the displayed site.
  369. *
  370. * @since 1.0.0
  371. *
  372. * @param array $caps List of Caps for the current capability check.
  373. * @param string $cap The current capability check.
  374. * @param int $user_id The current user ID.
  375. * @param array $args Additional arguments for the capability check.
  376. * @return array List of Caps for the current capability check.
  377. */
  378. function cpsf_map_forum_caps( $caps, $cap, $user_id, $args ) {
  379. if ( ! cp_displayed_site() ) {
  380. return $caps;
  381. }
  382. $is_site_admin = is_super_admin();
  383. if ( ! $is_site_admin && false !== array_search( $user_id, cp_displayed_site()->admins ) ) {
  384. $is_site_admin = true;
  385. }
  386. switch ( $cap ) {
  387. case 'publish_forums' :
  388. if ( $is_site_admin ) {
  389. $caps = array( 'exist' );
  390. }
  391. break;
  392. case 'edit_forum' :
  393. case 'delete_forum' :
  394. $_forum = get_post( $args[0] );
  395. if ( (int) $_forum->ID === (int) cp_displayed_site()->forum_id && $is_site_admin ) {
  396. $caps = array( 'exist' );
  397. }
  398. break;
  399. }
  400. /**
  401. * Filter here to edit the forum caps map.
  402. *
  403. * @since 1.0.0
  404. *
  405. * @param array $caps List of Caps for the current capability check.
  406. * @param string $cap The current capability check.
  407. * @param int $user_id The current user ID.
  408. * @param array $args Additional arguments for the capability check.
  409. */
  410. return apply_filters( 'cpsf_map_forum_caps', $caps, $cap, $user_id, $args );
  411. }
  412. add_filter( 'bbp_map_forum_meta_caps', 'cpsf_map_forum_caps', 10, 4 );
  413. /**
  414. * Map topic caps for the displayed site.
  415. *
  416. * @since 1.0.0
  417. *
  418. * @param array $caps List of Caps for the current capability check.
  419. * @param string $cap The current capability check.
  420. * @param int $user_id The current user ID.
  421. * @param array $args Additional arguments for the capability check.
  422. * @return array List of Caps for the current capability check.
  423. */
  424. function cpsf_map_topic_caps( $caps, $cap, $user_id, $args ) {
  425. if ( ! cp_displayed_site() ) {
  426. return $caps;
  427. }
  428. $is_site_admin = is_super_admin();
  429. if ( ! $is_site_admin && false !== array_search( $user_id, cp_displayed_site()->admins ) ) {
  430. $is_site_admin = true;
  431. }
  432. switch ( $cap ) {
  433. case 'publish_topics' :
  434. if ( ! $is_site_admin && ! empty( $user_id ) ) {
  435. $user_sites = cp_sites_get_user_sites( $user_id, 'any' );
  436. // Only site members of followers can publish topics
  437. if ( false === array_search( cp_get_displayed_site_id(), $user_sites ) ) {
  438. $caps = array( 'do_not_allow' );
  439. } else {
  440. $caps = array( 'exist' );
  441. }
  442. }
  443. break;
  444. case 'edit_topic' :
  445. case 'edit_topics' :
  446. case 'edit_others_topics' :
  447. case 'delete_topics' :
  448. case 'delete_others_topics' :
  449. if ( $is_site_admin ) {
  450. $caps = array( 'exist' );
  451. }
  452. break;
  453. case 'moderate' :
  454. case 'delete_topic' :
  455. if ( ! empty( $args[0] ) ) {
  456. $_topic = get_post( $args[0] );
  457. if ( (int) bbp_get_topic_forum_id( $_topic->ID ) === (int) cp_displayed_site()->forum_id && $is_site_admin ) {
  458. $caps = array( 'exist' );
  459. }
  460. }
  461. break;
  462. }
  463. /**
  464. * Filter here to edit the topic caps map.
  465. *
  466. * @since 1.0.0
  467. *
  468. * @param array $caps List of Caps for the current capability check.
  469. * @param string $cap The current capability check.
  470. * @param int $user_id The current user ID.
  471. * @param array $args Additional arguments for the capability check.
  472. */
  473. return apply_filters( 'cpsf_map_topic_caps', $caps, $cap, $user_id, $args );
  474. }
  475. add_filter( 'bbp_map_topic_meta_caps', 'cpsf_map_topic_caps', 10, 4 );
  476. /**
  477. * Map reply caps for the displayed site.
  478. *
  479. * @since 1.0.0
  480. *
  481. * @param array $caps List of Caps for the current capability check.
  482. * @param string $cap The current capability check.
  483. * @param int $user_id The current user ID.
  484. * @param array $args Additional arguments for the capability check.
  485. * @return array List of Caps for the current capability check.
  486. */
  487. function cpsf_map_reply_caps( $caps, $cap, $user_id, $args ) {
  488. if ( ! cp_displayed_site() ) {
  489. return $caps;
  490. }
  491. $is_site_admin = is_super_admin();
  492. if ( ! $is_site_admin && false !== array_search( $user_id, cp_displayed_site()->admins ) ) {
  493. $is_site_admin = true;
  494. }
  495. switch ( $cap ) {
  496. case 'publish_replies' :
  497. if ( ! $is_site_admin && ! empty( $user_id ) ) {
  498. $user_sites = cp_sites_get_user_sites( $user_id, 'any' );
  499. // Only site members of followers can publish topics
  500. if ( false === array_search( cp_get_displayed_site_id(), $user_sites ) ) {
  501. $caps = array( 'do_not_allow' );
  502. } else {
  503. $caps = array( 'exist' );
  504. }
  505. }
  506. break;
  507. case 'edit_reply' :
  508. case 'edit_replies' :
  509. case 'edit_others_replies' :
  510. case 'delete_replies' :
  511. case 'delete_others_replies' :
  512. if ( $is_site_admin ) {
  513. $caps = array( 'exist' );
  514. }
  515. break;
  516. case 'moderate' :
  517. case 'delete_reply' :
  518. if ( ! empty( $args[0] ) ) {
  519. $_reply = get_post( $args[0] );
  520. if ( (int) bbp_get_reply_forum_id( $_reply->ID ) === (int) cp_displayed_site()->forum_id && $is_site_admin ) {
  521. $caps = array( 'exist' );
  522. }
  523. }
  524. break;
  525. }
  526. /**
  527. * Filter here to edit the reply caps map.
  528. *
  529. * @since 1.0.0
  530. *
  531. * @param array $caps List of Caps for the current capability check.
  532. * @param string $cap The current capability check.
  533. * @param int $user_id The current user ID.
  534. * @param array $args Additional arguments for the capability check.
  535. */
  536. return apply_filters( 'cpsf_map_reply_caps', $caps, $cap, $user_id, $args );
  537. }
  538. add_filter( 'bbp_map_reply_meta_caps', 'cpsf_map_reply_caps', 10, 4 );
  539. /**
  540. * Map topic tags caps for the displayed site.
  541. *
  542. * @since 1.0.0
  543. *
  544. * @param array $caps List of Caps for the current capability check.
  545. * @param string $cap The current capability check.
  546. * @param int $user_id The current user ID.
  547. * @param array $args Additional arguments for the capability check.
  548. * @return array List of Caps for the current capability check.
  549. */
  550. function cpsf_map_topic_tag_caps( $caps, $cap, $user_id, $args ) {
  551. if ( ! cp_displayed_site() ) {
  552. return $caps;
  553. }
  554. $is_site_admin = is_super_admin();
  555. if ( ! $is_site_admin && false !== array_search( $user_id, cp_displayed_site()->admins ) ) {
  556. $is_site_admin = true;
  557. }
  558. switch ( $cap ) {
  559. case 'manage_topic_tags' :
  560. case 'edit_topic_tags' :
  561. case 'delete_topic_tags' :
  562. if ( $is_site_admin ) {
  563. $caps = array( 'exist' );
  564. }
  565. break;
  566. }
  567. /**
  568. * Filter here to edit the topic tags caps map.
  569. *
  570. * @since 1.0.0
  571. *
  572. * @param array $caps List of Caps for the current capability check.
  573. * @param string $cap The current capability check.
  574. * @param int $user_id The current user ID.
  575. * @param array $args Additional arguments for the capability check.
  576. */
  577. return apply_filters( 'cpsf_map_topic_tag_caps', $caps, $cap, $user_id, $args );
  578. }
  579. add_filter( 'bbp_map_topic_tag_meta_caps', 'cpsf_map_topic_tag_caps', 10, 4 );
  580. /**
  581. * Filters the bbPress Topics pagination to adapt it to the displayed site's forum.
  582. *
  583. * @since 1.0.0
  584. *
  585. * @param array $pagination The paginate link arguments built by bbPress.
  586. * @return array The paginate link arguments.
  587. */
  588. function cpsf_site_set_forum_pagination_base( $pagination = array() ) {
  589. if ( ( ! cpsf_is_single_forum() && ! cpsf_get_topic_tag() ) || ! isset( $pagination['base'] ) ) {
  590. return $pagination;
  591. }
  592. if ( cpsf_get_topic_tag() ) {
  593. $base = cpsf_get_topic_tag_link( '', cpsf_get_topic_tag_term(), bbp_get_topic_tag_tax_id() );
  594. } else {
  595. $forum = cpsf_get_current_forum();
  596. $base = cpsf_get_site_forum_permalink( '', $forum->ID );
  597. }
  598. if ( ! $base ) {
  599. return $pagination;
  600. }
  601. if ( ! clusterpress()->permalink_structure ) {
  602. $pagination['base'] = esc_url_raw( add_query_arg( 'paged', '%#%', $base ) );
  603. } else {
  604. $pagination['base'] = trailingslashit( $base ) . cp_get_paged_slug() . '/%#%/';
  605. }
  606. return $pagination;
  607. }
  608. add_filter( 'bbp_topic_pagination', 'cpsf_site_set_forum_pagination_base' );
  609. /**
  610. * Filters the bbPress Replies pagination to adapt it to the displayed site's forum.
  611. *
  612. * @since 1.0.0
  613. *
  614. * @param array $pagination The paginate link arguments built by bbPress.
  615. * @return array The paginate link arguments.
  616. */
  617. function cpsf_site_set_topic_pagination_base( $pagination = array() ) {
  618. if ( ! cpsf_is_single_topic() || ! isset( $pagination['base'] ) ) {
  619. return $pagination;
  620. }
  621. $topic = cpsf_get_current_topic();
  622. $base = cpsf_get_site_topic_permalink( '', $topic->ID );
  623. if ( ! $base ) {
  624. return $pagination;
  625. }
  626. if ( ! clusterpress()->permalink_structure ) {
  627. $pagination['base'] = esc_url_raw( add_query_arg( 'paged', '%#%', $base ) );
  628. } else {
  629. $pagination['base'] = trailingslashit( $base ) . cp_get_paged_slug() . '/%#%/';
  630. }
  631. return $pagination;
  632. }
  633. add_filter( 'bbp_replies_pagination', 'cpsf_site_set_topic_pagination_base' );