optionsframework_uploader

The SKT Parallaxme optionsframework uploader function.

Description

optionsframework_uploader( $_id, $_value, (string) $_desc = '', (string) $_name = '' ); 

Parameters (4)

0. $id
The id.
1. $value
The value.
2. $desc — Optional. (string) => ''
The desc.
3. $name — Optional. (string) => ''
The name.

Usage

  1. if ( !function_exists( 'optionsframework_uploader' ) ) { 
  2. require_once '/inc/options-media-uploader.php'; 
  3.  
  4. // The id. 
  5. $id = null; 
  6.  
  7. // The value. 
  8. $value = null; 
  9.  
  10. // The desc. 
  11. $desc = ''; 
  12.  
  13. // The name. 
  14. $name = ''; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = optionsframework_uploader($id, $value, $desc, $name); 
  18.  

Defined (1)

The function is defined in the following location(s).

/inc/options-media-uploader.php  
  1. function optionsframework_uploader( $_id, $_value, $_desc = '', $_name = '' ) { 
  2.  
  3. $optionsframework_settings = get_option( 'optionsframework' ); 
  4.  
  5. // Gets the unique option id 
  6. if ( isset( $optionsframework_settings['id'] ) ) { 
  7. $option_name = $optionsframework_settings['id']; 
  8. else { 
  9. $option_name = 'options_framework_theme'; 
  10. }; 
  11.  
  12. $output = ''; 
  13. $id = ''; 
  14. $class = ''; 
  15. $int = ''; 
  16. $value = ''; 
  17. $name = ''; 
  18.  
  19. $id = strip_tags( strtolower( $_id ) ); 
  20.  
  21. // If a value is passed and we don't have a stored value, use the value that's passed through. 
  22. if ( $_value != '' && $value == '' ) { 
  23. $value = $_value; 
  24.  
  25. if ( $_name != '' ) { 
  26. $name = $_name; 
  27. else { 
  28. $name = $option_name.'['.$id.']'; 
  29.  
  30. if ( $value ) { 
  31. $class = ' has-file'; 
  32. $output .= '<input id="' . $id . '" class="upload' . $class . '" type="text" name="'.$name.'" value="' . $value . '" placeholder="' . __('No file chosen', 'options_framework_theme') .'" />' . "\n"; 
  33. if ( function_exists( 'wp_enqueue_media' ) ) { 
  34. if ( ( $value == '' ) ) { 
  35. $output .= '<input id="upload-' . $id . '" class="upload-button button" type="button" value="' . __( 'Upload', 'options_framework_theme' ) . '" />' . "\n"; 
  36. } else { 
  37. $output .= '<input id="remove-' . $id . '" class="remove-file button" type="button" value="' . __( 'Remove', 'options_framework_theme' ) . '" />' . "\n"; 
  38. } else { 
  39. $output .= '<p><i>' . __( 'Upgrade your version of WordPress for full media support.', 'options_framework_theme' ) . '</i></p>'; 
  40.  
  41. if ( $_desc != '' ) { 
  42. $output .= '<span class="of-metabox-desc">' . $_desc . '</span>' . "\n"; 
  43.  
  44. $output .= '<div class="screenshot" id="' . $id . '-image">' . "\n"; 
  45.  
  46. if ( $value != '' ) {  
  47. $remove = '<a class="remove-image">Remove</a>'; 
  48. $image = preg_match( '/(^.*\.jpg|jpeg|png|gif|ico*)/i', $value ); 
  49. if ( $image ) { 
  50. $output .= '<img src="' . $value . '" alt="" />'.$remove.''; 
  51. } else { 
  52. $parts = explode( "/", $value ); 
  53. for( $i = 0; $i < sizeof( $parts ); ++$i ) { 
  54. $title = $parts[$i]; 
  55.  
  56. // No output preview if it's not an image.  
  57. $output .= ''; 
  58.  
  59. // Standard generic output if it's not an image.  
  60. $title = __( 'View File', 'options_framework_theme' ); 
  61. $output .= '<div class="no-image"><span class="file_link"><a href="' . $value . '" target="_blank" rel="external">'.$title.'</a></span></div>'; 
  62. }  
  63. $output .= '</div>' . "\n"; 
  64. return $output;