Skip to content
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

Fix erratic $log_file_link and $raw_log_file_link on Debug TAB on Windows #633

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions wp-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2085,8 +2085,16 @@ function wp_cache_debug_settings() {
if ( ! isset( $wp_cache_debug_log ) || $wp_cache_debug_log == '' ) {
extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username
}
$log_file_link = "<a href='" . site_url( str_replace( ABSPATH, '', "{$cache_path}view_{$wp_cache_debug_log}" ) ) . "'>$wp_cache_debug_log</a>";
$raw_log_file_link = "<a href='" . site_url( str_replace( ABSPATH, '', "{$cache_path}{$wp_cache_debug_log}" ) ) . "'>" . __( 'RAW', 'wp-super-cache' ) . "</a>";
if ( function_exists( 'wp_normalize_path' ) ) {
$cache_url = wp_normalize_path( $cache_path );
$cache_url = str_replace( wp_normalize_path( ABSPATH ), '', $cache_url );
} else {
$cache_url = str_replace( '\\', '/', $cache_path );
$cache_url = str_replace( str_replace( '\\', '/', ABSPATH ), '', $cache_url );
}

Choose a reason for hiding this comment

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

I've found old laptop with Windows XP/PHP 5.2,5.3,5.4. I've tested following code:

Suggested change
}
// Extracts and normalizes relative path.
$cache_rel_path = str_replace( realpath( ABSPATH ), '', realpath( $cache_path ) );
$cache_rel_path = str_replace( '\\', '/', $cache_rel_path );

It seems OK by first tests and it's more readable. We need only to replace \ because $cache_rel_path doesn't contain drive letter.

$cache_url = site_url( $cache_url );

Choose a reason for hiding this comment

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

Suggested change
$cache_url = site_url( $cache_url );
$cache_url = trailingslashit( site_url( $cache_rel_path ) );

It's possible to realpath strips last slash.

$log_file_link = "<a href='{$cache_url}view_{$wp_cache_debug_log}'>$wp_cache_debug_log</a>";
$raw_log_file_link = "<a href='{$cache_url}{$wp_cache_debug_log}'>" . __( 'RAW', 'wp-super-cache' ) . "</a>";
if ( $wp_super_cache_debug == 1 ) {
echo "<p>" . sprintf( __( 'Currently logging to: %s (%s)', 'wp-super-cache' ), $log_file_link, $raw_log_file_link ) . "</p>";
} else {
Expand Down