WP_Filesystem_Direct::mkdir() WordPress Method

The WP_Filesystem_Direct::mkdir() method is used to create a new directory on the filesystem. This is a wrapper for the PHP mkdir() function. The method takes two arguments: the path of the new directory to create, and the permissions to set for the new directory. The default permissions are set to 0755.

WP_Filesystem_Direct::mkdir( string $path, int|false $chmod = false, string|int|false $chown = false, string|int|false $chgrp = false ) #

Creates a directory.


Parameters

$path

(string)(Required)Path for new directory.

$chmod

(int|false)(Optional) The permissions as octal number (or false to skip chmod).

Default value: false

$chown

(string|int|false)(Optional) A user name or number (or false to skip chown).

Default value: false

$chgrp

(string|int|false)(Optional) A group name or number (or false to skip chgrp).

Default value: false


Top ↑

Return

(bool) True on success, false on failure.


Top ↑

Source

File: wp-admin/includes/class-wp-filesystem-direct.php

	public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false ) {
		// Safe mode fails with a trailing slash under certain PHP versions.
		$path = untrailingslashit( $path );

		if ( empty( $path ) ) {
			return false;
		}

		if ( ! $chmod ) {
			$chmod = FS_CHMOD_DIR;
		}

		if ( ! @mkdir( $path ) ) {
			return false;
		}

		$this->chmod( $path, $chmod );

		if ( $chown ) {
			$this->chown( $path, $chown );
		}

		if ( $chgrp ) {
			$this->chgrp( $path, $chgrp );
		}

		return true;
	}


Top ↑

Changelog

Changelog
VersionDescription
2.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.