WP_Filesystem_Direct::chown()
Changes the owner of a file or directory.
Method of the class: WP_Filesystem_Direct{}
No Hooks.
Return
true|false
. True on success, false on failure.
Usage
$WP_Filesystem_Direct = new WP_Filesystem_Direct(); $WP_Filesystem_Direct->chown( $file, $owner, $recursive );
- $file(string) (required)
- Path to the file or directory.
- $owner(string|int) (required)
- A user name or number.
- $recursive(true|false)
- If set to true, changes file owner recursively.
Default: false
Changelog
Since 2.5.0 | Introduced. |
WP_Filesystem_Direct::chown() WP Filesystem Direct::chown code WP 6.6.2
public function chown( $file, $owner, $recursive = false ) { if ( ! $this->exists( $file ) ) { return false; } if ( ! $recursive ) { return chown( $file, $owner ); } if ( ! $this->is_dir( $file ) ) { return chown( $file, $owner ); } // Is a directory, and we want recursive. $filelist = $this->dirlist( $file ); foreach ( $filelist as $filename ) { $this->chown( $file . '/' . $filename, $owner, $recursive ); } return true; }