Addons.php
11 months ago
Admin.php
9 months ago
Ajax.php
9 months ago
Announcements.php
1 year ago
Assets.php
10 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
9 months ago
Course_Embed.php
3 years ago
Course_Filter.php
1 year ago
Course_List.php
10 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
9 months ago
Input.php
1 year ago
Instructor.php
1 year ago
Instructors_List.php
11 months ago
Lesson.php
10 months ago
Options_V2.php
9 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
9 months ago
QuizBuilder.php
11 months 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
1 year 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
1 year ago
Tutor.php
9 months ago
TutorEDD.php
1 year ago
Tutor_Base.php
2 years ago
Tutor_Setup.php
1 year ago
Upgrader.php
9 months ago
User.php
1 year ago
Utils.php
9 months ago
Video_Stream.php
3 years ago
WhatsNew.php
9 months ago
Withdraw.php
1 year ago
Withdraw_Requests_List.php
11 months ago
WooCommerce.php
9 months 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 |