Advertisement
awan101

fp-employees.php

Jan 25th, 2016
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.14 KB | None | 0 0
  1. <?php
  2.  
  3. class Moesia_Employees extends WP_Widget {
  4.  
  5. // constructor
  6.     function moesia_employees() {
  7.         $widget_ops = array('classname' => 'moesia_employees_widget', 'description' => __( 'Display your team members in a stylish way.', 'moesia') );
  8.         parent::__construct(false, $name = __('Moesia FP: Employees', 'moesia'), $widget_ops);
  9.         $this->alt_option_name = 'moesia_employees_widget';
  10.        
  11.         add_action( 'save_post', array($this, 'flush_widget_cache') );
  12.         add_action( 'deleted_post', array($this, 'flush_widget_cache') );
  13.         add_action( 'switch_theme', array($this, 'flush_widget_cache') );      
  14.     }
  15.    
  16.     // widget form creation
  17.     function form($instance) {
  18.  
  19.     // Check values
  20.         $title     = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
  21.         $number    = isset( $instance['number'] ) ? intval( $instance['number'] ) : -1;
  22.         $see_all        = isset( $instance['see_all'] ) ? esc_url_raw( $instance['see_all'] ) : '';
  23.         $see_all_text   = isset( $instance['see_all_text'] ) ? esc_html( $instance['see_all_text'] ) : '';
  24.         $category   = isset( $instance['category '] ) ? esc_attr( $instance['category '] ) : '';                       
  25.         $image_uri = isset( $instance['image_uri'] ) ? esc_url_raw( $instance['image_uri'] ) : '';
  26.         $video_uri_mp4  = isset( $instance['video_uri_mp4'] ) ? esc_url_raw( $instance['video_uri_mp4'] ) : '';
  27.         $video_uri_webm  = isset( $instance['video_uri_webm'] ) ? esc_url_raw( $instance['video_uri_webm'] ) : '';     
  28.     ?>
  29.  
  30.     <p><?php _e('In order to display this widget, you must first add some employees from the dashboard. Add as many as you want and the theme will automatically display them all.', 'moesia'); ?></p>
  31.     <p>
  32.     <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'moesia'); ?></label>
  33.     <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
  34.     </p>
  35.  
  36.     <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of employees to show (-1 shows all of them):', 'moesia' ); ?></label>
  37.     <input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
  38.     <p><label for="<?php echo $this->get_field_id('see_all'); ?>"><?php _e('Enter the URL for your employees page. Useful if you want to show here just a few employees, then send your visitors to a page that uses the employees page template.', 'moesia'); ?></label>
  39.     <input class="widefat custom_media_url" id="<?php echo $this->get_field_id( 'see_all' ); ?>" name="<?php echo $this->get_field_name( 'see_all' ); ?>" type="text" value="<?php echo $see_all; ?>" size="3" /></p>  
  40.     <p><label for="<?php echo $this->get_field_id('see_all_text'); ?>"><?php _e('The text for the button [Defaults to <em>See all our employees</em> if left empty]', 'moesia'); ?></label>
  41.     <input class="widefat custom_media_url" id="<?php echo $this->get_field_id( 'see_all_text' ); ?>" name="<?php echo $this->get_field_name( 'see_all_text' ); ?>" type="text" value="<?php echo $see_all_text; ?>" size="3" /></p>       
  42.     <p><label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Enter the slug for your category or leave empty to show all employees.', 'moesia' ); ?></label>
  43.     <input class="widefat" id="<?php echo $this->get_field_id( 'category' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>" type="text" value="<?php echo $category; ?>" size="3" /></p>
  44.  
  45.  
  46.     <h3><?php _e('Image background', 'moesia'); ?></h3>
  47.     <?php
  48.         if ( $image_uri != '' ) :
  49.            echo '<p><img class="custom_media_image" src="' . $image_uri . '" style="max-width:100px;" /></p>';
  50.         endif;
  51.     ?>
  52.     <p><label for="<?php echo $this->get_field_id('image_uri'); ?>"><?php _e('[DEPRECATED - Go to Edit Row > Theme > Background image] Upload an image for the background if you want. It will get a parallax effect.', 'moesia'); ?></label></p>
  53.     <p><input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="<?php echo $this->get_field_name('image_uri'); ?>" value="Upload Image" style="margin-top:5px;" /></p>
  54.     <p><input class="widefat custom_media_url" id="<?php echo $this->get_field_id( 'image_uri' ); ?>" name="<?php echo $this->get_field_name( 'image_uri' ); ?>" type="text" value="<?php echo $image_uri; ?>" size="3" /></p>
  55.  
  56.     <h3><?php _e('Video background', 'moesia'); ?></h3>
  57.     <p>
  58.     <label for="<?php echo $this->get_field_id('video_uri_mp4'); ?>"><?php _e('Enter the full link to your video [mp4 format]', 'moesia'); ?></label>
  59.     <input class="widefat" id="<?php echo $this->get_field_id('video_uri_mp4'); ?>" name="<?php echo $this->get_field_name('video_uri_mp4'); ?>" type="text" value="<?php echo $video_uri_mp4; ?>" />
  60.     </p>
  61.     <p>
  62.     <label for="<?php echo $this->get_field_id('video_uri_webm'); ?>"><?php _e('Enter the full link to your video [webm format]', 'moesia'); ?></label>
  63.     <input class="widefat" id="<?php echo $this->get_field_id('video_uri_webm'); ?>" name="<?php echo $this->get_field_name('video_uri_webm'); ?>" type="text" value="<?php echo $video_uri_webm; ?>" />
  64.     </p>
  65.    
  66.     <?php
  67.     }
  68.  
  69.     // update widget
  70.     function update($new_instance, $old_instance) {
  71.         $instance = $old_instance;
  72.         $instance['title'] = strip_tags($new_instance['title']);
  73.         $instance['number'] = strip_tags($new_instance['number']);
  74.         $instance['category'] = strip_tags($new_instance['category']);
  75.         $instance['image_uri'] = esc_url_raw( $new_instance['image_uri'] );
  76.         $instance['see_all']        = esc_url_raw( $new_instance['see_all'] ); 
  77.         $instance['see_all_text']   = strip_tags($new_instance['see_all_text']);
  78.         $instance['video_uri_mp4'] = esc_url_raw( $new_instance['video_uri_mp4'] );
  79.         $instance['video_uri_webm'] = esc_url_raw( $new_instance['video_uri_webm'] );      
  80.         $this->flush_widget_cache();
  81.  
  82.         $alloptions = wp_cache_get( 'alloptions', 'options' );
  83.         if ( isset($alloptions['moesia_employees']) )
  84.             delete_option('moesia_employees');       
  85.          
  86.         return $instance;
  87.     }
  88.    
  89.     function flush_widget_cache() {
  90.         wp_cache_delete('moesia_employees', 'widget');
  91.     }
  92.    
  93.     // display widget
  94.     function widget($args, $instance) {
  95.         $cache = array();
  96.         if ( ! $this->is_preview() ) {
  97.             $cache = wp_cache_get( 'moesia_employees', 'widget' );
  98.         }
  99.  
  100.         if ( ! is_array( $cache ) ) {
  101.             $cache = array();
  102.         }
  103.  
  104.         if ( ! isset( $args['widget_id'] ) ) {
  105.             $args['widget_id'] = $this->id;
  106.         }
  107.  
  108.         if ( isset( $cache[ $args['widget_id'] ] ) ) {
  109.             echo $cache[ $args['widget_id'] ];
  110.             return;
  111.         }
  112.  
  113.         ob_start();
  114.         extract($args);
  115.  
  116.         $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Our Employees', 'moesia' );
  117.  
  118.         /** This filter is documented in wp-includes/default-widgets.php */
  119.         $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  120.         $image_uri = isset( $instance['image_uri'] ) ? esc_url($instance['image_uri']) : '';
  121.         $video_uri_mp4 = isset( $instance['video_uri_mp4'] ) ? esc_url($instance['video_uri_mp4']) : '';
  122.         $video_uri_webm = isset( $instance['video_uri_webm'] ) ? esc_url($instance['video_uri_webm']) : '';    
  123.         $see_all = isset( $instance['see_all'] ) ? esc_url($instance['see_all']) : '';
  124.         $see_all_text = isset( $instance['see_all_text'] ) ? esc_html($instance['see_all_text']) : '';
  125.         $number = ( ! empty( $instance['number'] ) ) ? intval( $instance['number'] ) : -1;
  126.         if ( ! $number )
  127.             $number = -1;          
  128.         $category = isset( $instance['category'] ) ? esc_attr($instance['category']) : '';
  129.  
  130.         /**
  131.          * Filter the arguments for the Recent Posts widget.
  132.          *
  133.          * @since 3.4.0
  134.          *
  135.          * @see WP_Query::get_posts()
  136.          *
  137.          * @param array $args An array of arguments used to retrieve the recent posts.
  138.          */
  139.         $r = new WP_Query( apply_filters( 'widget_posts_args', array(
  140.             'no_found_rows'       => true,
  141.             'post_status'         => 'publish',
  142.             'post_type'           => 'employees',
  143.             'posts_per_page'      => $number,
  144.             'category_name'       => $category
  145.         ) ) );
  146.  
  147.         if ($r->have_posts()) :
  148. ?>
  149.  
  150.         <section id="employees" class="employees-area">
  151.             <div class="container">
  152.                 <?php if ( $title ) echo $before_title . '<span class="wow bounce">' . $title . '</span>' . $after_title; ?>
  153.                 <?php while ( $r->have_posts() ) : $r->the_post(); ?>
  154.                     <?php //Get the custom field values
  155.                         $photo = get_post_meta( get_the_ID(), 'wpcf-photo', true );
  156.                         $position = get_post_meta( get_the_ID(), 'wpcf-position', true );
  157.                         $custom_link = get_post_meta( get_the_ID(), 'wpcf-custom-link', true );
  158.                         $facebook = get_post_meta( get_the_ID(), 'wpcf-facebook', true );
  159.                         $twitter = get_post_meta( get_the_ID(), 'wpcf-twitter', true );
  160.                         $google = get_post_meta( get_the_ID(), 'wpcf-google-plus', true );
  161.                         $linkedin = get_post_meta( get_the_ID(), 'wpcf-linkedin', true );
  162.                     ?>
  163.                     <div class="employee col-md-4 col-sm-6 col-xs-6">
  164.                         <?php if ($photo != '') : ?>
  165.                         <?php if ( $custom_link != '' ) : ?>
  166.                          <a href="<?php echo esc_url($custom_link); ?>">
  167.                          <?php endif; ?>
  168.                             <img class="employee-photo wow zoomInDown" src="<?php echo esc_url($photo); ?>" alt="<?php the_title(); ?>">
  169.                             <?php if ( $custom_link != '' ) : ?>
  170.                              </a>
  171.                              <?php endif; ?>
  172.                         <?php elseif ( has_post_thumbnail() ) : ?>
  173.                             <div class="employee-photo wow zoomInDown"><?php the_post_thumbnail('moesia-employees-thumb'); ?></div>
  174.                         <?php endif; ?>
  175.                         <h4 class="employee-name wow fadeInUp"><?php the_title(); ?></h4>
  176.                         <?php if ($position != '') : ?>
  177.                             <span class="employee-position wow fadeInUp"><?php echo esc_html($position); ?></span>
  178.                         <?php endif; ?>
  179.                         <div class="employee-desc wow fadeInUp"><?php the_content(); ?></div>
  180.                         <?php if ( ($facebook != '') || ($twitter != '') || ($google != '') || ($linkedin != '') ) : ?>
  181.                             <div class="employee-social wow fadeInUp">
  182.                                 <?php if ($facebook != '') : ?>
  183.                                     <a href="<?php echo esc_url($facebook); ?>" target="_blank"><i class="fa fa-facebook"></i></a>
  184.                                 <?php endif; ?>
  185.                                 <?php if ($twitter != '') : ?>
  186.                                     <a href="<?php echo esc_url($twitter); ?>" target="_blank"><i class="fa fa-twitter"></i></a>
  187.                                 <?php endif; ?>
  188.                                 <?php if ($google != '') : ?>
  189.                                     <a href="<?php echo esc_url($google); ?>" target="_blank"><i class="fa fa-google-plus"></i></a>
  190.                                 <?php endif; ?>                                        
  191.                                 <?php if ($linkedin != '') : ?>
  192.                                     <a href="<?php echo esc_url($linkedin); ?>" target="_blank"><i class="fa fa-linkedin"></i></a>
  193.                                 <?php endif; ?>
  194.                             </div>
  195.                         <?php endif; ?>
  196.                     </div>
  197.                 <?php endwhile; ?>
  198.             </div>
  199.             <?php if ($see_all != '') : ?>
  200.                 <a href="<?php echo esc_url($see_all); ?>" class="all-news">
  201.                     <?php if ($see_all_text) : ?>
  202.                         <?php echo $see_all_text; ?>
  203.                     <?php else : ?>
  204.                         <?php echo __('See all our employees', 'moesia'); ?>
  205.                     <?php endif; ?>
  206.                 </a>
  207.             <?php endif; ?>            
  208.             <?php if ($video_uri_mp4 !='') : ?>
  209.                 <video id="videobg" preload="auto" autoplay="true" loop="loop" muted="muted" volume="0">
  210.                      <source src="<?php echo esc_url($video_uri_mp4); ?>" type="video/mp4">
  211.                      <source src="<?php echo esc_url($video_uri_webm); ?>" type="video/webm">
  212.                 </video>
  213.             <?php endif; ?>        
  214.         </section>
  215.         <?php if (($image_uri != '') && ($video_uri_mp4 =='')) : ?>
  216.             <style type="text/css">
  217.                 .employees-area {
  218.                     display: block;            
  219.                     background: url(<?php echo $image_uri; ?>) no-repeat;
  220.                     background-position: center top;
  221.                     background-attachment: fixed;
  222.                     background-size: cover;
  223.                     z-index: -1;
  224.                     position: static;                  
  225.                 }
  226.                 .employee {
  227.                     background-color: rgba(0,0,0,0.6);
  228.                     border-right: 1px solid #5E5E5E;
  229.                 }
  230.                 .employee:nth-of-type(3),
  231.                 .employee:nth-of-type(6),
  232.                 .employee:nth-of-type(7) {
  233.                     border-right: 0;
  234.                 }  
  235.             </style>
  236.         <?php endif; ?>    
  237.        
  238.     <?php
  239.         // Reset the global $the_post as this query will have stomped on it
  240.         wp_reset_postdata();
  241.  
  242.         endif;
  243.  
  244.         if ( ! $this->is_preview() ) {
  245.             $cache[ $args['widget_id'] ] = ob_get_flush();
  246.             wp_cache_set( 'moesia_employees', $cache, 'widget' );
  247.         } else {
  248.             ob_end_flush();
  249.         }
  250.     }
  251.    
  252. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement