WordPress.org

Make WordPress Core

Ticket #30355: 30355.4.diff

File 30355.4.diff, 3.6 KB (added by DrewAPicture, 4 years ago)
  • src/wp-includes/author-template.php

     
    223223}
    224224
    225225/**
    226  * Display an HTML link to the author page of the author of the current post.
     226 * Retrieves an HTML link to the author page of the author of the current post.
    227227 *
    228  * Does just echo get_author_posts_url() function, like the others do. The
    229  * reason for this, is that another function is used to help in printing the
    230  * link to the author's posts.
     228 * Returns an HTML-formatted link using get_author_posts_url().
    231229 *
    232  * @link https://codex.wordpress.org/Template_Tags/the_author_posts_link
    233  * @since 1.2.0
     230 * @since 4.4.0
    234231 *
    235232 * @global object $authordata The current author's DB object.
    236233 *
    237  * @param string $deprecated Deprecated.
     234 * @return string An HTML link to the author page.
    238235 */
    239 function the_author_posts_link($deprecated = '') {
    240         if ( !empty( $deprecated ) )
    241                 _deprecated_argument( __FUNCTION__, '2.1' );
    242 
     236function get_the_author_posts_link() {
    243237        global $authordata;
    244238        if ( ! is_object( $authordata ) ) {
    245239                return;
     
    259253         *
    260254         * @param string $link HTML link.
    261255         */
    262         echo apply_filters( 'the_author_posts_link', $link );
     256        return apply_filters( 'the_author_posts_link', $link );
    263257}
    264258
    265259/**
     260 * Displays an HTML link to the author page of the author of the current post.
     261 *
     262 * @since 1.2.0
     263 * @since 4.4.0 Converted into a wrapper for get_the_author_posts_link()
     264 *
     265 * @param string $deprecated Unused.
     266 */
     267function the_author_posts_link( $deprecated = '' ) {
     268        if ( ! empty( $deprecated ) ) {
     269                _deprecated_argument( __FUNCTION__, '2.1' );
     270        }
     271        echo get_the_author_posts_link();
     272}
     273
     274/**
    266275 * Retrieve the URL to the author page for the user with the ID provided.
    267276 *
    268277 * @since 2.1.0
  • tests/phpunit/tests/template/author.php

     
     1<?php
     2
     3/**
     4 * A set of unit tests for functions in wp-includes/author-template.php
     5 *
     6 * @group template
     7 */
     8class Tests_Author_Template extends WP_UnitTestCase {
     9
     10        /**
     11         * @ticket 30355
     12         */
     13        public function test_get_the_author_posts_link_no_permalinks() {
     14                $author = $this->factory->user->create_and_get( array(
     15                        'display_name'  => 'Foo',
     16                        'user_nicename' => 'bar'
     17                ) );
     18
     19                $GLOBALS['authordata'] = $author->data;
     20
     21                $link = get_the_author_posts_link();
     22
     23                $url = sprintf( 'http://%1$s/?author=%2$s', WP_TESTS_DOMAIN, $author->ID );
     24
     25                $this->assertContains( $url, $link );
     26                $this->assertContains( 'Posts by Foo', $link );
     27                $this->assertContains( '>Foo</a>', $link );
     28
     29                unset( $GLOBALS['authordata'] );
     30        }
     31
     32        /**
     33         * @ticket 30355
     34         */
     35        public function test_get_the_author_posts_link_with_permalinks() {
     36                global $wp_rewrite;
     37                $wp_rewrite->init();
     38                $wp_rewrite->set_permalink_structure( '/%postname%/' );
     39                $wp_rewrite->flush_rules();
     40
     41                $author = $this->factory->user->create_and_get( array(
     42                        'display_name'  => 'Foo',
     43                        'user_nicename' => 'bar'
     44                ) );
     45
     46                $GLOBALS['authordata'] = $author;
     47
     48                $link = get_the_author_posts_link();
     49
     50                $url = sprintf( 'http://%1$s/author/%2$s/', WP_TESTS_DOMAIN, $author->user_nicename );
     51
     52                $this->assertContains( $url, $link );
     53                $this->assertContains( 'Posts by Foo', $link );
     54                $this->assertContains( '>Foo</a>', $link );
     55
     56                // Cleanup.
     57                $wp_rewrite->set_permalink_structure( '' );
     58                unset( $GLOBALS['authordata'] );
     59        }
     60}