WP_Filesystem_Direct::put_contents()
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(int|false)
- The file permissions as octal number, usually 0644.
По умолчанию: false
Список изменений
С версии 2.5.0 | Введена. |
Код WP_Filesystem_Direct::put_contents() WP Filesystem Direct::put contents WP 6.7.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; }