$description_typo = vcex_parse_typography_param($description_typo); // Load Google Font if needed if (isset($title_typo['font_family'])) { wpex_enqueue_google_font($title_typo['font_family']); } if (isset($title_typo['description_typo'])) { wpex_enqueue_google_font($title_typo['description_typo']); } // Get terms if ($parent_terms) { $terms = get_terms($taxonomy, array('parent' => 0)); } else { $terms = get_terms($taxonomy); } // Get term thumbnails $term_data = wpex_get_term_data(); // Define post type based on the taxonomy $taxonomy = get_taxonomy($taxonomy); $post_type = $taxonomy->object_type[0]; // Grid classes $grid_classes = array('vcex-terms-grid', 'wpex-row', 'clr'); if ('masonry' == $grid_style) { $grid_classes[] = 'vcex-isotope-grid'; vcex_inline_js('isotope'); } if ($columns_gap) { $grid_classes[] = 'gap-' . $columns_gap; } if ($visibility) { $grid_classes[] = $visibility; }
/** * Add Thumbnail field to edit form fields * * @since 2.1.0 */ public function edit_form_fields($term) { // Enqueue media for media selector wp_enqueue_media(); // Get current taxonomy $term_id = $term->term_id; $taxonomy = get_taxonomy($_GET['taxonomy']); $taxonomy = $taxonomy->labels->singular_name; // Get term data $term_data = wpex_get_term_data(); // Get thumbnail $thumbnail_id = isset($term_data[$term_id]['thumbnail']) ? $term_data[$term_id]['thumbnail'] : ''; if ($thumbnail_id) { $thumbnail_src = wp_get_attachment_image_src($thumbnail_id, 'thumbnail', false); $thumbnail_url = !empty($thumbnail_src[0]) ? $thumbnail_src[0] : ''; } // Get page header setting $page_header_bg = isset($term_data[$term_id]['page_header_bg']) ? $term_data[$term_id]['page_header_bg'] : ''; ?> <tr class="form-field"> <th scope="row" valign="top"><label><?php esc_html_e('Page Header Thumbnail', 'total'); ?> </label></th> <td> <select id="wpex_term_page_header_image" name="wpex_term_page_header_image" class="postform"> <option value="" <?php selected($page_header_bg, ''); ?> ><?php esc_html_e('Default', 'total'); ?> </option> <option value="false" <?php selected($page_header_bg, 'false'); ?> ><?php esc_html_e('No', 'total'); ?> </option> <option value="true" <?php selected($page_header_bg, 'true'); ?> ><?php esc_html_e('Yes', 'total'); ?> </option> </select> </td> </tr> <tr class="form-field"> <th scope="row" valign="top"> <label for="term-thumbnail"><?php esc_html_e('Thumbnail', 'total'); ?> </label> </th> <td> <div id="wpex-term-thumbnail" style="float:left;margin-right:10px;"> <?php if (!empty($thumbnail_url)) { ?> <img class="wpex-term-thumbnail-img" src="<?php echo esc_url($thumbnail_url); ?> " width="60px" height="60px" /> <?php } else { ?> <img class="wpex-term-thumbnail-img" src="<?php echo esc_url(wpex_placeholder_img_src()); ?> " width="60px" height="60px" /> <?php } ?> </div> <input type="hidden" id="wpex_term_thumbnail" name="wpex_term_thumbnail" value="<?php echo esc_attr($thumbnail_id); ?> " /> <button type="submit" class="wpex-remove-term-thumbnail button"<?php if (!$thumbnail_id) { echo 'style="display:none;"'; } ?> > <?php esc_html_e('Remove image', 'total'); ?> </button> <button type="submit" class="wpex-add-term-thumbnail button"> <?php esc_html_e('Upload/Add image', 'total'); ?> </button> <script type="text/javascript"> // Uploading files var file_frame; jQuery( document ).on( 'click', '.wpex-add-term-thumbnail', function( event ) { event.preventDefault(); // If the media frame already exists, reopen it. if ( file_frame ) { file_frame.open(); return; } // Create the media frame. file_frame = wp.media.frames.downloadable_file = wp.media({ title : '<?php esc_html_e('Choose an image', 'total'); ?> ', button : { text : '<?php esc_html_e('Use image', 'total'); ?> ', }, multiple : false } ); // When an image is selected, run a callback. file_frame.on( 'select', function() { attachment = file_frame.state().get( 'selection' ).first().toJSON(); jQuery( '#wpex_term_thumbnail' ).val( attachment.id ); jQuery( '.wpex-term-thumbnail-img' ).attr( 'src', attachment.url ); jQuery( '.wpex-remove-term-thumbnail' ).show(); } ); // Finally, open the modal. file_frame.open(); } ); jQuery( document ).on( 'click', '.wpex-remove-term-thumbnail', function( event ) { jQuery( '.wpex-term-thumbnail-img' ).attr( 'src', '<?php echo wpex_placeholder_img_src(); ?> ' ); jQuery( '#wpex_term_thumbnail' ).val( '' ); jQuery( '.wpex-remove-term-thumbnail' ).hide(); return false; } ); </script> <div class="clear"></div> </td> </tr> <?php }