WP_Filesystem_Direct::chmod( string $file, int|false $mode = false, bool $recursive = false ): bool

Changes filesystem permissions.

Parameters

$filestringrequired
Path to the file.
$modeint|falseoptional
The permissions as octal number, usually 0644 for files, 0755 for directories.

Default:false

$recursivebooloptional
If set to true, changes file permissions recursively.

Default:false

Return

bool True on success, false on failure.

Source

public function chmod( $file, $mode = false, $recursive = false ) {
	if ( ! $mode ) {
		if ( $this->is_file( $file ) ) {
			$mode = FS_CHMOD_FILE;
		} elseif ( $this->is_dir( $file ) ) {
			$mode = FS_CHMOD_DIR;
		} else {
			return false;
		}
	}

	if ( ! $recursive || ! $this->is_dir( $file ) ) {
		return chmod( $file, $mode );
	}

	// Is a directory, and we want recursive.
	$file     = trailingslashit( $file );
	$filelist = $this->dirlist( $file );

	foreach ( (array) $filelist as $filename => $filemeta ) {
		$this->chmod( $file . $filename, $mode, $recursive );
	}

	return true;
}

Changelog

VersionDescription
2.5.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    There must be a way to disable this. The server’s umask is correctly configured and this is useless work and in default configuration makes WordPress less secure. Trust the admin. umask is there for a reason. And besides that, umask can be set by php, which is much more efficient and more secure than chmod’ing everything after the fact.

You must log in before being able to contribute a note or feedback.