HEX
Server: Apache/2.4.49 (FreeBSD) OpenSSL/1.0.2s-freebsd PHP/5.6.36
System: FreeBSD hosting.icon.bg 11.3-RELEASE-p13 FreeBSD 11.3-RELEASE-p13 #0: Tue Sep 1 06:56:51 UTC 2020 root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC amd64
User: ftpuser (1002)
PHP: 5.6.36
Disabled: NONE
Upload Files
File: /hosting/kak.bg/web/wp-content/themes/kak/homepage/widget_home_author_carousel.php
<?php
/**
 * Plugin Name: DesignPicnic Homepage Featured Category
 * Description: This widget allows to display latest posts on the homepage
 * Version: 1.0
 * Author: DesignPicnicStudio
 * Author URI: http://designpicnic.com
 *
 */

/**
 * Add function to widgets_init that'll load our widget.
 */
add_action('widgets_init', 'fp_register_home_author_carousel_widget');
function fp_register_home_author_carousel_widget(){
	register_widget('fp_home_author_carousel_widget');
}

/**
 * This class handles everything that needs to be handled with the widget:
 * the settings, form, display, and update.  Nice!
 *
 */ 
class fp_home_author_carousel_widget extends WP_Widget {
	
	/**
	 * Widget setup.
	 */
	function fp_home_author_carousel_widget(){
		/* Widget settings. */	
		$widget_ops = array('classname' => 'feat-carousel', 'description' => 'Displays the author carousel on homepage.');
		
		/* Create the widget. */
		$this->WP_Widget('fp_home_author_carousel_widget', 'DesignPicnic: Homepage Author Carousel', $widget_ops);
	}
	
	/**
	 * display the widget on the screen.
	 */
	function widget($args, $instance){	
		 		
		extract($args);
		$widget_id = $args['widget_id'];
		
		echo $before_widget;				
		$title = isset($instance['title']) ? $instance['title'] : '';
		$subtitle = isset($instance['subtitle']) ? $instance['subtitle'] : '';		
						
                $users = get_users(array(
                    role => 'author'
                ));
                
		global $paged;
		
		if (!empty($title)) { ?>			
			
			<div class="section-title">
				<span class="carousel-prev"></span>
				<div class="title-wrap">
                                        <h4><?php echo $title; ?></h4>
					<?php if ($subtitle) { ?>
						<h6><?php echo $subtitle; ?></h6>
					<?php } ?>
				</div>
				<span class="carousel-next"></span>
			</div>
			
                <?php } ?>
		<script>
			jQuery(document).ready(function($) {				
				$(".carousel-posts").show();
				$('#<?php echo $widget_id; ?> .carousel-posts').bxSlider({
					minSlides: 1,
					maxSlides: 4,
					slideWidth: 178,
					slideMargin: 20,
					controls: true,
					adaptiveHeight: false,
					pager: false,
					nextSelector: '#<?php echo $widget_id; ?> .carousel-next',
					prevSelector: '#<?php echo $widget_id; ?> .carousel-prev'			  
				});
			});
		</script>
                <?php if (count($users)) { ?>
                    <ul class="carousel-posts list">
                        <?php foreach ($users as $user): ?>
                            <?php $user_catid = get_user_meta($user->ID, 'user_category'); ?>
                            <?php if (count($user_catid)): ?>
                                <li>
                                    <?php $profile_picture = get_user_meta($user->ID, 'profile_picture'); ?>	
                                    <?php if (count($profile_picture)): ?>
                                        <div class="thumb overlay">
                                            <a href="<?php echo get_author_posts_url($user->ID); ?>" >
                                                <?php echo wp_get_attachment_image($profile_picture[0], array(240, 165), 0, array('style' => 'display: block; margin-bottom: 10px;')); ?>
                                            </a>
                                        </div>
                                    <?php endif; ?>	
                                    <div class="post-info">

                                            <h5><a href="<?php echo get_author_posts_url($user->ID); ?>"><?php echo $user->display_name; ?></a></h5>
                                            <div class="entry-meta">
                                                <a class="tag" href="<?php echo get_category_link($user_catid[0]); ?>"><?php echo get_cat_name($user_catid[0]); ?></a>
                                            </div>									

                                    </div>		
                                </li>
                            <?php endif; ?>
                        <?php endforeach; ?>
                    </ul>				
                    <?php echo $after_widget;
                }
        }
	
	/**
	 * update widget settings
	 */
	function update($new_instance, $old_instance){
		$instance = $old_instance;	
		$instance['title'] = $new_instance['title'];
		$instance['subtitle'] = $new_instance['subtitle'];		
		$instance['cat_id'] = $new_instance['cat_id'];
		
		return $instance;
	}
	
	/**
	 * Displays the widget settings controls on the widget panel.
	 * Make use of the get_field_id() and get_field_name() function
	 * when creating your form elements. This handles the confusing stuff.
	 */	
	function form($instance){
		$defaults = array('title' => '', 'subtitle' => '', 'cat_id' => '');
		$instance = wp_parse_args((array) $instance, $defaults); ?>
		
		<div class="widget-field">			
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'fairpixels'); ?></label>
			<input type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" />
			<p class="desc"><?php _e('Enter the section title', 'fairpixels'); ?></p>
		</div>
		
		<div class="widget-field">			
			<label for="<?php echo $this->get_field_id( 'subtitle' ); ?>"><?php _e('Subtitle:', 'fairpixels'); ?></label>
			<input type="text" id="<?php echo $this->get_field_id('subtitle'); ?>" name="<?php echo $this->get_field_name('subtitle'); ?>" value="<?php echo $instance['subtitle']; ?>" />
			<p class="desc"><?php _e('Enter the section subtitle', 'fairpixels'); ?></p>
		</div>
		
		
	<?php }
}
?>