Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/10quality/wp-file
Wordpress File class library that mimics PHP file functionality but uses Wordpress standardized functions. Ideal for theme approval check.
https://github.com/10quality/wp-file
Last synced: 5 days ago
JSON representation
Wordpress File class library that mimics PHP file functionality but uses Wordpress standardized functions. Ideal for theme approval check.
- Host: GitHub
- URL: https://github.com/10quality/wp-file
- Owner: 10quality
- License: mit
- Created: 2016-09-21T18:10:49.000Z (about 8 years ago)
- Default Branch: v1.0
- Last Pushed: 2023-01-05T16:00:10.000Z (almost 2 years ago)
- Last Synced: 2024-08-10T11:17:29.585Z (3 months ago)
- Language: PHP
- Size: 10.7 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WordPress File (wrapper class)
[![Latest Stable Version](https://poser.pugx.org/10quality/wp-file/v/stable)](https://packagist.org/packages/10quality/wp-file)
[![Total Downloads](https://poser.pugx.org/10quality/wp-file/downloads)](https://packagist.org/packages/10quality/wp-file)
[![License](https://poser.pugx.org/10quality/wp-file/license)](https://packagist.org/packages/10quality/wp-file)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.## Installation
### With composer
Make the dependecy required in your project:
```bash
composer require 10quality/wp-file
```### Alternative
Download or clone the project and load the class with php functions:
```php
require_once '[PATH TO CLASS]/File.php';
```## Usage
The following example will let you see how to use the class:
Code to replace
```php
$filename = __DIR__.'/myfile.txt';$file = @fopen( $filename, ,'w+' );
$content = fread( $file );
fwrite( $file, $content );
fclose($file);
```Replacement:
```php
use TenQuality\WP\File;$filename = __DIR__.'/myfile.txt';
$content = File::auth()->read( $filename );
File::auth()->write( $filename, $content );
```### Authentication
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:
```php
File::auth( $url )->read( $filename );
```### Other methods
```php
// Returns bool
$isFile = File::auth()->is_file( $filename );
// Returns bool
$fileExists = File::auth()->exists( $filename );
```### Folder or Path handling
Methods to handle files:
```php
$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 );
```### Recomendations
Store your files in the `uploads` folder.
## Coding guidelines
PSR-4.
## LICENSE
The MIT License (MIT)
Copyright (c) 2016 [10Quality](http://www.10quality.com).