| | 922 | /** |
| | 923 | * Filter away the site URL from a post, UNLESS it is the topic starter them selves. |
| | 924 | * |
| | 925 | * @param string $content Topic reply content. |
| | 926 | * @return string |
| | 927 | */ |
| | 928 | public function filter_extra_url_topic_field_from_replies( $content ) { |
| | 929 | $url = get_post_meta( bbp_get_topic_id(), self::SITE_URL_META, true ); |
| | 930 | |
| | 931 | // If no custom URL has been added ot the post, no extra processing is needed. |
| | 932 | if ( ! $url ) { |
| | 933 | return $content; |
| | 934 | } |
| | 935 | |
| | 936 | $url = parse_url( $url ); |
| | 937 | |
| | 938 | // Return early if the URL has not been used. |
| | 939 | if ( substr_count( $content, $url['host'] ) < 1 ) { |
| | 940 | return $content; |
| | 941 | } |
| | 942 | |
| | 943 | // Do not filter the URL for the topic creator them selves. |
| | 944 | if ( bbp_get_topic_author_id() === get_current_user_id() ) { |
| | 945 | $user_information = sprintf( |
| | 946 | '<p class="wporg-bbp-topic-site-url">%s</p>', |
| | 947 | __( 'This post contains one, or more, links to the page you needed help with. These links are only viewable to you and the author of this reply.', 'wporg-forums' ) |
| | 948 | ); |
| | 949 | |
| | 950 | return $content . $user_information; |
| | 951 | } |
| | 952 | |
| | 953 | // Let the reply authors, and moderators, see their original content. |
| | 954 | if ( current_user_can( 'moderate' ) || bbp_get_reply_author_id() === get_current_user_id() ) { |
| | 955 | $user_information = sprintf( |
| | 956 | '<p class="wporg-bbp-topic-site-url">%s</p>', |
| | 957 | __( 'This post contains one, or more, links to the thread starters page. These links will only be viewable to you and the person who created this thread.', 'wporg-forums' ) |
| | 958 | ); |
| | 959 | |
| | 960 | return $content . $user_information; |
| | 961 | } |
| | 962 | |
| | 963 | // Replace the occurrence of the URL the user needs help on, with an example domain. |
| | 964 | $content = str_ireplace( $url['host'], 'example.com', $content ); |
| | 965 | |
| | 966 | // Wrap example URLs in code ticks to examplify that they are, in fact, not real links. |
| | 967 | $content = preg_replace( "/(\S*example.com\S*)/si", "<code>$1</code>", $content ); |
| | 968 | |
| | 969 | return $content; |
| | 970 | } |
| | 971 | |