8000 Fixes PHP notices (#383) and improve detects of backend request - rev by stodorovic · Pull Request #475 · Automattic/wp-super-cache · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixes PHP notices (#383) and improve detects of backend request - rev #475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

stodorovic
Copy link
  • Use wp_json_encode if this function exists (WP Core >= 4.1.0). It fixes #349
  • Introduce wpsc_is_backend
  • Improve get_current_url_supercache_dir by using regular expressions
  • Additional checking for $WPSC_HTTP_HOST

It's replacement for #384 which can't be easy merged at this moment.

$dir = preg_replace( '/:.*$/', '', $WPSC_HTTP_HOST ) . $uri; // To avoid XSS attacks
$uri = wpsc_deep_replace( array( '..', '\\', 'index.php', ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace( "/(\?.*)?(#.*)?$/", '', $uri ) ) );
// Get hostname from wp options for wp-cron, wp-cli and similar requests.
$hostname = empty( $WPSC_HTTP_HOST ) ? (string) parse_url( get_option( 'home' ), PHP_URL_HOST ) : $WPSC_HTTP_HOST;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a problem for users running old versions of WordPress as get_option() won't always be defined. I tested WordPress 4.4 as get_current_url_supercache_dir() is called by wp_cache_serve_cache_file() and that obviously runs really early on. (I didn't test your patch directly, I Just added a function_exists( 'get_option' ) to get_current_url_supercache_dir() and it returned false.)

We probably need to check if get_option() exists and if it doesn't and if WPSC_HTTP_HOST is blank disable caching. What do you think?

Copy link
Author
@stodorovic stodorovic Dec 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added checking if function get_option exists. So, it'll help because almost all cases are related (when WPSC_HTTP_HOST is empty) for cron request (via php-cli), wp-cli or other kind of php-cli scripts. I'm planning to make some improvements related to preload and for now it's enough (my original idea is to fix issues related to cron jobs).
It's very rare case that webserver doesn't pass $_SERVER variables. So, I think that's acceptable for merging now. Anyway, if someone uses very old webserver, php and wordpress, then there are many other issues and he should update everything.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Unfortunately WP 4.4 is still maintained so it's going to be an issue for a long time but I agree it should hardly ever happen.

I'm excited to get this into the plugin. It's a really nice cleanup of some of the code!

@donnchawp donnchawp merged commit 1dc3921 into Automattic:master Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

json_encode(): Invalid UTF-8 sequence in argument in /wp-cache-phase2.php on line 53
2 participants
0