| 1 |
<?php |
| 2 |
/** |
| 3 |
* Output a text input box. |
| 4 |
* |
| 5 |
* @param array $field |
| 6 |
*/ |
| 7 |
function lp_meta_box_text_input_field( $field ) { |
| 8 |
global $thepostid, $post; |
| 9 |
|
| 10 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 11 |
$field['placeholder'] = esc_attr( $field['placeholder'] ?? '' ); |
| 12 |
$field['class'] = esc_attr( $field['class'] ?? '' ); |
| 13 |
$field['style'] = esc_attr( $field['style'] ?? '' ); |
| 14 |
$wrapper_class = esc_attr( $field['wrapper_class'] ?? '' ); |
| 15 |
|
| 16 |
/** |
| 17 |
* If you want to set default value for input text |
| 18 |
* You must us hook default_{$meta_type}_metadata | Read more get_metadata_default() function |
| 19 |
*/ |
| 20 |
$value_exists = LP_Database::getInstance()->check_key_postmeta_exists( $thepostid, $field['id'] ); |
| 21 |
$value = get_post_meta( $thepostid, $field['id'], true ); |
| 22 |
$field['value'] = $value_exists ? $value : ( $field['default'] ?? '' ); |
| 23 |
$field['id'] = esc_attr( $field['id'] ?? '' ); |
| 24 |
$field['type_input'] = esc_attr( $field['type_input'] ?? 'text' ); |
| 25 |
$field['desc_tip'] = esc_attr( $field['desc_tip'] ?? '' ); |
| 26 |
|
| 27 |
// Custom attribute handling |
| 28 |
$custom_attributes = array(); |
| 29 |
|
| 30 |
if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { |
| 31 |
foreach ( $field['custom_attributes'] as $attribute => $custom_attribute ) { |
| 32 |
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $custom_attribute ) . '"'; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
$custom_attributes_str = implode( ' ', $custom_attributes ); |
| 37 |
?> |
| 38 |
|
| 39 |
<div class="form-field <?php echo esc_attr( $field['id'] . '_field ' . $wrapper_class ); ?>"> |
| 40 |
<label for="<?php echo esc_attr( $field['id'] ); ?>"> |
| 41 |
<?php echo wp_kses_post( $field['label'] ); ?> |
| 42 |
</label> |
| 43 |
<input type="<?php echo esc_attr( $field['type_input'] ); ?>" |
| 44 |
class="<?php echo esc_attr( $field['class'] ); ?>" |
| 45 |
style="<?php echo esc_attr( $field['style'] ); ?>" |
| 46 |
name="<?php echo esc_attr( $field['id'] ); ?>" |
| 47 |
id="<?php echo esc_attr( $field['id'] ); ?>" |
| 48 |
value="<?php echo esc_attr( $field['value'] ); ?>" |
| 49 |
placeholder="<?php echo esc_attr( $field['placeholder'] ); ?>" |
| 50 |
<?php echo learn_press_echo_vuejs_write_on_php( $custom_attributes_str ); ?> /> |
| 51 |
<?php |
| 52 |
if ( ! empty( $field['description'] ) ) { |
| 53 |
echo '<p class="description">'; |
| 54 |
echo '<span>' . wp_kses_post( $field['description'] ) . '</span>'; |
| 55 |
|
| 56 |
if ( ! empty( $field['desc_tip'] ) ) { |
| 57 |
learn_press_quick_tip( $field['desc_tip'] ); |
| 58 |
} |
| 59 |
echo '</p>'; |
| 60 |
} |
| 61 |
?> |
| 62 |
</div> |
| 63 |
<?php |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Output a textarea input box. |
| 68 |
* |
| 69 |
* @param array $field |
| 70 |
*/ |
| 71 |
function lp_meta_box_textarea_field( $field ) { |
| 72 |
global $thepostid, $post; |
| 73 |
|
| 74 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 75 |
$field['id'] = esc_attr( $field['id'] ?? '' ); |
| 76 |
$field['placeholder'] = esc_attr( $field['placeholder'] ?? '' ); |
| 77 |
$field['class'] = esc_attr( $field['class'] ?? 'short' ); |
| 78 |
$field['style'] = esc_attr( $field['style'] ?? '' ); |
| 79 |
$value_exists = LP_Database::getInstance()->check_key_postmeta_exists( $thepostid, $field['id'] ); |
| 80 |
$value = get_post_meta( $thepostid, $field['id'], true ); |
| 81 |
$field['value'] = esc_textarea( $value_exists ? $value : ( $field['default'] ?? '' ) ); |
| 82 |
$field['desc_tip'] = esc_attr( $field['desc_tip'] ?? '' ); |
| 83 |
$field['name'] = esc_attr( $field['name'] ?? $field['id'] ); |
| 84 |
|
| 85 |
// Custom attribute handling |
| 86 |
$custom_attributes = array(); |
| 87 |
if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { |
| 88 |
foreach ( $field['custom_attributes'] as $attribute => $custom_attribute ) { |
| 89 |
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $custom_attribute ) . '"'; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
$custom_attributes_str = implode( ' ', $custom_attributes ); |
| 94 |
?> |
| 95 |
|
| 96 |
<p class="form-field <?php echo esc_attr( $field['id'] . '_field ' ); ?>"> |
| 97 |
<label for="<?php echo esc_attr( $field['id'] ); ?>>"> |
| 98 |
<?php echo wp_kses_post( $field['label'] ); ?> |
| 99 |
</label> |
| 100 |
<textarea class="<?php echo esc_attr( $field['class'] ); ?>" |
| 101 |
style="<?php echo esc_attr( $field['style'] ); ?>" |
| 102 |
name="<?php echo esc_attr( $field['name'] ); ?>" |
| 103 |
id="<?php esc_attr( $field['id'] ); ?>" |
| 104 |
placeholder="<?php echo esc_attr( $field['placeholder'] ); ?>" |
| 105 |
rows="5" <?php echo esc_attr( $custom_attributes_str ); ?>><?php echo wp_kses_post( $field['value'] ); ?></textarea> |
| 106 |
<?php |
| 107 |
if ( ! empty( $field['description'] ) ) { |
| 108 |
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>'; |
| 109 |
|
| 110 |
if ( ! empty( $field['desc_tip'] ) ) { |
| 111 |
learn_press_quick_tip( $field['desc_tip'] ); |
| 112 |
} |
| 113 |
} |
| 114 |
?> |
| 115 |
</p> |
| 116 |
<?php |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* Output a checkbox input box. |
| 121 |
* |
| 122 |
* @param array $field |
| 123 |
*/ |
| 124 |
function lp_meta_box_checkbox_field( $field ) { |
| 125 |
global $thepostid, $post; |
| 126 |
|
| 127 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 128 |
$field['id'] = esc_attr( $field['id'] ?? '' ); |
| 129 |
$field['class'] = esc_attr( $field['class'] ?? '' ); |
| 130 |
$field['style'] = esc_attr( $field['style'] ?? '' ); |
| 131 |
$wrapper_class = esc_attr( $field['wrapper_class'] ?? '' ); |
| 132 |
$name = ! empty( $field['name'] ) ? esc_attr( $field['name'] ) : esc_attr( $field['id'] ); |
| 133 |
|
| 134 |
$value_db = get_post_meta( $thepostid, $field['id'], true ); |
| 135 |
|
| 136 |
$checked = ''; |
| 137 |
if ( 'yes' === $value_db ) { |
| 138 |
$checked = 'checked="checked"'; |
| 139 |
} |
| 140 |
|
| 141 |
// Custom attribute handling |
| 142 |
$custom_attributes = array(); |
| 143 |
if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { |
| 144 |
foreach ( $field['custom_attributes'] as $attribute => $custom_attribute ) { |
| 145 |
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $custom_attribute ) . '"'; |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
$custom_attributes_str = implode( ' ', $custom_attributes ); |
| 150 |
?> |
| 151 |
|
| 152 |
<div class="form-field <?php echo esc_attr( $field['id'] . '_field' . $wrapper_class ); ?>"> |
| 153 |
<label for="<?php echo esc_attr( $field['id'] ); ?>"> |
| 154 |
<?php echo wp_kses_post( $field['label'] ); ?> |
| 155 |
</label> |
| 156 |
|
| 157 |
<input type="checkbox" |
| 158 |
class="<?php echo esc_attr( $field['class'] ); ?>" |
| 159 |
style="<?php echo esc_attr( $field['style'] ); ?>" |
| 160 |
name="<?php echo esc_attr( $name ); ?>" |
| 161 |
id="<?php echo esc_attr( $field['id'] ); ?>" |
| 162 |
<?php learn_press_echo_vuejs_write_on_php( $checked ); ?> |
| 163 |
<?php learn_press_echo_vuejs_write_on_php( $custom_attributes_str ); ?> /> |
| 164 |
|
| 165 |
<?php |
| 166 |
if ( ! empty( $field['description'] ) ) { |
| 167 |
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>'; |
| 168 |
|
| 169 |
if ( ! empty( $field['desc_tip'] ) ) { |
| 170 |
learn_press_quick_tip( $field['desc_tip'] ); |
| 171 |
} |
| 172 |
} |
| 173 |
?> |
| 174 |
</div> |
| 175 |
<?php |
| 176 |
} |
| 177 |
|
| 178 |
/** |
| 179 |
* Output a select input box. |
| 180 |
* |
| 181 |
* @param array $field Data about the field to render. |
| 182 |
*/ |
| 183 |
function lp_meta_box_select_field( $field = array() ) { |
| 184 |
global $thepostid, $post; |
| 185 |
|
| 186 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 187 |
$default = ( ! get_post_meta( |
| 188 |
$thepostid, |
| 189 |
$field['id'], |
| 190 |
true |
| 191 |
) && isset( $field['default'] ) ) ? $field['default'] : get_post_meta( |
| 192 |
$thepostid, |
| 193 |
$field['id'], |
| 194 |
true |
| 195 |
); |
| 196 |
|
| 197 |
$field = wp_parse_args( |
| 198 |
$field, |
| 199 |
array( |
| 200 |
'class' => 'select', |
| 201 |
'style' => '', |
| 202 |
'wrapper_class' => '', // Use "lp-select-2" for select2. |
| 203 |
'value' => isset( $field['value'] ) ? $field['value'] : $default, |
| 204 |
'name' => $field['id'], |
| 205 |
'desc_tip' => false, |
| 206 |
'multiple' => false, |
| 207 |
'custom_attributes' => array(), |
| 208 |
) |
| 209 |
); |
| 210 |
|
| 211 |
$label_attributes = array( |
| 212 |
'for' => $field['id'], |
| 213 |
); |
| 214 |
|
| 215 |
$field_attributes = (array) $field['custom_attributes']; |
| 216 |
$field_attributes['style'] = $field['style'] ?? ''; |
| 217 |
$field_attributes['id'] = $field['id'] ?? ''; |
| 218 |
$field_attributes['name'] = $field['multiple'] ? $field['name'] . '[]' : $field['name']; |
| 219 |
$field_attributes['class'] = $field['class'] ?? ''; |
| 220 |
|
| 221 |
if ( $field['multiple'] ) { |
| 222 |
$field['wrapper_class'] = 'lp-select-2'; |
| 223 |
$field_attributes['multiple'] = true; |
| 224 |
} |
| 225 |
|
| 226 |
$tooltip = ! empty( $field['description'] ) && false !== $field['desc_tip'] ? $field['description'] : ''; |
| 227 |
$description = ! empty( $field['description'] ) && false === $field['desc_tip'] ? $field['description'] : ''; |
| 228 |
?> |
| 229 |
|
| 230 |
<p class="form-field <?php echo esc_attr( $field['id'] . '_field ' . $field['wrapper_class'] ); ?>"> |
| 231 |
<label for="<?php echo esc_attr( $field['id'] ); ?>"><?php echo wp_kses_post( $field['label'] ); ?></label> |
| 232 |
<select <?php echo lp_implode_html_attributes( $field_attributes ); ?>> |
| 233 |
<?php |
| 234 |
foreach ( $field['options'] as $key => $value ) { |
| 235 |
echo '<option value="' . esc_attr( $key ) . '"' . ( is_array( $field['value'] ) ? selected( in_array( (string) $key, $field['value'], true ), true ) : selected( $key, $field['value'], false ) ) . '>' . esc_html( $value ) . '</option>'; |
| 236 |
} |
| 237 |
?> |
| 238 |
</select> |
| 239 |
<?php |
| 240 |
if ( ! empty( $field['description'] ) ) { |
| 241 |
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>'; |
| 242 |
|
| 243 |
if ( ! empty( $field['desc_tip'] ) ) { |
| 244 |
learn_press_quick_tip( $field['desc_tip'] ); |
| 245 |
} |
| 246 |
} |
| 247 |
?> |
| 248 |
</p> |
| 249 |
<?php |
| 250 |
} |
| 251 |
|
| 252 |
/** |
| 253 |
* Output a radio input box. |
| 254 |
* |
| 255 |
* @param array $field |
| 256 |
*/ |
| 257 |
function lp_meta_box_radio_field( $field ) { |
| 258 |
global $thepostid, $post; |
| 259 |
|
| 260 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 261 |
$field['class'] = $field['class'] ?? 'select'; |
| 262 |
$field['style'] = $field['style'] ?? ''; |
| 263 |
$field['wrapper_class'] = $field['wrapper_class'] ?? ''; |
| 264 |
$field['default'] = ( ! get_post_meta( |
| 265 |
$thepostid, |
| 266 |
$field['id'], |
| 267 |
true |
| 268 |
) && isset( $field['default'] ) ) ? $field['default'] : get_post_meta( |
| 269 |
$thepostid, |
| 270 |
$field['id'], |
| 271 |
true |
| 272 |
); |
| 273 |
$field['value'] = $field['value'] ?? $field['default']; |
| 274 |
$field['name'] = $field['name'] ?? $field['id']; |
| 275 |
$field['desc_tip'] = $field['desc_tip'] ?? false; |
| 276 |
|
| 277 |
echo '<fieldset class="form-field ' . esc_attr( $field['id'] . '_field ' . $field['wrapper_class'] ) . '"><h4>' . wp_kses_post( $field['label'] ) . '</h4>'; |
| 278 |
|
| 279 |
if ( ! empty( $field['description'] ) && false !== $field['desc_tip'] ) { |
| 280 |
learn_press_quick_tip( $field['description'] ); |
| 281 |
} |
| 282 |
|
| 283 |
echo '<ul class="lp-radios-field-meta-box">'; |
| 284 |
|
| 285 |
foreach ( $field['options'] as $key => $value ) { |
| 286 |
echo '<li><label><input |
| 287 |
name="' . esc_attr( $field['name'] ) . '" |
| 288 |
value="' . esc_attr( $key ) . '" |
| 289 |
type="radio" |
| 290 |
class="' . esc_attr( $field['class'] ) . '" |
| 291 |
style="' . esc_attr( $field['style'] ) . '" |
| 292 |
' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . ' |
| 293 |
/> ' . ( $value ) . '</label> |
| 294 |
</li>'; |
| 295 |
} |
| 296 |
echo '</ul>'; |
| 297 |
|
| 298 |
if ( ! empty( $field['description'] ) && false === $field['desc_tip'] ) { |
| 299 |
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>'; |
| 300 |
} |
| 301 |
|
| 302 |
echo '</fieldset>'; |
| 303 |
} |
| 304 |
|
| 305 |
function lp_meta_box_file_input_field( $field ) { |
| 306 |
global $thepostid, $post; |
| 307 |
|
| 308 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 309 |
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'short'; |
| 310 |
$field['style'] = isset( $field['style'] ) ? $field['style'] : ''; |
| 311 |
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; |
| 312 |
$field['default'] = ( ! get_post_meta( |
| 313 |
$thepostid, |
| 314 |
$field['id'], |
| 315 |
true |
| 316 |
) && isset( $field['default'] ) ) ? $field['default'] : get_post_meta( |
| 317 |
$thepostid, |
| 318 |
$field['id'], |
| 319 |
true |
| 320 |
); |
| 321 |
$field['value'] = isset( $field['value'] ) ? $field['value'] : $field['default']; |
| 322 |
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; |
| 323 |
$field['mime_type'] = isset( $field['mime_type'] ) ? implode( ',', $field['mime_type'] ) : ''; |
| 324 |
$field['multil'] = ( isset( $field['multil'] ) && $field['multil'] ) ? true : false; |
| 325 |
$field['desc_tip'] = isset( $field['desc_tip'] ) ? $field['desc_tip'] : false; |
| 326 |
|
| 327 |
// Custom attribute handling |
| 328 |
$custom_attributes = array(); |
| 329 |
|
| 330 |
if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { |
| 331 |
foreach ( $field['custom_attributes'] as $attribute => $custom_attribute ) { |
| 332 |
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $custom_attribute ) . '"'; |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
echo '<div class="form-field ' . esc_attr( $field['id'] . '_field ' . $field['wrapper_class'] ) . '"> |
| 337 |
<label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>'; |
| 338 |
|
| 339 |
echo '<div id="' . esc_attr( $field['id'] ) . '" class="lp-meta-box__file ' . esc_attr( $field['class'] ) . '" data-mime="' . $field['mime_type'] . '" data-multil="' . $field['multil'] . '" style="' . esc_attr( $field['style'] ) . '" ' . implode( |
| 340 |
' ', |
| 341 |
$custom_attributes |
| 342 |
) . '>'; |
| 343 |
echo '<ul class="lp-meta-box__file_list">'; |
| 344 |
|
| 345 |
if ( ! empty( $field['value'] ) ) { |
| 346 |
foreach ( (array) $field['value'] as $attachment_id ) { |
| 347 |
$url = wp_get_attachment_url( $attachment_id ); |
| 348 |
|
| 349 |
if ( $url ) { |
| 350 |
$check_file = wp_check_filetype( $url ); |
| 351 |
|
| 352 |
echo '<li class="lp-meta-box__file_list-item image" data-attachment_id="' . $attachment_id . '">'; |
| 353 |
|
| 354 |
if ( in_array( $check_file['ext'], array( 'jpg', 'png', 'gif', 'bmp', 'tif', 'jpeg' ), true ) ) { |
| 355 |
echo wp_get_attachment_image( $attachment_id, 'thumbnail' ); |
| 356 |
} else { |
| 357 |
echo '<img class="is_file" src="' . wp_mime_type_icon( $check_file['type'] ) . '" />'; |
| 358 |
echo '<span>' . wp_basename( get_attached_file( $attachment_id ) ) . '</span>'; |
| 359 |
} |
| 360 |
echo '<ul class="actions"><li><a href="#" class="delete"></a></li></ul>'; |
| 361 |
echo '</li>'; |
| 362 |
} |
| 363 |
} |
| 364 |
} |
| 365 |
|
| 366 |
echo '</ul>'; |
| 367 |
echo '<input class="lp-meta-box__file_input" type="hidden" name="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( |
| 368 |
( ! empty( $field['value'] ) && is_array( $field['value'] ) ) ? implode( |
| 369 |
',', |
| 370 |
$field['value'] |
| 371 |
) : $field['value'] |
| 372 |
) . '" />'; |
| 373 |
echo '<p>'; |
| 374 |
echo '<a href="#" class="button btn-upload">' . esc_html__( '+ Add media', 'learnpress' ) . '</a>'; |
| 375 |
if ( ! empty( $field['description'] ) && false !== $field['desc_tip'] ) { |
| 376 |
learn_press_quick_tip( $field['description'] ); |
| 377 |
} |
| 378 |
echo '</p>'; |
| 379 |
|
| 380 |
if ( ! empty( $field['description'] ) && false === $field['desc_tip'] ) { |
| 381 |
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>'; |
| 382 |
} |
| 383 |
echo '</div>'; |
| 384 |
echo '</div>'; |
| 385 |
} |
| 386 |
|
| 387 |
/** |
| 388 |
* Output a duration input box. |
| 389 |
* |
| 390 |
* @param array $field |
| 391 |
*/ |
| 392 |
function lp_meta_box_duration_field( $field ) { |
| 393 |
global $thepostid, $post; |
| 394 |
|
| 395 |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
| 396 |
$field['placeholder'] = $field['placeholder'] ?? ''; |
| 397 |
$field['class'] = $field['class'] ?? 'short'; |
| 398 |
$field['style'] = $field['style'] ?? ''; |
| 399 |
$field['wrapper_class'] = $field['wrapper_class'] ?? ''; |
| 400 |
$field['default'] = ( ! get_post_meta( |
| 401 |
$thepostid, |
| 402 |
$field['id'], |
| 403 |
true |
| 404 |
) && isset( $field['default'] ) ) ? $field['default'] : get_post_meta( |
| 405 |
$thepostid, |
| 406 |
$field['id'], |
| 407 |
true |
| 408 |
); |
| 409 |
$field['value'] = $field['value'] ?? $field['default']; |
| 410 |
$field['name'] = $field['name'] ?? $field['id']; |
| 411 |
$data_type = empty( $field['data_type'] ) ? '' : $field['data_type']; |
| 412 |
$duration = learn_press_get_course_duration_support(); |
| 413 |
|
| 414 |
$duration_keys = array_keys( $duration ); |
| 415 |
$default_time = ! empty( $field['default_time'] ) ? $field['default_time'] : end( $duration_keys ); |
| 416 |
|
| 417 |
if ( preg_match_all( '!([0-9]+)\s*(' . join( '|', $duration_keys ) . ')?!', $field['value'], $matches ) ) { |
| 418 |
$a1 = $matches[1][0]; |
| 419 |
$a2 = in_array( $matches[2][0], $duration_keys ) ? $matches[2][0] : $default_time; |
| 420 |
} else { |
| 421 |
$a1 = absint( $field['value'] ); |
| 422 |
$a2 = $default_time; |
| 423 |
} |
| 424 |
|
| 425 |
// Custom attribute handling |
| 426 |
$custom_attributes = array(); |
| 427 |
|
| 428 |
if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { |
| 429 |
foreach ( $field['custom_attributes'] as $attribute => $custom_attribute ) { |
| 430 |
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $custom_attribute ) . '"'; |
| 431 |
} |
| 432 |
} |
| 433 |
|
| 434 |
$html_option = ''; |
| 435 |
foreach ( $duration as $k => $v ) { |
| 436 |
$html_option .= sprintf( '<option value="%s" %s>%s</option>', $k, selected( $k, $a2, false ), $v ); |
| 437 |
} |
| 438 |
|
| 439 |
echo '<p class="lp-meta-box__duration form-field ' . esc_attr( $field['id'] . '_field ' . $field['wrapper_class'] ) . '"> |
| 440 |
<label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>'; |
| 441 |
|
| 442 |
echo '<input type="number" class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['name'] ) . '[]" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $a1 ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" ' . implode( |
| 443 |
' ', |
| 444 |
$custom_attributes |
| 445 |
) . ' /> '; |
| 446 |
|
| 447 |
echo '<select name="' . esc_attr( $field['name'] ) . '[]" class="lp-meta-box__duration-select">' . $html_option . '</select>'; |
| 448 |
|
| 449 |
if ( ! empty( $field['description'] ) ) { |
| 450 |
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>'; |
| 451 |
|
| 452 |
if ( ! empty( $field['desc_tip'] ) ) { |
| 453 |
learn_press_quick_tip( $field['desc_tip'] ); |
| 454 |
} |
| 455 |
} |
| 456 |
|
| 457 |
echo '</p>'; |
| 458 |
} |
| 459 |
|
| 460 |
/** |
| 461 |
* Use for Type: custom_fields in LP4. |
| 462 |
* |
| 463 |
* @param [type] $field get ID, options.... |
| 464 |
* @param [type] $values get_option() value |
| 465 |
* @param [type] $key |
| 466 |
* |
| 467 |
* @return void |
| 468 |
*/ |
| 469 |
function lp_metabox_custom_fields( $field, $values, $key ) { |
| 470 |
?> |
| 471 |
<tr> |
| 472 |
<td class="sort"> |
| 473 |
<input class="count" type="hidden" value="<?php echo esc_attr( $key ); ?>" name="<?php echo esc_attr( $field['id'] ) . '[' . $key . ']' . '[sort]'; ?>"> |
| 474 |
<input type="hidden" value="<?php echo ! empty( $values['id'] ) ? $values['id'] : wp_rand( 1, 10000 ) . $key; ?>" name="<?php echo esc_attr( $field['id'] ) . '[' . $key . ']' . '[id]'; ?>"> |
| 475 |
</td> |
| 476 |
<?php |
| 477 |
if ( $field['options'] ) { |
| 478 |
foreach ( $field['options'] as $cfk => $val ) { |
| 479 |
$name = $field['id'] . '[' . $key . ']' . '[' . $cfk . ']'; |
| 480 |
|
| 481 |
switch ( $val['type'] ) { |
| 482 |
case 'text': |
| 483 |
case 'password': |
| 484 |
case 'datetime': |
| 485 |
case 'datetime-local': |
| 486 |
case 'date': |
| 487 |
case 'month': |
| 488 |
case 'time': |
| 489 |
case 'week': |
| 490 |
case 'number': |
| 491 |
case 'email': |
| 492 |
case 'url': |
| 493 |
case 'tel': |
| 494 |
?> |
| 495 |
<td> |
| 496 |
<input name="<?php echo esc_attr( $name ); ?>" type="<?php echo esc_attr( $val['type'] ); ?>" |
| 497 |
class="input-text" |
| 498 |
placeholder="<?php echo isset( $val['placeholder'] ) ? esc_attr( $val['placeholder'] ) : ''; ?>" |
| 499 |
value="<?php echo ! empty( $values[ $cfk ] ) ? esc_attr( $values[ $cfk ] ) : ''; ?>"> |
| 500 |
</td> |
| 501 |
<?php |
| 502 |
break; |
| 503 |
|
| 504 |
case 'select': |
| 505 |
?> |
| 506 |
<td> |
| 507 |
<select name="<?php echo esc_attr( $name ); ?>"> |
| 508 |
<?php |
| 509 |
if ( isset( $val['options'] ) ) { |
| 510 |
foreach ( $val['options'] as $cfks => $cfselect ) { |
| 511 |
?> |
| 512 |
<option |
| 513 |
value="<?php echo esc_attr( $cfks ); ?>" |
| 514 |
<?php |
| 515 |
echo ! empty( $values[ $cfk ] ) ? selected( |
| 516 |
$values[ $cfk ], |
| 517 |
(string) $cfks |
| 518 |
) : ''; |
| 519 |
?> |
| 520 |
><?php echo wp_kses_post( $cfselect ); ?></option> |
| 521 |
<?php |
| 522 |
} |
| 523 |
} |
| 524 |
?> |
| 525 |
</select> |
| 526 |
</td> |
| 527 |
<?php |
| 528 |
break; |
| 529 |
|
| 530 |
case 'checkbox': |
| 531 |
?> |
| 532 |
<td> |
| 533 |
<input name="<?php echo esc_attr( $name ); ?>" type="checkbox" name="" value="1" <?php echo ! empty( $values[ $cfk ] ) ? checked( $values[ $cfk ], 'yes' ) : ''; ?>> |
| 534 |
</td> |
| 535 |
<?php |
| 536 |
break; |
| 537 |
} |
| 538 |
} |
| 539 |
} |
| 540 |
?> |
| 541 |
<td width="2%"><a href="#" class="delete"></a></td> |
| 542 |
</tr> |
| 543 |
<?php |
| 544 |
} |
| 545 |
|
| 546 |
function lp_implode_html_attributes( $raw_attributes ) { |
| 547 |
$attributes = array(); |
| 548 |
foreach ( $raw_attributes as $name => $value ) { |
| 549 |
$attributes[] = esc_attr( $name ) . '="' . esc_attr( $value ) . '"'; |
| 550 |
} |
| 551 |
|
| 552 |
return implode( ' ', $attributes ); |
| 553 |
} |
| 554 |
|
| 555 |
function lp_meta_box_output( $metaboxes = array() ) { |
| 556 |
if ( ! empty( $metaboxes ) ) { |
| 557 |
foreach ( $metaboxes as $id => $field ) { |
| 558 |
$field['id'] = $id; |
| 559 |
|
| 560 |
switch ( $field['type'] ) { |
| 561 |
case 'text': |
| 562 |
case 'number': |
| 563 |
case 'url': |
| 564 |
lp_meta_box_text_input_field( $field ); |
| 565 |
break; |
| 566 |
|
| 567 |
case 'textarea': |
| 568 |
lp_meta_box_textarea_field( $field ); |
| 569 |
break; |
| 570 |
|
| 571 |
case 'checkbox': |
| 572 |
lp_meta_box_checkbox_field( $field ); |
| 573 |
break; |
| 574 |
|
| 575 |
case 'duration': |
| 576 |
lp_meta_box_duration_field( $field ); |
| 577 |
break; |
| 578 |
|
| 579 |
case 'select': |
| 580 |
lp_meta_box_select_field( $field ); |
| 581 |
break; |
| 582 |
|
| 583 |
case 'radio': |
| 584 |
lp_meta_box_radio_field( $field ); |
| 585 |
break; |
| 586 |
|
| 587 |
case 'file': |
| 588 |
lp_meta_box_file_input_field( $field ); |
| 589 |
break; |
| 590 |
} |
| 591 |
} |
| 592 |
} |
| 593 |
} |
| 594 |
|