|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This is used by addons to add cool stuff to the settings modal as an additional tab |
|
4
|
|
|
* |
|
5
|
|
|
* Example: |
|
6
|
|
|
* add_filter('lasso_modal_tabs', 'try_tabs'); |
|
7
|
|
|
* function try_tabs( $tabs ){ |
|
8
|
|
|
* $tabs[] = array( |
|
9
|
|
|
* 'name' => 'Tab', |
|
10
|
|
|
* 'content' => 'mytestcallback', |
|
11
|
|
|
* 'options' => 'myOptionsCallback' |
|
12
|
|
|
* ); |
|
13
|
|
|
* |
|
14
|
|
|
* return $tabs; |
|
15
|
|
|
* } |
|
16
|
|
|
* function myOptionsCallback(){ |
|
17
|
|
|
* |
|
18
|
|
|
* $options = array( |
|
19
|
|
|
* array( |
|
20
|
|
|
* 'id' => 'title', |
|
21
|
|
|
* 'name' => 'Title', |
|
22
|
|
|
* 'type' => 'text', |
|
23
|
|
|
* 'default' => 'default', |
|
24
|
|
|
* 'desc' => 'Cool' |
|
25
|
|
|
* ), |
|
26
|
|
|
* array( |
|
27
|
|
|
* 'id' => 'another', |
|
28
|
|
|
* 'name' => 'Another', |
|
29
|
|
|
* 'type' => 'textarea', |
|
30
|
|
|
* 'default' => 'default', |
|
31
|
|
|
* 'desc' => 'Awesome' |
|
32
|
|
|
* ) |
|
33
|
|
|
* ); |
|
34
|
|
|
* |
|
35
|
|
|
* return $options; |
|
36
|
|
|
* |
|
37
|
|
|
* } |
|
38
|
|
|
* |
|
39
|
|
|
* @since 0.9.4 |
|
40
|
|
|
*/ |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Get an array of addon data for the settings modal |
|
44
|
|
|
* @since 0.9.4 |
|
45
|
|
|
*/ |
|
46
|
|
|
function lasso_get_modal_tabs(){ |
|
47
|
|
|
|
|
48
|
|
|
$tabs = array(); |
|
49
|
|
|
|
|
50
|
|
|
return apply_filters('lasso_modal_tabs', $tabs); |
|
51
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Build a side tabs to fit alongside the post settings modal |
|
56
|
|
|
* This is used by addons to add cool stuff to the settings modal as an additional tab |
|
57
|
|
|
* |
|
58
|
|
|
* @param $type string tab or content |
|
59
|
|
|
* @uses lasso_get_modal_tabs() |
|
60
|
|
|
* @uses lasso_modal_addons_content() |
|
61
|
|
|
* @since 0.9.4 |
|
62
|
|
|
*/ |
|
63
|
|
|
function lasso_modal_addons( $type = 'tab' ){ |
|
64
|
|
|
|
|
65
|
|
|
$tabs = lasso_get_modal_tabs(); |
|
66
|
|
|
$out = ''; |
|
67
|
|
|
|
|
68
|
|
|
if ( $tabs ): |
|
69
|
|
|
|
|
70
|
|
|
if ( 'tab' == $type ) { |
|
71
|
|
|
|
|
72
|
|
|
$out = '<ul class="lasso--modal__tabs">'; |
|
73
|
|
|
|
|
74
|
|
|
$out .= '<li class="active-tab" data-addon-name="core">Editus</li>'; |
|
75
|
|
|
|
|
76
|
|
|
foreach ( $tabs as $tab ) { |
|
77
|
|
|
|
|
78
|
|
|
if ( isset( $tab ) ) { |
|
79
|
|
|
|
|
80
|
|
|
$out .= lasso_modal_addons_content( $tab, $type ); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$out .= '</ul>'; |
|
85
|
|
|
|
|
86
|
|
|
} elseif ( 'content' == $type ) { |
|
87
|
|
|
foreach ( $tabs as $tab ) { |
|
88
|
|
|
|
|
89
|
|
|
if ( isset( $tab ) ) { |
|
90
|
|
|
$out .= lasso_modal_addons_content( $tab , $type ); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
endif; |
|
97
|
|
|
|
|
98
|
|
|
return !empty( $out ) ? $out : false; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Build a post meta options form |
|
103
|
|
|
* |
|
104
|
|
|
* @param $name string the name of this tab being logged |
|
105
|
|
|
* @param $options array an array of option fields in the format below |
|
106
|
|
|
* |
|
107
|
|
|
* array( |
|
108
|
|
|
* 'id' => 'title', |
|
109
|
|
|
* 'name' => 'Title', |
|
110
|
|
|
* 'type' => 'text', |
|
111
|
|
|
* 'default' => 'default', |
|
112
|
|
|
* 'desc' => 'My description' |
|
113
|
|
|
* ) |
|
114
|
|
|
* |
|
115
|
|
|
* @since 0.9.5 |
|
116
|
|
|
* @subpackage lasso_modal_addons_content |
|
117
|
|
|
*/ |
|
118
|
|
|
function lasso_option_form( $name = '', $options = array() ){ |
|
119
|
|
|
|
|
120
|
|
|
ob_start(); |
|
121
|
|
|
|
|
122
|
|
|
if ( empty( $name ) || empty( $options ) || !is_array( $options ) ) |
|
123
|
|
|
return; |
|
124
|
|
|
|
|
125
|
|
|
$nonce = wp_create_nonce('lasso-process-post-meta'); |
|
126
|
|
|
$key = sprintf('_lasso_%s_settings', $name ); |
|
127
|
|
|
|
|
128
|
|
|
$out = sprintf('<form id="lasso--post-form" class="lasso--post-form">' ); |
|
129
|
|
|
|
|
130
|
|
|
$out .= lasso_option_fields( $name, $options ); |
|
131
|
|
|
$out .='<div class="form--bottom">'; |
|
132
|
|
|
$out .='<input type="submit" value="'.__( 'Save', 'lasso' ).'">'; |
|
133
|
|
|
$out .='<input type="hidden" name="tab_name" value="'.$key.'">'; |
|
134
|
|
|
$out .='<input type="hidden" name="post_id" value="'.get_the_ID().'">'; |
|
135
|
|
|
$out .='<input type="hidden" name="nonce" value="'.$nonce.'">'; |
|
136
|
|
|
$out .='<input type="hidden" name="action" value="process_meta_update">'; |
|
137
|
|
|
$out .='</div>'; |
|
138
|
|
|
|
|
139
|
|
|
$out .= '</form>'; |
|
140
|
|
|
|
|
141
|
|
|
$out .= "<script>(function( $ ) { |
|
142
|
|
|
$(document).ready(function(){ |
|
143
|
|
|
|
|
144
|
|
|
function imgCustomTabDialog( ){ |
|
145
|
|
|
var that = this; |
|
146
|
|
|
|
|
147
|
|
|
// Create the media frame. |
|
148
|
|
|
var lasso_file_frame = wp.media.frames.file_frame = wp.media({ |
|
149
|
|
|
title: 'Select Image', |
|
150
|
|
|
button: { |
|
151
|
|
|
text: 'Insert Image', |
|
152
|
|
|
}, |
|
153
|
|
|
multiple: false // Set to true to allow multiple files to be selected |
|
154
|
|
|
}); |
|
155
|
|
|
|
|
156
|
|
|
// When an image is selected, run a callback. |
|
157
|
|
|
lasso_file_frame.on( 'select', function() { |
|
158
|
|
|
var attachment = lasso_file_frame.state().get('selection').first().toJSON(); |
|
159
|
|
|
$(that).parent().find('input').val(attachment.url ); |
|
160
|
|
|
$(that).parent().find('img').attr('src', attachment.url ); |
|
161
|
|
|
|
|
162
|
|
|
}); |
|
163
|
|
|
|
|
164
|
|
|
// Finally, open the modal |
|
165
|
|
|
lasso_file_frame.open(); |
|
166
|
|
|
}; |
|
167
|
|
|
|
|
168
|
|
|
function imgCustomTabRemove( ){ |
|
169
|
|
|
$(this).parent().find('input').val(''); |
|
170
|
|
|
$(this).parent().find('img').attr('src', '' ); |
|
171
|
|
|
}; |
|
172
|
|
|
|
|
173
|
|
|
jQuery('.editus-customtab-image-control').mousedown(imgCustomTabDialog); |
|
174
|
|
|
jQuery('.editus-customtab-image-remove').mousedown(imgCustomTabRemove); |
|
175
|
|
|
}); |
|
176
|
|
|
})( jQuery ); |
|
177
|
|
|
|
|
178
|
|
|
|
|
179
|
|
|
</script>"; |
|
180
|
|
|
|
|
181
|
|
|
echo $out; |
|
182
|
|
|
|
|
183
|
|
|
return ob_get_clean(); |
|
184
|
|
|
|
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Build settings fields for lasso_option_form |
|
189
|
|
|
* |
|
190
|
|
|
* @param $name string the name of this tab being logged |
|
191
|
|
|
* @param $options array an array of option fields in the format above |
|
192
|
|
|
* @since 0.9.5 |
|
193
|
|
|
* @subpackage lasso_modal_addons_content |
|
194
|
|
|
*/ |
|
195
|
|
|
function lasso_option_fields( $name = '', $options = array() ){ |
|
196
|
|
|
|
|
197
|
|
|
$out = ''; |
|
198
|
|
|
$before = '<div class="lasso--postsettings__option">'; |
|
199
|
|
|
$after = '</div>'; |
|
200
|
|
|
|
|
201
|
|
|
if ( empty( $name ) || empty( $options ) ) |
|
202
|
|
|
return; |
|
203
|
|
|
|
|
204
|
|
|
foreach ( (array) $options as $option ) { |
|
205
|
|
|
|
|
206
|
|
|
$type = isset( $option['type'] ) ? $option['type'] : 'text'; |
|
207
|
|
|
|
|
208
|
|
|
$out .= sprintf('%s%s%s', $before, lasso_option_engine_option( $name, $option,$type ), $after ); |
|
209
|
|
|
|
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
|
|
213
|
|
|
|
|
214
|
|
|
return $out; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* Build settings inputs for settings fields |
|
220
|
|
|
* |
|
221
|
|
|
* @param $name |
|
222
|
|
|
* @param $option mixed object |
|
223
|
|
|
* @param $type string text, textarea, checkbox, color |
|
224
|
|
|
* @since 5.0 |
|
225
|
|
|
*/ |
|
226
|
|
|
function lasso_option_engine_option( $name = '', $option = '', $type = '') { |
|
|
|
|
|
|
227
|
|
|
|
|
228
|
|
|
if ( empty( $type ) || empty( $option ) ) |
|
229
|
|
|
return; |
|
230
|
|
|
|
|
231
|
|
|
$id = isset( $option['id'] ) ? $option['id'] : false; |
|
232
|
|
|
//$id = $id ? lasso_clean_string( $id ) : false; |
|
233
|
|
|
|
|
234
|
|
|
$desc = isset( $option['desc'] ) ? $option['desc'] : false; |
|
235
|
|
|
|
|
236
|
|
|
$value = get_post_meta( get_the_id(), $option[ 'id' ], true ); |
|
237
|
|
|
|
|
238
|
|
|
switch ( $type ) { |
|
239
|
|
|
case 'text': |
|
240
|
|
|
$out = sprintf('<label for="lasso--post-option-%s">%s</label><input id="lasso--post-option-%s" class="editus-custom-field-text" name="%s" type="text" value="%s">',$id, esc_html( $desc ), $id, $id, $value ); |
|
241
|
|
|
break; |
|
242
|
|
|
case 'textarea': |
|
243
|
|
|
$out = sprintf('<label for="lasso--post-option-%s">%s</label><textarea id="lasso--post-option-%s" name="%s">%s</textarea>',$id, esc_html( $desc ), $id, $id, $value ); |
|
244
|
|
|
break; |
|
245
|
|
|
case 'imgurl': |
|
246
|
|
|
$out = sprintf('<label for="lasso--post-option-%s">%s</label><img src="%s" style="height:80px;"><input id="lasso--post-option-%s" class="editus-custom-field-text" name="%s" type="text" value="%s" style="display:none;"><div title="Replace Image" class="editus-customtab-image-control" style="float:left;"><i class="lasso-icon-image" style="font-size:20px;padding:5px;"></i></div><div title="Remove Image" class="editus-customtab-image-remove" style="float:left;"><i class="lasso-icon-bin2" style="font-size:20px;padding:5px;"></i></div>',$id, esc_html( $desc ), $value, $id, $id, $value ); |
|
247
|
|
|
break; |
|
248
|
|
|
case 'checkbox': |
|
249
|
|
|
$out = sprintf('<label for="lasso--post-option-%s" class="checkbox-control checkbox"><input id="lasso--post-option-%s" type="checkbox" name="%s" class="checkbox"><span class="control-indicator"></span>%s',$id, $id, $id ,esc_html( $desc ) ); |
|
250
|
|
|
break; |
|
251
|
|
|
case 'dropdown': |
|
252
|
|
|
$out = sprintf('<label for="lasso--post-option-%s">%s</label><select id="lasso--post-option-%s" name="%s">',$id, esc_html( $desc ), $id, $id); |
|
253
|
|
|
$options = explode(";", $option['options']); |
|
254
|
|
|
foreach ($options as &$opt) { |
|
255
|
|
|
$opts = explode(":", $opt); |
|
256
|
|
|
if ($opts[0] == $value) { |
|
257
|
|
|
$out .= sprintf('<option value = "%s" selected>%s</option>',$opts[0], $opts[1]); |
|
258
|
|
|
} else { |
|
259
|
|
|
$out .= sprintf('<option value = "%s">%s</option>',$opts[0], $opts[1]); |
|
260
|
|
|
} |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
$out .='</select>'; |
|
264
|
|
|
break; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
return $out; |
|
|
|
|
|
|
268
|
|
|
|
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.