Making WordPress.org

Ticket #5093: 50932.patch

File 50932.patch, 2.9 KB (added by vladytimy, 3 years ago)

Minor non-functional changes

  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php

     
    8080                // Display extra topic fields after content.
    8181                add_action( 'bbp_theme_after_topic_content', array( $this, 'display_extra_topic_fields' ) );
    8282
     83                // Filter site URL from replies.
     84        add_action( 'bbp_get_reply_content', array( $this, 'filter_extra_url_topic_field_from_replies' ) );
     85
    8386                // Add extra topic fields after Title field in topic form.
    8487                add_action( 'bbp_theme_after_topic_form_title', array( $this, 'add_extra_topic_fields' ) );
    8588
     
    929932        }
    930933
    931934        /**
     935         * Filter away SITE_URL_META from a reply, UNLESS current user is the topic starter themselves, a moderator or the author of the reply.
     936         *
     937         * @param string $content Topic reply content.
     938         * @return string
     939         */
     940        public function filter_extra_url_topic_field_from_replies( $content ) {
     941                $url = get_post_meta( bbp_get_topic_id(), self::SITE_URL_META, true );
     942
     943                // If no custom URL has been added to the post, no extra processing is needed.
     944                if ( ! $url ) {
     945                        return $content;
     946                }
     947
     948                $url = parse_url( $url );
     949
     950                // Return early if the URL has not been used.
     951                if ( substr_count( $content, $url['host'] ) < 1 ) {
     952                        return $content;
     953                }
     954
     955                // Do not filter the URL for the topic creator themselves.
     956                if ( bbp_get_topic_author_id() === get_current_user_id() ) {
     957                        $user_information = sprintf(
     958                                '<p class="wporg-bbp-topic-site-url">%s</p>',
     959                                __( 'This reply contains one or more links to the page you need help with. These links will only be shown to you and the author of this reply.', 'wporg-forums' )
     960                        );
     961
     962                        return $content . $user_information;
     963                }
     964
     965                // Do not filter the URL for the reply author and moderators.
     966                if ( current_user_can( 'moderate' ) || bbp_get_reply_author_id() === get_current_user_id() ) {
     967                        $user_information = sprintf(
     968                                '<p class="wporg-bbp-topic-site-url">%s</p>',
     969                                __( 'This reply contains one or more links to the thread starter\'s page. These links will only be shown to you and the person who created this thread.', 'wporg-forums' )
     970                        );
     971
     972                        return $content . $user_information;
     973                }
     974
     975                // Replace the occurrence of the URL the user needs help on, with an example domain.
     976                $content = str_ireplace( $url['host'], 'example.com', $content );
     977
     978                // Wrap example URLs in code ticks to exemplify that they are, in fact, not real links.
     979                $content = preg_replace( "/(\S*example.com\S*)/si", "<code>$1</code>", $content );
     980
     981                return $content;
     982        }
     983
     984        /**
    932985         * Add extra topic fields after Title field in topic form.
    933986         */
    934987        public function add_extra_topic_fields() {