Make WordPress Core

Changeset 53294


Ignore:
Timestamp:
04/27/2022 01:45:57 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Bootstrap/Load: Avoid a PHP warning when setting the $pagenow global in wp-includes/vars.php.

In some scenarios where is_admin() returns true but $_SERVER['PHP_SELF'] does not match a wp-admin/* location, setting the $pagenow global could trigger a PHP warning: Undefined array key 1.

This commit avoids the warning by checking whether the matches array is not empty.

Props janh2, konradyoast, peterwilsoncc.
Fixes #54700.

File:
1 edited

Legend:

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

    r53060 r53294  
    3030        preg_match( '#/wp-admin/?(.*?)$#i', $_SERVER['PHP_SELF'], $self_matches );
    3131    }
    32     $pagenow = $self_matches[1];
     32
     33    $pagenow = ! empty( $self_matches[1] ) ? $self_matches[1] : '';
    3334    $pagenow = trim( $pagenow, '/' );
    3435    $pagenow = preg_replace( '#\?.*?$#', '', $pagenow );
     36
    3537    if ( '' === $pagenow || 'index' === $pagenow || 'index.php' === $pagenow ) {
    3638        $pagenow = 'index.php';
Note: See TracChangeset for help on using the changeset viewer.