Make WordPress Core

Changeset 57232


Ignore:
Timestamp:
12/29/2023 01:52:57 PM (4 months ago)
Author:
SergeyBiryukov
Message:

Canonical: Check if the author parameter is a string in redirect_canonical().

This avoids a PHP warning or error when viewing an author on the front end, while an array is passed as $_GET['author'].

Follow-up to [12034], [12040], [12202].

Props david.binda, antonvlasenko, azaozz, SergeyBiryukov.
Fixes #60059.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/canonical.php

    r56738 r57232  
    317317                }
    318318            }
    319         } elseif ( is_author() && ! empty( $_GET['author'] ) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) {
     319        } elseif ( is_author() && ! empty( $_GET['author'] )
     320            && is_string( $_GET['author'] ) && preg_match( '|^[0-9]+$|', $_GET['author'] )
     321        ) {
    320322            $author = get_userdata( get_query_var( 'author' ) );
    321323
  • trunk/tests/phpunit/tests/canonical.php

    r56657 r57232  
    207207            // array( '/?author=%d&year=2008', '/2008/?author=3'),
    208208            // array( '/author/canonical-author/?year=2008', '/2008/?author=3'), // Either or, see previous testcase.
     209            array( '/author/canonical-author/?author[1]=hello', '/author/canonical-author/?author[1]=hello', 60059 ),
    209210
    210211            // Feeds.
Note: See TracChangeset for help on using the changeset viewer.