Skip to content

wp_mkdir_p & warning message #142

@ernestmarcinko

Description

@ernestmarcinko

The usage of mkdir in Utils\FileManager.php is incorrect:

if ( $this->initialized(true, 'is_dir') ) {
	foreach ( $directories as $directory ) {
		if ( !$wp_filesystem->is_dir( $directory ) ) {
			$wp_filesystem->mkdir( $directory, 0755, true );
		}
	}
} else {
	foreach ( $directories as $directory ) {
		if ( !is_dir($directory) ) {
			@mkdir($directory, 0755, true); // @phpcs:ignore
		}
	}
}

The file system wrapper is not neccessary here, also $wp_filesystem->mkdir( $directory, 0755, true ) in not recursive. This should be replaced with something like:

foreach ( $directories as $directory ) {
	if ( !is_dir($directory) ) {
		if ( !wp_mkdir_p($directory) ) {
			@mkdir($directory, 0755, true); // @phpcs:ignore
		}
	}
}
  • Make the change
  • Test under many different permissions and folder structures
  • Add a notification to the back-end to make the missing directories and permissions if the directories does not exist Instead of notifications keep the current way of loading from source gracefully

Metadata

Metadata

Labels

bugSomething isn't workingfeatureNew feature or request

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions