get_current_url_supercache_dir() WPSCache 1.0
Hooks from the function
Return
Null. Nothing.
Usage
get_current_url_supercache_dir( $post_id );
Code of get_current_url_supercache_dir() get current url supercache dir WPSCache 1.7.1
function get_current_url_supercache_dir( $post_id = 0 ) {
global $cached_direct_pages, $cache_path, $wp_cache_request_uri, $WPSC_HTTP_HOST, $wp_cache_home_path;
static $saved_supercache_dir = array();
if ( isset( $saved_supercache_dir[ $post_id ] ) ) {
return $saved_supercache_dir[ $post_id ];
}
$DONOTREMEMBER = 0;
if ( $post_id != 0 ) {
$site_url = site_url();
$permalink = get_permalink( $post_id );
if ( false === strpos( $permalink, $site_url ) ) {
/*
* Sometimes site_url doesn't return the siteurl. See https://wordpress.org/support/topic/wp-super-cache-not-refreshing-post-after-comments-made
*/
$DONOTREMEMBER = 1;
wp_cache_debug( "get_current_url_supercache_dir: WARNING! site_url ($site_url) not found in permalink ($permalink).", 1 );
if ( preg_match( '`^(https?:)?//([^/]+)(/.*)?$`i', $permalink, $matches ) ) {
if ( $WPSC_HTTP_HOST != $matches[2] ) {
wp_cache_debug( "get_current_url_supercache_dir: WARNING! SERVER_NAME ({$WPSC_HTTP_HOST}) not found in permalink ($permalink).", 1 );
}
wp_cache_debug( "get_current_url_supercache_dir: Removing SERVER_NAME ({$matches[2]}) from permalink ($permalink). Is the url right?", 1 );
$uri = isset( $matches[3] ) ? $matches[3] : '';
} elseif ( preg_match( '`^/([^/]+)(/.*)?$`i', $permalink, $matches ) ) {
wp_cache_debug( "get_current_url_supercache_dir: WARNING! Permalink ($permalink) looks as absolute path. Is the url right?", 1 );
$uri = $permalink;
} else {
wp_cache_debug( "get_current_url_supercache_dir: WARNING! Permalink ($permalink) could not be understood by parsing url. Using front page.", 1 );
$uri = '';
}
} else {
$uri = str_replace( $site_url, '', $permalink );
if ( strpos( $uri, $wp_cache_home_path ) !== 0 )
$uri = rtrim( $wp_cache_home_path, '/' ) . $uri;
}
} else {
$uri = strtolower( $wp_cache_request_uri );
}
$uri = wpsc_deep_replace( array( '..', '\\', 'index.php', ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace( "/(\?.*)?(#.*)?$/", '', $uri ) ) );
$hostname = $WPSC_HTTP_HOST;
// Get hostname from wp options for wp-cron, wp-cli and similar requests.
if ( empty( $hostname ) && function_exists( 'get_option' ) ) {
$hostname = (string) parse_url( get_option( 'home' ), PHP_URL_HOST );
}
$dir = preg_replace( '/:.*$/', '', $hostname ) . $uri; // To avoid XSS attacks
if ( function_exists( "apply_filters" ) ) {
$dir = apply_filters( 'supercache_dir', $dir );
} else {
$dir = do_cacheaction( 'supercache_dir', $dir );
}
$dir = $cache_path . 'supercache/' . $dir . '/';
if( is_array( $cached_direct_pages ) && in_array( $_SERVER[ 'REQUEST_URI' ], $cached_direct_pages ) ) {
$dir = ABSPATH . $uri . '/';
}
$dir = str_replace( '..', '', str_replace( '//', '/', $dir ) );
wp_cache_debug( "supercache dir: $dir", 5 );
if ( $DONOTREMEMBER == 0 )
$saved_supercache_dir[ $post_id ] = $dir;
return $dir;
}