Skip to content

Commit

Permalink
Bootstrap/Load: Check $_SERVER['SCRIPT_NAME'] exists before passing…
Browse files Browse the repository at this point in the history
… to `strpos()` in `wp_fix_server_vars()`.

If `SCRIPT_NAME'` does not exist (which can happen in cron jobs), the following happens:

* PHP 8.1+:
    * `Warning: Undefined array key "SCRIPT_NAME"`
    * `Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated` 
* PHP 8.0: `Warning: Undefined array key "SCRIPT_NAME"`
* PHP 5.6-7.4: No warning or notice

This commit checks if the key exists before passing it to `strpos()`. This resolves the warning, notice, and future error.

Follow-up to [3034], [3069], [12732].

Props audrasjb, costdev, hellofromTonya, karpstrucking, mcjambi, sergeybiryukov.
Fixes #54142.

git-svn-id: https://develop.svn.wordpress.org/trunk@52144 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
hellofromtonya committed Nov 12, 2021
1 parent 95adcec commit ff04bb0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/wp-includes/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function wp_fix_server_vars() {
}

// Fix for Dreamhost and other PHP as CGI hosts.
if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false ) {
if ( isset( $_SERVER['SCRIPT_NAME'] ) && ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false ) ) {
unset( $_SERVER['PATH_INFO'] );
}

Expand Down

0 comments on commit ff04bb0

Please sign in to comment.