wppaste
WordPress

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:65
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

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 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.