PHP Class RWMB_File_Field

Inheritance: extends RWMB_Field
Show file Open project: rilwis/meta-box Class Usage Examples

Public Methods

Method Description
add_actions ( ) Add custom actions
admin_enqueue_scripts ( ) Enqueue scripts and styles
file_info ( integer $file, array $args = [] ) : array | boolean Get uploaded file information
files_info ( array $field, array $files, array $args ) : array Get uploaded files information
format_single_value ( array $field, array $value ) : string Format a single value for the helper functions.
format_value ( array $field, string | array $value ) : string Format value for the helper functions.
get_value ( array $field, array $args = [], integer | null $post_id = null ) : mixed Get the field value. Return meaningful info of the files.
html ( mixed $meta, array $field ) : string Get field HTML
normalize ( array $field ) : array Normalize parameters for field
post_edit_form_tag ( ) Add data encoding type for file uploading
value ( mixed $new, mixed $old, integer $post_id, array $field ) : array | mixed Get meta values to save
wp_ajax_delete_file ( ) Ajax callback for deleting files.
wp_ajax_reorder_files ( ) Ajax callback for reordering images

Protected Methods

Method Description
file_html ( integer $file ) : string Get HTML for uploaded file.
get_uploaded_files ( array $files, array $field ) : string Get HTML for uploaded files.
transform ( array $files ) : array Transform $_FILES from $_FILES['field']['key']['index'] to $_FILES['field']['index']['key']
upload ( array $file, integer $post ) : integer Handle upload file.

Method Details

add_actions() public static method

Add custom actions
public static add_actions ( )

admin_enqueue_scripts() public static method

Enqueue scripts and styles
public static admin_enqueue_scripts ( )

file_html() protected static method

Get HTML for uploaded file.
protected static file_html ( integer $file ) : string
$file integer Attachment (file) ID
return string

file_info() public static method

Get uploaded file information
public static file_info ( integer $file, array $args = [] ) : array | boolean
$file integer Attachment file ID (post ID). Required.
$args array Array of arguments (for size).
return array | boolean False if file not found. Array of (id, name, path, url) on success

files_info() public static method

Get uploaded files information
public static files_info ( array $field, array $files, array $args ) : array
$field array Field parameter
$files array Files IDs
$args array Additional arguments (for image size)
return array

format_single_value() public static method

Format a single value for the helper functions.
public static format_single_value ( array $field, array $value ) : string
$field array Field parameter
$value array The value
return string

format_value() public static method

Format value for the helper functions.
public static format_value ( array $field, string | array $value ) : string
$field array Field parameter
$value string | array The field meta value
return string

get_uploaded_files() protected static method

Get HTML for uploaded files.
protected static get_uploaded_files ( array $files, array $field ) : string
$files array List of uploaded files
$field array Field parameters
return string

get_value() public static method

Get the field value. Return meaningful info of the files.
public static get_value ( array $field, array $args = [], integer | null $post_id = null ) : mixed
$field array Field parameters
$args array Not used for this field
$post_id integer | null Post ID. null for current post. Optional.
return mixed Full info of uploaded files

html() public static method

Get field HTML
public static html ( mixed $meta, array $field ) : string
$meta mixed
$field array
return string

normalize() public static method

Normalize parameters for field
public static normalize ( array $field ) : array
$field array
return array

post_edit_form_tag() public static method

Add data encoding type for file uploading
public static post_edit_form_tag ( )

transform() protected static method

Transform $_FILES from $_FILES['field']['key']['index'] to $_FILES['field']['index']['key']
protected static transform ( array $files ) : array
$files array
return array

upload() protected static method

Handle upload file.
protected static upload ( array $file, integer $post ) : integer
$file array
$post integer Post parent ID
return integer Attachment ID on success, false on failure.

value() public static method

Get meta values to save
public static value ( mixed $new, mixed $old, integer $post_id, array $field ) : array | mixed
$new mixed
$old mixed
$post_id integer
$field array
return array | mixed

wp_ajax_delete_file() public static method

Modified from a function used by "Verve Meta Boxes" plugin
public static wp_ajax_delete_file ( )

wp_ajax_reorder_files() public static method

Ajax callback for reordering images
public static wp_ajax_reorder_files ( )