PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.6.9.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.6.9.1
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / inc / admin / views / meta-boxes / fields / file.php

file.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.6.9.1, at inc/admin/views/meta-boxes/fields/file.php

108 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * LP_Meta_Box_Duration_Attribute
5 *
6 * @author Nhamdv
7 * @version 1.0.0
8 * @since 4.0.0
9 */
10 class LP_Meta_Box_File_Field extends LP_Meta_Box_Field {
11
12 /**
13 * Constructor.
14 *
15 * @param string $id
16 * @param string $label
17 * @param string $description
18 * @param mixed $default
19 * @param array $extra
20 */
21 public function __construct( $label = '', $description = '', $default = '', $extra = array() ) {
22 parent::__construct( $label, $description, $default, $extra );
23 }
24
25 public function output( $thepostid ) {
26 if ( empty( $this->id ) ) {
27 return;
28 }
29
30 $field = $this->extra;
31 $field['id'] = $this->id;
32 $field['default'] = $this->default;
33 $field['description'] = $this->description;
34 $field['label'] = $this->label;
35
36 $field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
37 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
38 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
39 $field['default'] = ( ! $this->meta_value( $thepostid ) && isset( $field['default'] ) ) ? $field['default'] : $this->meta_value( $thepostid );
40 $field['value'] = isset( $field['value'] ) ? $field['value'] : $field['default'];
41 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
42 $field['mime_type'] = isset( $field['mime_type'] ) ? implode( ',', $field['mime_type'] ) : '';
43 $field['multil'] = ( isset( $field['multil'] ) && $field['multil'] ) ? true : false;
44 $field['desc_tip'] = isset( $field['desc_tip'] ) ? $field['desc_tip'] : false;
45
46 // Custom attribute handling
47 $custom_attributes = array();
48
49 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
50 foreach ( $field['custom_attributes'] as $attribute => $custom_attribute ) {
51 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $custom_attribute ) . '"';
52 }
53 }
54
55 echo '<div class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '">
56 <label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>';
57
58 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(
59 ' ',
60 $custom_attributes
61 ) . '>';
62 echo '<ul class="lp-meta-box__file_list">';
63
64 if ( ! empty( $field['value'] ) ) {
65 foreach ( (array) $field['value'] as $attachment_id ) {
66 $url = wp_get_attachment_url( $attachment_id );
67
68 if ( $url ) {
69 $check_file = wp_check_filetype( $url );
70
71 echo '<li class="lp-meta-box__file_list-item image" data-attachment_id="' . $attachment_id . '">';
72
73 if ( in_array( $check_file['ext'], array( 'jpg', 'png', 'gif', 'bmp', 'tif' ), true ) ) {
74 echo wp_get_attachment_image( $attachment_id, 'thumbnail' );
75 } else {
76 echo '<img class="is_file" src="' . wp_mime_type_icon( $check_file['type'] ) . '" />';
77 echo '<span>' . wp_basename( get_attached_file( $attachment_id ) ) . '</span>';
78 }
79 echo '<ul class="actions"><li><a href="#" class="delete"></a></li></ul>';
80 echo '</li>';
81 }
82 }
83 }
84
85 echo '</ul>';
86 echo '<input class="lp-meta-box__file_input" type="hidden" name="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( ( ! empty( $field['value'] ) && is_array( $field['value'] ) ) ? implode( ',', $field['value'] ) : $field['value'] ) . '" />';
87 echo '<p>';
88 echo '<a href="#" class="button btn-upload">' . esc_html__( '+ Add media', 'learnpress' ) . '</a>';
89 if ( ! empty( $field['description'] ) && false !== $field['desc_tip'] ) {
90 learn_press_quick_tip( $field['description'] );
91 }
92 echo '</p>';
93
94 if ( ! empty( $field['description'] ) && false === $field['desc_tip'] ) {
95 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
96 }
97 echo '</div>';
98 echo '</div>';
99
100 }
101
102 public function save( $post_id ) {
103 $value = ! empty( $_POST[ $this->id ] ) ? wp_unslash( array_filter( explode( ',', $_POST[ $this->id ] ) ) ) : '';
104
105 update_post_meta( $post_id, $this->id, $value );
106 }
107 }
108