WP_Filesystem_Direct::put_contents( string $file, string $contents, int|false $mode = false ): bool
- Since
- 2.5.0
- Source
wp-admin/includes/class-wp-filesystem-direct.php:68
Writes a string to a file.
Parameters
$filestring- Remote path to the file where to write the data.
$contentsstring- The data to write.
$modeint|falseoptional- The file permissions as octal number, usually 0644. Default false.Default:
false
Return
bool- True on success, false on failure.
Uses · 3
- mbstring_binary_safe_encoding()Sets the mbstring internal encoding to a binary safe encoding when func_overload is enabled.
- reset_mbstring_encoding()Resets the mbstring internal encoding to a users previously set encoding.
- WP_Filesystem_Direct::chmod()Changes filesystem permissions.
Source
public function put_contents( $file, $contents, $mode = false ) { $fp = @fopen( $file, 'wb' ); if ( ! $fp ) { return false; } mbstring_binary_safe_encoding(); $data_length = strlen( $contents ); $bytes_written = fwrite( $fp, $contents ); reset_mbstring_encoding(); fclose( $fp ); if ( $data_length !== $bytes_written ) { return false; } $this->chmod( $file, $mode ); return true; }History
Introduced in 2.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-admin/includes/class-wp-filesystem-direct.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.