PHP Класс WPAS_File_Upload

Автор: Julien Liabeuf ([email protected])
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$error_message Store the potential error messages.
$index
$instance object Instance of this class.
$parent_id
$post_id

Открытые методы

Метод Описание
__construct ( )
add_form_enctype ( $post )
add_wrapper_class_admin ( array $classes, array $field ) : array Add a custom class to the upload field wrapper in the admin
attachment_endpoint ( ) : void Add a new rewrite endpoint.
attachment_query_var ( WP_Query $query ) : void Add the attachment query var to the $query object.
can_attach_files ( ) : boolean Check if the current user can attach a file.
create_upload_dir ( string $dir ) : boolean Create the upload directory for a ticket.
custom_mime_types ( array $mimes ) : array Add the custom file types to the WordPress whitelist
delete_attachments ( integer $post_id ) : void Delete post attachments.
filter_attachments_out ( array $clauses, WP_Query $wp_query ) : array Filter out tickets and ticket replies attachments
get_allowed_filetypes ( )
get_attachments ( integer $post_id ) : array Get post attachments.
get_instance ( ) : object Return an instance of this class.
has_attachments ( integer $post_id ) : boolean Check if post has attachments.
human_filesize ( integer $bytes, integer $decimals = 2 ) : string Human readable filesize.
individualize_files ( ) : boolean Individualize uploaded files.
limit_upload ( array $file ) : array Limit upload filetypes.
new_reply_attachment ( integer $reply_id ) : void Process upload on new reply creation.
new_reply_backend_attachment ( integer $reply_id ) : void Process upload on new reply creation.
new_ticket_attachment ( integer $ticket_id ) : void Process upload on new ticket creation.
process_upload ( ) : boolean Process the upload.
redirect_error ( string $location ) : string Change the redirection URL.
set_upload_dir ( array $upload ) : string Set upload directory.
show_attachments ( integer $post_id ) : void Show ticket attachments.
upload_field ( ) : void Add dropzone markup.
view_attachment ( ) : void Display the attachment.

Защищенные методы

Метод Описание
protect_upload_dir ( string $dir ) : void Protects an upload directory by adding an .htaccess file

Описание методов

__construct() публичный Метод

public __construct ( )

add_form_enctype() публичный Метод

public add_form_enctype ( $post )

add_wrapper_class_admin() публичный Метод

Add a custom class to the upload field wrapper in the admin
С версии: 3.2.10
public add_wrapper_class_admin ( array $classes, array $field ) : array
$classes array Field wrapper classes
$field array Field parameters
Результат array

attachment_endpoint() публичный Метод

Add a new rewrite endpoint.
С версии: 3.2.0
public attachment_endpoint ( ) : void
Результат void

attachment_query_var() публичный Метод

This is used as a fallback for when pretty permalinks are not enabled.
С версии: 3.2.0
public attachment_query_var ( WP_Query $query ) : void
$query WP_Query The WordPress main query
Результат void

can_attach_files() публичный Метод

Check if the current user can attach a file.
С версии: 3.0.0
public can_attach_files ( ) : boolean
Результат boolean True if the user has the capability, false otherwise

create_upload_dir() публичный Метод

Create the upload directory for a ticket.
С версии: 3.1.7
public create_upload_dir ( string $dir ) : boolean
$dir string Upload directory
Результат boolean Whether or not the directory was created

custom_mime_types() публичный Метод

Add the custom file types to the WordPress whitelist
С версии: 3.2
public custom_mime_types ( array $mimes ) : array
$mimes array Allowed mime types
Результат array Our custom mime types list

delete_attachments() публичный Метод

Delete all post attachments if a ticket is deleted.
С версии: 3.0.0
public delete_attachments ( integer $post_id ) : void
$post_id integer ID of the post to be deleted
Результат void

filter_attachments_out() публичный Метод

Tickets attachments don't have their place in the media library. The library can quickly become a huge mess and it becomes impossible to work with actual post attachments.
С версии: 3.3
public filter_attachments_out ( array $clauses, WP_Query $wp_query ) : array
$clauses array SQL query clauses
$wp_query WP_Query WordPress query object
Результат array

get_allowed_filetypes() публичный Метод

get_attachments() публичный Метод

Get the attachments for a specific ticket or reply.
С версии: 3.0.0
public get_attachments ( integer $post_id ) : array
$post_id integer ID of the post to get attachment for
Результат array Array of attachments or empty array if no attachments are found

get_instance() публичный статический Метод

Return an instance of this class.
С версии: 1.0.0
public static get_instance ( ) : object
Результат object A single instance of this class.

has_attachments() публичный Метод

Check if a specific ticket or reply has attachments. This method is based on get_attachments() and only returns a boolean value based on the returned array being empty or not.
С версии: 3.0.0
public has_attachments ( integer $post_id ) : boolean
$post_id integer ID of the post to get attachment for
Результат boolean True if the ticket has attachments, false otherwise

human_filesize() публичный Метод

Transform the file size into a readable format including the size unit.
С версии: 3.0.0
public human_filesize ( integer $bytes, integer $decimals = 2 ) : string
$bytes integer Filesize in bytes
$decimals integer Number of decimals to show
Результат string Human readable filesize

individualize_files() публичный Метод

If multiple files were uploaded we need to separate each file in a separate array in the $_FILE array in order to let WordPress process them one by one.
С версии: 3.0.0
public individualize_files ( ) : boolean
Результат boolean Whether or not files were individualized

limit_upload() публичный Метод

Gets the list of allowed file extensions from the plugin settings and compare the processed file. If the extension is not in the list we simply return an error message to prevent uploading it.
С версии: 3.0.0
public limit_upload ( array $file ) : array
$file array Currently processed file details
Результат array File details with a possible error message

new_reply_attachment() публичный Метод

Process upload on new reply creation.
С версии: 3.0.0
public new_reply_attachment ( integer $reply_id ) : void
$reply_id integer New reply ID
Результат void

new_reply_backend_attachment() публичный Метод

Process upload on new reply creation.
С версии: 3.0.0
public new_reply_backend_attachment ( integer $reply_id ) : void
$reply_id integer New reply ID
Результат void

new_ticket_attachment() публичный Метод

Process upload on new ticket creation.
С версии: 3.0.0
public new_ticket_attachment ( integer $ticket_id ) : void
$ticket_id integer New ticket ID
Результат void

process_upload() публичный Метод

We delegate the upload process to WordPress. Why reinvent the wheel? The only thing we do change is the upload path. For the rest it's all standard.
С версии: 3.0.0
public process_upload ( ) : boolean
Результат boolean Whether or not the upload has been processed

protect_upload_dir() защищенный Метод

Protects an upload directory by adding an .htaccess file
С версии: 3.1.7
protected protect_upload_dir ( string $dir ) : void
$dir string Upload directory
Результат void

redirect_error() публичный Метод

In case the upload fails we want to notify the user. We change the redirection URL and integrate a custom message encoded in base64 that will be interpreted by the notification class.
С версии: 3.0.0
public redirect_error ( string $location ) : string
$location string Original redirection URL
Результат string New redirection URL

set_upload_dir() публичный Метод

Set a custom upload directory in order to properly separate WordPress uploads and tickets attachments.
С версии: 3.0.0
public set_upload_dir ( array $upload ) : string
$upload array Initial upload directory
Результат string Upload directory

show_attachments() публичный Метод

Displays a ticket or reply attachments.
С версии: 3.0.0
public show_attachments ( integer $post_id ) : void
$post_id integer ID of the post to get attachment for
Результат void

upload_field() публичный Метод

Add dropzone markup.
public upload_field ( ) : void
Результат void

view_attachment() публичный Метод

Uses the new rewrite endpoint to get an attachment ID and display the attachment if the currently logged in user has the authorization to.
С версии: 3.2.0
public view_attachment ( ) : void
Результат void

Описание свойств

$error_message защищенное свойство

Store the potential error messages.
protected $error_message

$index защищенное свойство

protected $index

$instance защищенное статическое свойство

Instance of this class.
С версии: 1.0.0
protected static object $instance
Результат object

$parent_id защищенное свойство

protected $parent_id

$post_id защищенное свойство

protected $post_id