forked from devinsays/options-framework-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions-media-uploader.php
More file actions
111 lines (88 loc) · 3.26 KB
/
options-media-uploader.php
File metadata and controls
111 lines (88 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* Media Uploader Using the WordPress Media Library.
*
* Parameters:
* - string $_id - A token to identify this field (the name).
* - string $_value - The value of the field, if present.
* - string $_desc - An optional description of the field.
*
*/
if ( ! function_exists( 'optionsframework_uploader' ) ) :
function optionsframework_uploader( $_id, $_value, $_desc = '', $_name = '' ) {
$optionsframework_settings = get_option( 'optionsframework' );
// Gets the unique option id
$option_name = $optionsframework_settings['id'];
$output = '';
$id = '';
$class = '';
$int = '';
$value = '';
$name = '';
$id = strip_tags( strtolower( $_id ) );
// If a value is passed and we don't have a stored value, use the value that's passed through.
if ( $_value != '' && $value == '' ) {
$value = $_value;
}
if ($_name != '') {
$name = $_name;
}
else {
$name = $option_name.'['.$id.']';
}
if ( $value ) {
$class = ' has-file';
}
$output .= '<input id="' . $id . '" class="upload' . $class . '" type="text" name="'.$name.'" value="' . $value . '" placeholder="' . __('No file chosen', 'optionsframework') .'" />' . "\n";
if ( function_exists( 'wp_enqueue_media' ) ) {
if ( ( $value == '' ) ) {
$output .= '<input id="upload-' . $id . '" class="upload-button button" type="button" value="' . __( 'Upload', 'optionsframework' ) . '" />' . "\n";
} else {
$output .= '<input id="remove-' . $id . '" class="remove-file button" type="button" value="' . __( 'Remove', 'optionsframework' ) . '" />' . "\n";
}
} else {
$output .= '<p><i>' . __( 'Upgrade your version of WordPress for full media support.', 'optionsframework' ) . '</i></p>';
}
if ( $_desc != '' ) {
$output .= '<span class="of-metabox-desc">' . $_desc . '</span>' . "\n";
}
$output .= '<div class="screenshot" id="' . $id . '-image">' . "\n";
if ( $value != '' ) {
$remove = '<a class="remove-image">Remove</a>';
$image = preg_match( '/(^.*\.jpg|jpeg|png|gif|ico*)/i', $value );
if ( $image ) {
$output .= '<img src="' . $value . '" alt="" />' . $remove;
} else {
$parts = explode( "/", $value );
for( $i = 0; $i < sizeof( $parts ); ++$i ) {
$title = $parts[$i];
}
// No output preview if it's not an image.
$output .= '';
// Standard generic output if it's not an image.
$title = __( 'View File', 'optionsframework' );
$output .= '<div class="no-image"><span class="file_link"><a href="' . $value . '" target="_blank" rel="external">'.$title.'</a></span></div>';
}
}
$output .= '</div>' . "\n";
return $output;
}
endif;
/**
* Enqueue scripts for file uploader
*/
if ( ! function_exists( 'optionsframework_media_scripts' ) ) :
function optionsframework_media_scripts( $hook ) {
if ( 'appearance_page_options-framework' != $hook )
return;
if ( function_exists( 'wp_enqueue_media' ) )
wp_enqueue_media();
wp_register_script( 'of-media-uploader', OPTIONS_FRAMEWORK_URL .'js/media-uploader.js', array( 'jquery' ) );
wp_enqueue_script( 'of-media-uploader' );
wp_localize_script( 'of-media-uploader', 'optionsframework_l10n', array(
'upload' => __( 'Upload', 'optionsframework' ),
'remove' => __( 'Remove', 'optionsframework' )
) );
}
add_action( 'admin_enqueue_scripts', 'optionsframework_media_scripts' );
endif;