Documentation

wph/router/actual_file_path

Posted in: Getting Started (4) How To (17) Plugin Options Explained (42) Actions / Filters (35)      Code Example (19)  

Name: wph/router/actual_file_path
Type: Filter
Arguments:
(str) $file_path

The wph/router/actual_file_path filter is a new addition to WP Hide PRO, designed to improve how the router resolves asset file paths during runtime. This filter is applied internally within the router and targets JavaScript and CSS files that are loaded asynchronously from other JS or CSS assets.

In many setups, asynchronously loaded assets inherit paths that point to the WP Hide cache folder. While this works in most cases, certain dynamic loading scenarios require more precise path resolution. The wph/router/actual_file_path filter allows developers to adjust and normalize these asset paths so they correctly reflect their real location before any further routing logic is applied.

Once the path is adjusted through this filter, the asset continues through the normal WP Hide routing and processing flow, ensuring all hiding, rewriting, and optimization rules remain effective. This provides greater flexibility and accuracy when dealing with complex asset loading chains, especially in advanced themes or plugin integrations.

First, add these 2 rewrites into PostProcessing > Document Loaded Assets PostProcessing area:


/wp-content/cache/wph/.*\.js
/wp-content/cache/wph/.*\.css

Secondly, add the following code into a custom file on your /wp-content/mu-plugins/
This example presumes the /pixfort-core/dist/front/ ( pixfort Core plugin ) are the actual location of the files. Adjust that path accordingly.


    add_filter ( 'wph/router/actual_file_path', 'wph_router_actual_file_path' );
    function wph_router_actual_file_path( $file_path )
        {
            if ( is_file ( ABSPATH .  $file_path )  &&   file_exists ( ABSPATH .  $file_path) )
                return $file_path;
            
            global $wph;
            
            $cache_folder   =   defined ( 'WPH_CACHE_FOLDER' )  &&  ! empty ( WPH_CACHE_FOLDER ) ?  WPH_CACHE_FOLDER    :   'cache/wph';
            $cache_folder   =   trailingslashit ( $cache_folder );
            
            //Attempt to locate the file in a specific folder
            $check_file_location    =   array ( 
                                                WP_PLUGIN_DIR . '/pixfort-core/dist/front/'
                                                );
                                                
            $file_path                          =   str_replace( ltrim ( trailingslashit ( $wph->default_variables['content_directory'] ) . $cache_folder , '/' ) , '', $file_path );
            
            foreach ( $check_file_location  as  $check_path ) 
                {
                    if ( is_file ( $check_path .  $file_path )  &&   file_exists ( $check_path .  $file_path) )
                        {
                            $file_path  =   str_replace ( ABSPATH, '', $check_path ) .  $file_path;
                            break;
                        } 
                }
                
            return $file_path;   
        }
Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn
Scroll to top