Files
in package
Files class
Table of Contents
Properties
- $instance : Files|null
- The single instance of the class.
- $upload_dir : string
- The upload directory.
- $upload_url : string
- The upload directory URL.
Methods
- delete() : void
- Handles the deletion of a CSV file.
- init() : Files
- Gets the single instance of the class.
- upload() : void
- Uploads a CSV file.
- __construct() : mixed
- Constructor.
- handle_csv_upload() : string|WP_Error
- Handles the upload of a CSV file.
Properties
$instance
The single instance of the class.
protected
static Files|null
$instance
= null
$upload_dir
The upload directory.
protected
string
$upload_dir
$upload_url
The upload directory URL.
protected
string
$upload_url
Methods
delete()
Handles the deletion of a CSV file.
public
delete() : void
Checks if the file deletion request is valid and if the user has the capabilities to delete the file. If the file exists, it will be deleted and a success notice will be displayed.
init()
Gets the single instance of the class.
public
static init() : Files
Return values
Files —Single instance of the class.
upload()
Uploads a CSV file.
public
upload() : void
Handles the upload of a CSV file through the admin page.
__construct()
Constructor.
private
__construct() : mixed
Initializes the upload directory and URL.
Tags
handle_csv_upload()
Handles the upload of a CSV file.
private
handle_csv_upload(array<string|int, mixed> $file) : string|WP_Error
Validates the uploaded file for correct type and mime type, and moves it to the upload directory if valid.
Parameters
- $file : array<string|int, mixed>
-
The uploaded file array from $_FILES.
Return values
string|WP_Error —The path to the uploaded file on success, or a WP_Error object on failure.