WordPress.org

Make WordPress Core

Ticket #30355: 30355.3.diff

File 30355.3.diff, 3.5 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                $this->assertContains( 'http://example.org/?author=' . $author->ID, $link );
     24                $this->assertContains( 'Posts by Foo', $link );
     25                $this->assertRegExp( '/>Foo<\/a>/', $link );
     26
     27                unset( $GLOBALS['authordata'] );
     28        }
     29
     30        /**
     31         * @ticket 30355
     32         */
     33        public function test_get_the_author_posts_link_with_permalinks() {
     34                global $wp_rewrite;
     35                $wp_rewrite->init();
     36                $wp_rewrite->set_permalink_structure( '/%postname%/' );
     37                $wp_rewrite->flush_rules();
     38
     39                $author = $this->factory->user->create_and_get( array(
     40                        'display_name'  => 'Foo',
     41                        'user_nicename' => 'bar'
     42                ) );
     43
     44                $GLOBALS['authordata'] = $author;
     45
     46                $link = get_the_author_posts_link();
     47
     48                $this->assertContains( 'http://example.org/author/bar/', $link );
     49                $this->assertContains( 'Posts by Foo', $link );
     50                $this->assertRegExp( '/>Foo<\/a>/', $link );
     51
     52                // Cleanup.
     53                $wp_rewrite->set_permalink_structure( '' );
     54                unset( $GLOBALS['authordata'] );
     55        }
     56}