Making WordPress.org


Ignore:
Timestamp:
02/05/2020 05:43:15 AM (5 years ago)
Author:
dd32
Message:

Plugin Directory: Add ugc to rel="nofollow" links in user supplied content.

Props diddledan.
Fixes #4958.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r9187 r9470  
    4646        add_filter( 'query_vars', array( $this, 'filter_query_vars' ) );
    4747        add_filter( 'single_term_title', array( $this, 'filter_single_term_title' ) );
    48         add_filter( 'the_content', array( $this, 'filter_rel_nofollow' ) );
     48        add_filter( 'the_content', array( $this, 'filter_rel_nofollow_ugc' ) );
    4949        add_action( 'wp_head', array( Template::class, 'json_ld_schema' ), 1 );
    5050        add_action( 'wp_head', array( Template::class, 'output_meta' ), 1 );
     
    704704
    705705    /**
    706      * Filter content to make links rel=nofollow on plugin pages only
     706     * Filter content to make links rel="nofollow ugc" on plugin pages only
    707707     *
    708708     * @param string $content    The content.
    709709     * @return string
    710710     */
    711     public function filter_rel_nofollow( $content ) {
     711    public function filter_rel_nofollow_ugc( $content ) {
    712712        if ( get_post_type() == 'plugin' ) {
    713             // regex copied from wp_rel_nofollow(). Not calling that function because it messes with slashes.
    714             $content = preg_replace_callback( '|<a (.+?)>|i', 'wp_rel_nofollow_callback', $content );
    715         }
     713            // regex copied from wp_rel_ugc(). Not calling that function because it messes with slashes.
     714            $content = preg_replace_callback(
     715                '|<a (.+?)>|i',
     716                function( $matches ) {
     717                        return wp_rel_callback( $matches, 'nofollow ugc' );
     718                },
     719                $content
     720            );
     721        }
     722
    716723        return $content;
    717724    }
Note: See TracChangeset for help on using the changeset viewer.