WP_Filesystem_Base::put_contents( string $file, string $contents, int|false $mode = false ): bool

Writes a string to a file.

Parameters

$filestringrequired
Remote path to the file where to write the data.
$contentsstringrequired
The data to write.
$modeint|falseoptional
The file permissions as octal number, usually 0644.

Default:false

Return

bool True on success, false on failure.

Source

public function put_contents( $file, $contents, $mode = false ) {
	return false;
}

Changelog

VersionDescription
2.5.0Introduced.

User Contributed Notes

  1. Skip to note 2 content
    global $wp_filesystem;
    include_once ABSPATH . 'wp-admin/includes/file.php';
    WP_Filesystem();
    
    $content  = 'WordPress: Publish your passion';
    $filepath = '/path/to/file/';
    
    $success = $wp_filesystem->put_contents( $filepath . 'index.txt', $content, FS_CHMOD_FILE );
    
    if ( $success ) {
    	echo 'File created successfully.';
    } else {
    	echo 'Error creating file.';
    }

You must log in before being able to contribute a note or feedback.