This small class library facilitates file handling for WordPress custom developments, will provide all functionality to meet WordPress' standards.
Features:
- Theme Check ready.
- Easy to use.
Make the dependecy required in your project:
composer require 10quality/wp-file
Download or clone the project and load the class with php functions:
require_once '[PATH TO CLASS]/File.php';
The following example will let you see how to use the class:
Code to replace
$filename = __DIR__.'/myfile.txt';
$file = @fopen( $filename, ,'w+' );
$content = fread( $file );
fwrite( $file, $content );
fclose($file);
Replacement:
use TenQuality\WP\File;
$filename = __DIR__.'/myfile.txt';
$content = File::auth()->read( $filename );
File::auth()->write( $filename, $content );
WordPress will require to authenticate a url in order to validate if filesystem credentials are in place.
If you need to authenticate a specific url, pass it like this:
File::auth( $url )->read( $filename );
// Returns bool
$isFile = File::auth()->is_file( $filename );
// Returns bool
$fileExists = File::auth()->exists( $filename );
Methods to handle files:
$file = File::auth();
// Use is_dir to check if a path exists or not.
if ( $file->is_dir( $path ) )
// Use mkdir to create non-existent paths.
$file->mkdir( $path );
// Use rmdir to remove paths.
$file->rmdir( $path );
Store your files in the uploads
folder.
PSR-4.
The MIT License (MIT)
Copyright (c) 2016 10Quality.