Patch to reduce disk access
-
Every time the plugin renders a form, it will re-create the empty
index.phpto protect folders from being browsed. Even if theindex.phpalready exists. This heavily increase disk write for no reason, negatively impacting the server performance.Here is a patch that centralize the check whether
index.phpshould be created inside the concerned method\Forminator_Field::add_index_file(). So, that method can be called without repeating the fragile, and broken, check before calling it.diff -ur a/library/abstracts/abstract-class-field.php b/library/abstracts/abstract-class-field.php
--- library/abstracts/abstract-class-field.php 2026-01-20 11:31:24.000000000 +0900
+++ library/abstracts/abstract-class-field.php 2026-03-20 16:29:23.815566745 +0900
@@ -2227,7 +2227,7 @@
return;
}
// Make sure it was not called before WP init.
- if ( ! file_exists( $upload_root . 'index.php' ) && function_exists( 'insert_with_markers' ) ) {
+ if ( function_exists( 'insert_with_markers' ) ) {
self::add_index_file( $upload_root );
self::add_htaccess_file();
}
@@ -2241,8 +2241,9 @@
* @return void
*/
public static function add_index_file( $dir ) {
- $dir = untrailingslashit( $dir );
- if ( ! is_dir( $dir ) || ! wp_is_writable( $dir ) || is_link( $dir ) ) {
+ $dir = untrailingslashit( $dir );
+ $index_file_path = $dir . '/index.php';
+ if ( is_file( $index_file_path ) || ! is_dir( $dir ) || ! wp_is_writable( $dir ) || is_link( $dir ) ) {
return;
}
$dp = opendir( $dir );
@@ -2256,7 +2257,6 @@
global $wp_filesystem;
if ( WP_Filesystem() ) {
- $index_file_path = $dir . '/index.php';
// creates an empty index.php file.
$wp_filesystem->put_contents( $index_file_path, '', FS_CHMOD_FILE );
}
@@ -2289,12 +2289,8 @@
}
self::check_upload_root_index_file();
- if ( ! file_exists( forminator_get_upload_path( $form_id ) . 'index.php' ) ) {
- self::add_index_file( forminator_get_upload_path( $form_id ) );
- }
- if ( ! file_exists( $path . 'index.php' ) ) {
- self::add_index_file( $path );
- }
+ self::add_index_file( forminator_get_upload_path( $form_id ) );
+ self::add_index_file( $path );
}
/**
diff -ur a/forminator/library/class-form-fields.php b/library/class-form-fields.php
--- forminator/library/class-form-fields.php 2025-10-20 10:50:06.000000000 +0900
+++ library/class-form-fields.php 2026-03-20 16:27:42.102583525 +0900
@@ -212,11 +212,7 @@
Forminator_Field::check_upload_root_index_file();
- if ( ! file_exists( $upload_root . 'css/index.php' ) ) {
- Forminator_Field::add_index_file( $upload_root . 'css/index.php' );
- }
- if ( ! file_exists( $upload_root . 'signatures/index.php' ) ) {
- Forminator_Field::add_index_file( $upload_root . 'signatures/index.php' );
- }
+ Forminator_Field::add_index_file( $upload_root . 'css' );
+ Forminator_Field::add_index_file( $upload_root . 'signatures' );
}
}
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.