Options_Framework_Media_Uploader

The SKT Photo World Options Framework Media Uploader class.

Defined (1)

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

/inc/includes/class-options-media-uploader.php  
  1. class Options_Framework_Media_Uploader { 
  2.  
  3. /** 
  4. * Initialize the media uploader class 
  5. * @since 1.7.0 
  6. */ 
  7. public function init() { 
  8. add_action( 'admin_enqueue_scripts', array( $this, 'optionsframework_media_scripts' ) ); 
  9.  
  10. /** 
  11. * Media Uploader Using the WordPress Media Library. 
  12. * Parameters: 
  13. * string $_id - A token to identify this field (the name). 
  14. * string $_value - The value of the field, if present. 
  15. * string $_desc - An optional description of the field. 
  16. */ 
  17.  
  18. static function optionsframework_uploader( $_id, $_value, $_desc = '', $_name = '' ) { 
  19.  
  20. // Gets the unique option id 
  21. $options_framework = new Options_Framework; 
  22. $option_name = $options_framework->get_option_name(); 
  23.  
  24. $output = ''; 
  25. $id = ''; 
  26. $class = ''; 
  27. $int = ''; 
  28. $value = ''; 
  29. $name = ''; 
  30.  
  31. $id = strip_tags( strtolower( $_id ) ); 
  32.  
  33. // If a value is passed and we don't have a stored value, use the value that's passed through. 
  34. if ( $_value != '' && $value == '' ) { 
  35. $value = $_value; 
  36.  
  37. if ($_name != '') { 
  38. $name = $_name; 
  39. else { 
  40. $name = $option_name.'['.$id.']'; 
  41.  
  42. if ( $value ) { 
  43. $class = ' has-file'; 
  44. $output .= '<input id="' . $id . '" class="upload' . $class . '" type="text" name="'.$name.'" value="' . $value . '" placeholder="' . __('No file chosen', 'skt-photo-world') .'" />' . "\n"; 
  45. if ( function_exists( 'wp_enqueue_media' ) ) { 
  46. if ( ( $value == '' ) ) { 
  47. $output .= '<input id="upload-' . $id . '" class="upload-button button" type="button" value="' . __( 'Upload', 'skt-photo-world' ) . '" />' . "\n"; 
  48. } else { 
  49. $output .= '<input id="remove-' . $id . '" class="remove-file button" type="button" value="' . __( 'Remove', 'skt-photo-world' ) . '" />' . "\n"; 
  50. } else { 
  51. $output .= '<p><i>' . __( 'Upgrade your version of WordPress for full media support.', 'skt-photo-world' ) . '</i></p>'; 
  52.  
  53. if ( $_desc != '' ) { 
  54. $output .= '<span class="of-metabox-desc">' . $_desc . '</span>' . "\n"; 
  55.  
  56. $output .= '<div class="screenshot" id="' . $id . '-image">' . "\n"; 
  57.  
  58. if ( $value != '' ) { 
  59. $remove = '<a class="remove-image">Remove</a>'; 
  60. $image = preg_match( '/(^.*\.jpg|jpeg|png|gif|ico*)/i', $value ); 
  61. if ( $image ) { 
  62. $output .= '<img src="' . $value . '" alt="" />' . $remove; 
  63. } else { 
  64. $parts = explode( "/", $value ); 
  65. for( $i = 0; $i < sizeof( $parts ); ++$i ) { 
  66. $title = $parts[$i]; 
  67.  
  68. // No output preview if it's not an image. 
  69. $output .= ''; 
  70.  
  71. // Standard generic output if it's not an image. 
  72. $title = __( 'View File', 'skt-photo-world' ); 
  73. $output .= '<div class="no-image"><span class="file_link"><a href="' . $value . '" target="_blank" rel="external">'.$title.'</a></span></div>'; 
  74.  
  75. $output .= '</div>' . "\n"; 
  76. return $output; 
  77.  
  78. /** 
  79. * Enqueue scripts for file uploader 
  80. */ 
  81. function optionsframework_media_scripts( $hook ) { 
  82.  
  83. $menu = Options_Framework_Admin::menu_settings(); 
  84.  
  85. if ( substr( $hook, -strlen( $menu['menu_slug'] ) ) !== $menu['menu_slug'] ) 
  86. return; 
  87.  
  88. if ( function_exists( 'wp_enqueue_media' ) ) 
  89. wp_enqueue_media(); 
  90.  
  91. wp_register_script( 'of-media-uploader', OPTIONS_FRAMEWORK_DIRECTORY .'js/media-uploader.js', array( 'jquery' ), Options_Framework::VERSION ); 
  92. wp_enqueue_script( 'of-media-uploader' ); 
  93. wp_localize_script( 'of-media-uploader', 'optionsframework_l10n', array( 
  94. 'upload' => __( 'Upload', 'skt-photo-world' ),  
  95. 'remove' => __( 'Remove', 'skt-photo-world' ) 
  96. ) );