| 1 |
<?php |
| 2 |
|
| 3 |
//When posting a new topic, or replying, users can click the link button. This brings up a list of recent posts, pages, topics and replies using wp_link_query |
| 4 |
//This filter takes the 'results' array from wp-link-query and filters it to exclude topics, replies or forums that the user is not allowed to see |
| 5 |
|
| 6 |
add_filter( 'wp_link_query', 'rpg_link_query', 10, 2 ); |
| 7 |
|
| 8 |
Function rpg_link_query ($results, $query) { |
| 9 |
|
| 10 |
//bring in the $results array that wp_link_query creates and sort through |
| 11 |
foreach ( $results as $key => $result ) { |
| 12 |
$postcheck= $result['ID'] ; |
| 13 |
//look up post type |
| 14 |
$pg_post_type = get_post_type( $postcheck ) ; |
| 15 |
//test to see if post if topic, reply or forum |
| 16 |
if ( ($pg_post_type == bbp_get_forum_post_type() ) || ($pg_post_type == bbp_get_topic_post_type() ) || ($pg_post_type == bbp_get_reply_post_type() ) ) { |
| 17 |
//Get the Forum ID based on Post Type (Reply, Topic, Forum) |
| 18 |
$pg_forum_id = private_groups_get_forum_id_from_post_id($postcheck, $pg_post_type); |
| 19 |
|
| 20 |
//test to see if not allowed this forum |
| 21 |
if (private_groups_can_user_view_post_id($pg_forum_id) == false || topic_permissions_check ($postcheck) == false) { |
| 22 |
//and if so unset the result |
| 23 |
unset ($results[$key]) ; |
| 24 |
} |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
} |
| 29 |
return apply_filters( 'rpg_link_query', $results, $query ); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|