Making WordPress.org

Ticket #5093: 5093.patch

File 5093.patch, 3.1 KB (added by Clorith, 3 years ago)
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php

    diff --git a/sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php b/sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php
    a b  
    7777                // Display extra topic fields after content.
    7878                add_action( 'bbp_theme_after_topic_content', array( $this, 'display_extra_topic_fields' ) );
    7979
     80                // Filter site URL from replies.
     81        add_action( 'bbp_get_reply_content', array( $this, 'filter_extra_url_topic_field_from_replies' ) );
     82
    8083                // Add extra topic fields after Title field in topic form.
    8184                add_action( 'bbp_theme_after_topic_form_title', array( $this, 'add_extra_topic_fields' ) );
    8285
     
    916919                }
    917920        }
    918921
     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
    919972        /**
    920973         * Add extra topic fields after Title field in topic form.
    921974         */