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.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / Taxonomies.php
tutor / classes Last commit date
Addons.php 11 months ago Admin.php 2 months ago Ajax.php 9 months ago Announcements.php 1 year ago Assets.php 2 months ago Backend_Page_Trait.php 1 year ago BaseController.php 1 year ago Config.php 11 months ago Container.php 11 months ago Course.php 2 months ago Course_Embed.php 3 years ago Course_Filter.php 1 year ago Course_List.php 5 months ago Course_Settings_Tabs.php 1 year ago Course_Widget.php 1 year ago Custom_Validation.php 3 years ago Dashboard.php 1 year ago Earnings.php 9 months ago FormHandler.php 2 years ago Frontend.php 1 year ago Gutenberg.php 1 year ago Icon.php 8 months ago Input.php 1 year ago Instructor.php 2 months ago Instructors_List.php 2 months ago Lesson.php 2 weeks ago Options_V2.php 7 months ago Permalink.php 2 years ago Post_types.php 1 year ago Private_Course_Access.php 1 year ago Q_And_A.php 10 months ago Question_Answers_List.php 11 months ago Quiz.php 2 weeks ago QuizBuilder.php 3 days ago Quiz_Attempts_List.php 9 months ago RestAPI.php 2 years ago Reviews.php 9 months ago Rewrite_Rules.php 2 years ago Shortcode.php 9 months ago Singleton.php 1 year ago Student.php 2 months ago Students_List.php 1 year ago Taxonomies.php 1 year ago Template.php 9 months ago Theme_Compatibility.php 3 years ago Tools.php 1 year ago Tools_V2.php 3 weeks ago Tutor.php 2 months ago TutorEDD.php 1 year ago Tutor_Base.php 2 years ago Tutor_Setup.php 8 months ago Upgrader.php 9 months ago User.php 4 months ago Utils.php 3 days ago Video_Stream.php 3 years ago WhatsNew.php 9 months ago Withdraw.php 3 days ago Withdraw_Requests_List.php 11 months ago WooCommerce.php 3 days ago
Taxonomies.php
273 lines
1 <?php
2 /**
3 * Tutor taxonomies
4 *
5 * @package Tutor\Taxonomies
6 * @author Themeum <support@themeum.com>
7 * @link https://themeum.com
8 * @since 1.0.0
9 */
10
11 namespace TUTOR;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Manage taxonomies
19 *
20 * @since 1.0.0
21 */
22 class Taxonomies {
23
24 /**
25 * Register hooks
26 *
27 * @since 1.0.0
28 */
29 public function __construct() {
30 add_action( 'course-category_add_form_fields', array( $this, 'add_category_fields' ) );
31 add_action( 'course-category_edit_form_fields', array( $this, 'edit_category_fields' ) );
32
33 add_action( 'created_term', array( $this, 'save_category_fields' ), 10, 3 );
34 add_action( 'edit_term', array( $this, 'save_category_fields' ), 10, 3 );
35
36 add_filter( 'manage_edit-course-category_columns', array( $this, 'course_category_columns' ) );
37 add_filter( 'manage_course-category_custom_column', array( $this, 'course_category_column' ), 10, 3 );
38 }
39
40 /**
41 * Add category fields
42 *
43 * @return void
44 */
45 public function add_category_fields() {
46 ?>
47 <div class="form-field term-thumbnail-wrap">
48 <label><?php esc_html_e( 'Thumbnail', 'tutor' ); ?></label>
49 <div id="course-category_thumbnail" style="float: left; margin-right: 10px;"><img src="<?php echo esc_url( tutor_placeholder_img_src() ); ?>" width="60px" height="60px" /></div>
50 <div style="line-height: 60px;">
51 <input type="hidden" id="course-category_thumbnail_id" name="course_category_thumbnail_id" />
52 <button type="button" class="upload_image_button button"><?php esc_html_e( 'Upload/Add image', 'tutor' ); ?></button>
53 <button type="button" class="remove_image_button button"><?php esc_html_e( 'Remove image', 'tutor' ); ?></button>
54 </div>
55 <script type="text/javascript">
56
57 // Only show the "remove image" button when needed
58 if ( ! jQuery( '#course-category_thumbnail_id' ).val() ) {
59 jQuery( '.remove_image_button' ).hide();
60 }
61
62 // Uploading files
63 var file_frame;
64
65 jQuery( document ).on( 'click', '.upload_image_button', function( event ) {
66
67 event.preventDefault();
68
69 // If the media frame already exists, reopen it.
70 if ( file_frame ) {
71 file_frame.open();
72 return;
73 }
74
75 // Create the media frame.
76 file_frame = wp.media.frames.downloadable_file = wp.media({
77 title: '<?php esc_html_e( 'Choose an image', 'tutor' ); ?>',
78 button: {
79 text: '<?php esc_html_e( 'Use image', 'tutor' ); ?>'
80 },
81 multiple: false
82 });
83
84 // When an image is selected, run a callback.
85 file_frame.on( 'select', function() {
86 var attachment = file_frame.state().get( 'selection' ).first().toJSON();
87 var attachment_thumbnail = attachment.sizes.thumbnail || attachment.sizes.full;
88
89 jQuery( '#course-category_thumbnail_id' ).val( attachment.id );
90 jQuery( '#course-category_thumbnail' ).find( 'img' ).attr( 'src', attachment_thumbnail.url );
91 jQuery( '.remove_image_button' ).show();
92 });
93
94 // Finally, open the modal.
95 file_frame.open();
96 });
97
98 jQuery( document ).on( 'click', '.remove_image_button', function() {
99 jQuery( '#course-category_thumbnail' ).find( 'img' ).attr( 'src', '<?php echo esc_js( tutor_placeholder_img_src() ); ?>' );
100 jQuery( '#course-category_thumbnail_id' ).val( '' );
101 jQuery( '.remove_image_button' ).hide();
102 return false;
103 });
104
105 </script>
106 <div class="clear"></div>
107 </div>
108 <?php
109 }
110
111 /**
112 * Edit category fields
113 *
114 * @since 1.0.0
115 *
116 * @param mixed $term term.
117 *
118 * @return void
119 */
120 public function edit_category_fields( $term ) {
121
122 $thumbnail_id = absint( get_term_meta( $term->term_id, 'thumbnail_id', true ) );
123
124 if ( $thumbnail_id ) {
125 $image = wp_get_attachment_thumb_url( $thumbnail_id );
126 } else {
127 $image = tutor_placeholder_img_src();
128 }
129 ?>
130
131 <tr class="form-field term-thumbnail-wrap">
132 <th scope="tutor-row" valign="top"><label><?php esc_html_e( 'Thumbnail', 'tutor' ); ?></label></th>
133 <td>
134
135 <div class="form-field term-thumbnail-wrap">
136 <div id="course-category_thumbnail" style="float: left; margin-right: 10px;"><img src="<?php echo esc_url( $image ); ?>" width="60px" height="60px" /></div>
137 <div style="line-height: 60px;">
138 <input type="hidden" id="course-category_thumbnail_id" name="course_category_thumbnail_id" value="<?php echo esc_attr( $thumbnail_id ); ?>" />
139 <button type="button" class="upload_image_button button"><?php esc_html_e( 'Upload/Add image', 'tutor' ); ?></button>
140 <button type="button" class="remove_image_button button"><?php esc_html_e( 'Remove image', 'tutor' ); ?></button>
141 </div>
142 <script type="text/javascript">
143
144 // Only show the "remove image" button when needed
145 if ( ! jQuery( '#course-category_thumbnail_id' ).val() ) {
146 jQuery( '.remove_image_button' ).hide();
147 }
148
149 // Uploading files
150 var file_frame;
151
152 jQuery( document ).on( 'click', '.upload_image_button', function( event ) {
153
154 event.preventDefault();
155
156 // If the media frame already exists, reopen it.
157 if ( file_frame ) {
158 file_frame.open();
159 return;
160 }
161
162 // Create the media frame.
163 file_frame = wp.media.frames.downloadable_file = wp.media({
164 title: '<?php esc_html_e( 'Choose an image', 'tutor' ); ?>',
165 button: {
166 text: '<?php esc_html_e( 'Use image', 'tutor' ); ?>'
167 },
168 multiple: false
169 });
170
171 // When an image is selected, run a callback.
172 file_frame.on( 'select', function() {
173 var attachment = file_frame.state().get( 'selection' ).first().toJSON();
174 var attachment_thumbnail = attachment.sizes.thumbnail || attachment.sizes.full;
175
176 jQuery( '#course-category_thumbnail_id' ).val( attachment.id );
177 jQuery( '#course-category_thumbnail' ).find( 'img' ).attr( 'src', attachment_thumbnail.url );
178 jQuery( '.remove_image_button' ).show();
179 });
180
181 // Finally, open the modal.
182 file_frame.open();
183 });
184
185 jQuery( document ).on( 'click', '.remove_image_button', function() {
186 jQuery( '#course-category_thumbnail' ).find( 'img' ).attr( 'src', '<?php echo esc_js( tutor_placeholder_img_src() ); ?>' );
187 jQuery( '#course-category_thumbnail_id' ).val( '' );
188 jQuery( '.remove_image_button' ).hide();
189 return false;
190 });
191
192 </script>
193 <div class="clear"></div>
194 </div>
195
196 </td>
197 </tr>
198 <?php
199 }
200
201 /**
202 * Save Course Category Thumbnail
203 *
204 * @since 1.0.0
205 *
206 * @param int $term_id term id.
207 * @param string $tt_id tt id.
208 * @param string $taxonomy taxonomy.
209 *
210 * @return void
211 */
212 public function save_category_fields( $term_id, $tt_id = '', $taxonomy = '' ) {
213 $thumbnail_id = Input::post( 'course_category_thumbnail_id', 0, Input::TYPE_INT );
214 if ( Input::has( 'course_category_thumbnail_id' ) && 'course-category' === $taxonomy ) {
215 update_term_meta( $term_id, 'thumbnail_id', absint( $thumbnail_id ) );
216 }
217 }
218
219 /**
220 * Course category edit columns
221 *
222 * @since 1.0.0
223 *
224 * @param array $columns columns.
225 *
226 * @return array
227 */
228 public function course_category_columns( $columns ) {
229 $new_columns = array();
230
231 if ( isset( $columns['cb'] ) ) {
232 $new_columns['cb'] = $columns['cb'];
233 unset( $columns['cb'] );
234 }
235
236 $new_columns['thumb'] = __( 'Image', 'tutor' );
237
238 $columns = array_merge( $new_columns, $columns );
239 $columns['handle'] = '';
240
241 return $columns;
242 }
243
244 /**
245 * Course category columns
246 *
247 * @param array $columns columns.
248 * @param mixed $column column name.
249 * @param int $id term id.
250 *
251 * @return mixed
252 */
253 public function course_category_column( $columns, $column, $id ) {
254 if ( 'thumb' === $column ) {
255 $thumbnail_id = get_term_meta( $id, 'thumbnail_id', true );
256
257 if ( $thumbnail_id ) {
258 $image = wp_get_attachment_thumb_url( $thumbnail_id );
259 } else {
260 $image = tutor_placeholder_img_src();
261 }
262
263 // Prevent esc_url from breaking spaces in urls for image embeds. Ref: https://core.trac.wordpress.org/ticket/23605 .
264 $image = str_replace( ' ', '%20', $image );
265 $columns .= '<img src="' . esc_url( $image ) . '" alt="' . __( 'Thumbnail', 'tutor' ) . '" class="wp-post-image" height="48" width="48" />';
266 }
267 if ( 'handle' === $column ) {
268 $columns .= '<input type="hidden" name="term_id" value="' . $id . '" />';
269 }
270 return $columns;
271 }
272 }
273