PHP Class WPAS_File_Upload

Author: Julien Liabeuf ([email protected])
Afficher le fichier Open project: awesome-support/awesome-support Class Usage Examples

Protected Properties

Свойство Type Description
$error_message Store the potential error messages.
$index
$instance object Instance of this class.
$parent_id
$post_id

Méthodes publiques

Méthode Description
__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.

Méthodes protégées

Méthode Description
protect_upload_dir ( string $dir ) : void Protects an upload directory by adding an .htaccess file

Method Details

__construct() public méthode

public __construct ( )

add_form_enctype() public méthode

public add_form_enctype ( $post )

add_wrapper_class_admin() public méthode

Add a custom class to the upload field wrapper in the admin
Since: 3.2.10
public add_wrapper_class_admin ( array $classes, array $field ) : array
$classes array Field wrapper classes
$field array Field parameters
Résultat array

attachment_endpoint() public méthode

Add a new rewrite endpoint.
Since: 3.2.0
public attachment_endpoint ( ) : void
Résultat void

attachment_query_var() public méthode

This is used as a fallback for when pretty permalinks are not enabled.
Since: 3.2.0
public attachment_query_var ( WP_Query $query ) : void
$query WP_Query The WordPress main query
Résultat void

can_attach_files() public méthode

Check if the current user can attach a file.
Since: 3.0.0
public can_attach_files ( ) : boolean
Résultat boolean True if the user has the capability, false otherwise

create_upload_dir() public méthode

Create the upload directory for a ticket.
Since: 3.1.7
public create_upload_dir ( string $dir ) : boolean
$dir string Upload directory
Résultat boolean Whether or not the directory was created

custom_mime_types() public méthode

Add the custom file types to the WordPress whitelist
Since: 3.2
public custom_mime_types ( array $mimes ) : array
$mimes array Allowed mime types
Résultat array Our custom mime types list

delete_attachments() public méthode

Delete all post attachments if a ticket is deleted.
Since: 3.0.0
public delete_attachments ( integer $post_id ) : void
$post_id integer ID of the post to be deleted
Résultat void

filter_attachments_out() public méthode

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.
Since: 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
Résultat array

get_allowed_filetypes() public méthode

get_attachments() public méthode

Get the attachments for a specific ticket or reply.
Since: 3.0.0
public get_attachments ( integer $post_id ) : array
$post_id integer ID of the post to get attachment for
Résultat array Array of attachments or empty array if no attachments are found

get_instance() public static méthode

Return an instance of this class.
Since: 1.0.0
public static get_instance ( ) : object
Résultat object A single instance of this class.

has_attachments() public méthode

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.
Since: 3.0.0
public has_attachments ( integer $post_id ) : boolean
$post_id integer ID of the post to get attachment for
Résultat boolean True if the ticket has attachments, false otherwise

human_filesize() public méthode

Transform the file size into a readable format including the size unit.
public human_filesize ( integer $bytes, integer $decimals = 2 ) : string
$bytes integer Filesize in bytes
$decimals integer Number of decimals to show
Résultat string Human readable filesize

individualize_files() public méthode

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.
Since: 3.0.0
public individualize_files ( ) : boolean
Résultat boolean Whether or not files were individualized

limit_upload() public méthode

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.
Since: 3.0.0
public limit_upload ( array $file ) : array
$file array Currently processed file details
Résultat array File details with a possible error message

new_reply_attachment() public méthode

Process upload on new reply creation.
Since: 3.0.0
public new_reply_attachment ( integer $reply_id ) : void
$reply_id integer New reply ID
Résultat void

new_reply_backend_attachment() public méthode

Process upload on new reply creation.
Since: 3.0.0
public new_reply_backend_attachment ( integer $reply_id ) : void
$reply_id integer New reply ID
Résultat void

new_ticket_attachment() public méthode

Process upload on new ticket creation.
Since: 3.0.0
public new_ticket_attachment ( integer $ticket_id ) : void
$ticket_id integer New ticket ID
Résultat void

process_upload() public méthode

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.
Since: 3.0.0
public process_upload ( ) : boolean
Résultat boolean Whether or not the upload has been processed

protect_upload_dir() protected méthode

Protects an upload directory by adding an .htaccess file
Since: 3.1.7
protected protect_upload_dir ( string $dir ) : void
$dir string Upload directory
Résultat void

redirect_error() public méthode

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.
Since: 3.0.0
public redirect_error ( string $location ) : string
$location string Original redirection URL
Résultat string New redirection URL

set_upload_dir() public méthode

Set a custom upload directory in order to properly separate WordPress uploads and tickets attachments.
Since: 3.0.0
public set_upload_dir ( array $upload ) : string
$upload array Initial upload directory
Résultat string Upload directory

show_attachments() public méthode

Displays a ticket or reply attachments.
Since: 3.0.0
public show_attachments ( integer $post_id ) : void
$post_id integer ID of the post to get attachment for
Résultat void

upload_field() public méthode

Add dropzone markup.
public upload_field ( ) : void
Résultat void

view_attachment() public méthode

Uses the new rewrite endpoint to get an attachment ID and display the attachment if the currently logged in user has the authorization to.
Since: 3.2.0
public view_attachment ( ) : void
Résultat void

Property Details

$error_message protected_oe property

Store the potential error messages.
protected $error_message

$index protected_oe property

protected $index

$instance protected_oe static_oe property

Instance of this class.
Since: 1.0.0
protected static object $instance
Résultat object

$parent_id protected_oe property

protected $parent_id

$post_id protected_oe property

protected $post_id