Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/micropackage/filesystem
Wrapper for WordPress' Filesystem for easier file manipulations
https://github.com/micropackage/filesystem
bracketspace composer-library filesystem micropackage wordpress
Last synced: about 1 month ago
JSON representation
Wrapper for WordPress' Filesystem for easier file manipulations
- Host: GitHub
- URL: https://github.com/micropackage/filesystem
- Owner: micropackage
- License: mit
- Created: 2020-01-28T07:09:44.000Z (almost 5 years ago)
- Default Branch: develop
- Last Pushed: 2023-06-23T08:34:23.000Z (over 1 year ago)
- Last Synced: 2024-11-19T13:08:28.108Z (about 1 month ago)
- Topics: bracketspace, composer-library, filesystem, micropackage, wordpress
- Language: PHP
- Homepage:
- Size: 58.6 KB
- Stars: 20
- Watchers: 4
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Filesystem
[![BracketSpace Micropackage](https://img.shields.io/badge/BracketSpace-Micropackage-brightgreen)](https://bracketspace.com)
[![Latest Stable Version](https://poser.pugx.org/micropackage/filesystem/v/stable)](https://packagist.org/packages/micropackage/filesystem)
[![PHP from Packagist](https://img.shields.io/packagist/php-v/micropackage/filesystem.svg)](https://packagist.org/packages/micropackage/filesystem)
[![Total Downloads](https://poser.pugx.org/micropackage/filesystem/downloads)](https://packagist.org/packages/micropackage/filesystem)
[![License](https://poser.pugx.org/micropackage/filesystem/license)](https://packagist.org/packages/micropackage/filesystem)
## 🧬 About Filesystem
This micropackage is a wrapper for WordPress filesystem intended to be used within the `wp-content` directory.
Supports:
- plugins
- must-use plugins
- themes
- custom upload directories
- custom wp-content directoriesThis package will prefix all the relative paths to full paths giving a convinient way to manipulate files.
## 💾 Installation
``` bash
composer require micropackage/filesystem
```## 🕹 Usage
Initializing the Filesystem class from the main plugin/theme file. It just needs a base directory.
```php
use Micropackage\Filesystem\Filesystem;$filesystem = new Filesystem( __DIR__ );
```Using the micropackage to obtain full paths (plugin example).
```php
echo $filesystem->path();
// /var/www/html/wp-content/plugins/my-plugin/echo $filesystem->path( 'src/templates/full-width.php' );
// /var/www/html/wp-content/plugins/my-plugin/src/templates/full-width.php
```Using the micropackage to obtain full URL (plugin example).
```php
echo $filesystem->url();
// https://my.plugin/wp-content/plugins/my-plugin/echo $filesystem->url( 'assets/images/logo.svg' );
// https://my.plugin/wp-content/plugins/my-plugin/assets/images/logo.svg
```Convert image file to base64 URL.
```php
printf( '', $filesystem->image_to_base64( 'assets/images/logo.svg' ) );
//
```On top of that, you can use any method provided by WP_Filesystem class, which includes:
- `get_contents()`
- `exists()`
- `is_file()`, `is_dir()`
- `mkdir()`
- `delete()`
- ...[See all available methods](https://developer.wordpress.org/reference/classes/wp_filesystem_base/#methods)
## 📦 About the Micropackage project
Micropackages - as the name suggests - are micro packages with a tiny bit of reusable code, helpful particularly in WordPress development.
The aim is to have multiple packages which can be put together to create something bigger by defining only the structure.
Micropackages are maintained by [BracketSpace](https://bracketspace.com).
## 📖 Changelog
[See the changelog file](./CHANGELOG.md).
## 📃 License
This software is released under MIT license. See the [LICENSE](./LICENSE) file for more information.