WP_Filesystem_Direct::put_contents() public WP 2.5.0
Writes a string to a file.
{} Это метод класса: WP_Filesystem_Direct{}
Хуков нет.
Возвращает
true/false. True on success, false on failure.
Использование
$WP_Filesystem_Direct = new WP_Filesystem_Direct(); $WP_Filesystem_Direct->put_contents( $file, $contents, $mode );
- $file(строка) (обязательный)
- Remote path to the file where to write the data.
- $contents(строка) (обязательный)
- The data to write.
- $mode(число/false)
- The file permissions as octal number, usually 0644.
По умолчанию: false
Список изменений
С версии 2.5.0 | Введена. |
Код WP_Filesystem_Direct::put_contents() WP Filesystem Direct::put contents WP 5.6.2
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;
}