Plugin Updates
This commit is contained in:
@@ -45,7 +45,7 @@ class TransientFilesEngine implements RegisterHooksInterface {
|
||||
*
|
||||
* @var LegacyProxy
|
||||
*/
|
||||
private LegacyProxy $legacy_proxy;
|
||||
private $legacy_proxy;
|
||||
|
||||
/**
|
||||
* Register hooks.
|
||||
@@ -54,7 +54,7 @@ class TransientFilesEngine implements RegisterHooksInterface {
|
||||
self::add_action( self::CLEANUP_ACTION_NAME, array( $this, 'handle_expired_files_cleanup_action' ) );
|
||||
self::add_filter( 'woocommerce_debug_tools', array( $this, 'add_debug_tools_entries' ), 999, 1 );
|
||||
|
||||
self::add_action( 'init', array( $this, 'handle_init' ), 0 );
|
||||
self::add_action( 'init', array( $this, 'add_endpoint' ), 0 );
|
||||
self::add_filter( 'query_vars', array( $this, 'handle_query_vars' ), 0 );
|
||||
self::add_action( 'parse_request', array( $this, 'handle_parse_request' ), 0 );
|
||||
}
|
||||
@@ -109,6 +109,14 @@ class TransientFilesEngine implements RegisterHooksInterface {
|
||||
if ( ! $this->legacy_proxy->call_function( 'wp_mkdir_p', $transient_files_directory ) ) {
|
||||
throw new Exception( "Can't create directory: $transient_files_directory" );
|
||||
}
|
||||
|
||||
// Create infrastructure to prevent listing the contents of the transient files directory.
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
\WP_Filesystem();
|
||||
$wp_filesystem = $this->legacy_proxy->get_global( 'wp_filesystem' );
|
||||
$wp_filesystem->put_contents( $transient_files_directory . '/.htaccess', 'deny from all' );
|
||||
$wp_filesystem->put_contents( $transient_files_directory . '/index.html', '' );
|
||||
|
||||
$realpathed_transient_files_directory = $this->legacy_proxy->call_function( 'realpath', $transient_files_directory );
|
||||
} else {
|
||||
throw new Exception( "The base transient files directory doesn't exist: $transient_files_directory" );
|
||||
@@ -153,7 +161,8 @@ class TransientFilesEngine implements RegisterHooksInterface {
|
||||
}
|
||||
$filepath = $transient_files_directory . '/' . $filename;
|
||||
|
||||
WP_Filesystem();
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
\WP_Filesystem();
|
||||
$wp_filesystem = $this->legacy_proxy->get_global( 'wp_filesystem' );
|
||||
if ( false === $wp_filesystem->put_contents( $filepath, $file_contents ) ) {
|
||||
throw new Exception( "Can't create file: $filepath" );
|
||||
@@ -175,6 +184,23 @@ class TransientFilesEngine implements RegisterHooksInterface {
|
||||
* @return string|null The full physical path of the file, or null if the files doesn't exist.
|
||||
*/
|
||||
public function get_transient_file_path( string $filename ): ?string {
|
||||
$expiration_date = self::get_expiration_date( $filename );
|
||||
if ( is_null( $expiration_date ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$file_path = $this->get_transient_files_directory() . '/' . $expiration_date . '/' . substr( $filename, 6 );
|
||||
|
||||
return is_file( $file_path ) ? $file_path : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the expiration date of a transient file based on its file name. The actual existence of the file is NOT checked.
|
||||
*
|
||||
* @param string $filename The name of the transient file to get the expiration date for.
|
||||
* @return string|null Expiration date formatted as Y-m-d, null if the file name isn't encoding a proper date.
|
||||
*/
|
||||
public static function get_expiration_date( string $filename ) : ?string {
|
||||
if ( strlen( $filename ) < 7 || ! ctype_xdigit( $filename ) ) {
|
||||
return null;
|
||||
}
|
||||
@@ -185,13 +211,18 @@ class TransientFilesEngine implements RegisterHooksInterface {
|
||||
hexdec( substr( $filename, 3, 1 ) ),
|
||||
hexdec( substr( $filename, 4, 2 ) )
|
||||
);
|
||||
if ( ! TimeUtil::is_valid_date( $expiration_date, 'Y-m-d' ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$file_path = $this->get_transient_files_directory() . '/' . $expiration_date . '/' . substr( $filename, 6 );
|
||||
return TimeUtil::is_valid_date( $expiration_date, 'Y-m-d' ) ? $expiration_date : null;
|
||||
}
|
||||
|
||||
return is_file( $file_path ) ? $file_path : null;
|
||||
/**
|
||||
* Get the public URL of a transient file. The file name is NOT checked for validity or actual existence.
|
||||
*
|
||||
* @param string $filename The name of the transient file to get the public URL for.
|
||||
* @return string The public URL of the file.
|
||||
*/
|
||||
public function get_public_url( string $filename ) {
|
||||
return $this->legacy_proxy->call_function( 'get_site_url', null, '/wc/file/transient/' . $filename );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -394,7 +425,7 @@ class TransientFilesEngine implements RegisterHooksInterface {
|
||||
/**
|
||||
* Handle the "init" action, add rewrite rules for the "wc/file" endpoint.
|
||||
*/
|
||||
private function handle_init() {
|
||||
public static function add_endpoint() {
|
||||
add_rewrite_rule( '^wc/file/transient/?$', 'index.php?wc-transient-file-name=', 'top' );
|
||||
add_rewrite_rule( '^wc/file/transient/(.+)$', 'index.php?wc-transient-file-name=$matches[1]', 'top' );
|
||||
add_rewrite_endpoint( 'wc/file/transient', EP_ALL );
|
||||
|
||||
Reference in New Issue
Block a user